[CentOS] LVM and hotswap (USB/iSCSI) devices?

Simen Timian Thoresen simentt at dolphinics.no
Sun Aug 31 16:28:23 UTC 2008


Simen Timian Thoresen wrote:
> nate wrote:
>> Simen Timian Thoresen wrote:
>>
>>> So - with the LV unmounted, I power my USB-device down, and then back 
>>> up;
>>
> 
> Hi Nate,
> 
>> I believe your problem is you didn't deactivate the logical
>> volume, and export the volume group before disconnecting.
> 
> Yes! Thank you - exporting and then importing again after replugging 
> worked.
> 
> I'll have to read up on what actually happens here .-)
> 
> Still - say that the USB (or iSCSI) PV is not exported before being 
> unplugged (cables tripped over, internet connection going down, etc) - 
> how do I recover from an unplugged but not exported PV/VG? It seems that 
> vg[im/ex]port only fiddle with the off-PV metadata. Is this correct?
> 
> I think I'm looking for a force-import that allows me to bring a VG with 
> associated LVs up provided that the PVs are present - affectively a 
> 'assemble' ala mdadm.

Hah! I got this one on my own.

After unplugging, I removed the /etc/lvm/archive/ /etc/lvm/backup and 
/dev/mapper/<device> entries, and then replugged;

[root at kasse ~]# pvscan
   PV /dev/iscsi_01   VG iscsistorage   lvm2 [102.79 GB / 102.59 GB free]
   Total: 1 [102.79 GB] / in use: 1 [102.79 GB] / in no VG: 0 [0   ]
(this I've seen before)

Thinking that I could import the VG, I found that it's impossible to 
imoport a non-exported VG;

[root at kasse ~]# vgimport -a
   Volume group "iscsistorage" is not exported

...but just setting it active worked;
[root at kasse ~]# vgchange -a y iscsistorage
   1 logical volume(s) in volume group "iscsistorage" now active
[root at kasse ~]# lvdisplay
   /dev/mapper/iscsistorage-lv1: open failed: No such file or directory
   /dev/mapper/iscsistorage-lv1: open failed: No such file or directory
   --- Logical volume ---
   LV Name                /dev/iscsistorage/lv1
   VG Name                iscsistorage
   LV UUID                mKP1DG-Pc1q-vFzf-sR9v-RE3e-ChNV-T0dWq1
(...)

...and the LV is not mountable;
[root at kasse ~]# mount /dev/iscsistorage/lv1 /mnt/
mount: special device /dev/iscsistorage/lv1 does not exist


To remove the missing /dev/mapper entries, I exported and then 
reimported the VG;

[root at kasse ~]# vgexport -a
   Volume group "iscsistorage" successfully exported
[root at kasse ~]# vgimport -a
   Volume group "iscsistorage" successfully imported
[root at kasse ~]# lvdisplay
   --- Logical volume ---
   LV Name                /dev/iscsistorage/lv1
   VG Name                iscsistorage
   LV UUID                mKP1DG-Pc1q-vFzf-sR9v-RE3e-ChNV-T0dWq1
(...)
[root at kasse ~]# mount /dev/iscsistorage/lv1 /mnt/
[root at kasse ~]# ls /mnt/
lost+found
(...)

Woila!

I think I saw someone doing something to /dev/mapper/control as well to 
skip the export-reimport steps.

I'll see if I can robustify this a little, but if this works, I'll be 
significantly closer to my main goal.

Thank you again for your help .-)

Yours,
-S


> Thank you for pointing me in the right way ;-)
> 
> -S
> 
>> lvchange -a n <path to lvm>
>> vgexport -a (don't worry it will only export groups that are
>> ready to be exported)
>>
>> Now you can safely power the device down(provided the VG was
>> successfully exported, all logical volumes must be unmounted
>> and deactivated before it will succeed).
>>
>> when you power it back up run
>>
>> pvscan
>> vgimport -a
>> lvchange -a y <path to lvm>
>>
>> LVM is very useful for volumes that change device names, but you
>> must use it properly otherwise bad things will happen as you
>> saw.
>>
>> If you want to have USB mount automatically it may be better
>> to put a label on the file system, at least in Debian(don't
>> have a CentOS system with a USB disk handy here) the volume
>> is mounted as /media/<disk label> if there is a disk label.
>> You can use the e2label command to label the device. I'd
>> expect CentOS to likely behave similarly to debian in this
>> respect.
>>
>> nate
>>
>>
>> _______________________________________________
>> CentOS mailing list
>> CentOS at centos.org
>> http://lists.centos.org/mailman/listinfo/centos
>>
> 
> 


-- 
Simen Thoresen, Dolphin ICS
Systems Administration and Wulfkit Support


More information about the CentOS mailing list