LVM external drive, HDD data access with LVM partition (eg a USB HD)

The LVM volumes have many advantages but when you connect a hard drive (with LVM) to an operating system (for example via USB) and want to access the data, we see that is not automatic.

To access the data directly we can mount the volume because the device simply does not exist, this can be easily solved. The sequence of actions is:

1- Connect the HD (logically)
2- Perform vgscan
3- Perform lvscan
4- Enable LVM volume desired
5- Mount the device and access the data

To extract HDD must:

1- Umount the device
2- Disable the LVM volume
3- Extract the HD

And ready.

Below an example of how discover and activate two devices (fedora/root and fedora/vol):

Source   
[jcmolinos@sulaco ~]$ sudo lvm
lvm> vgscan
Reading all physical volumes.  This may take a while...
Found volume group "fedora" using metadata type lvm2
Found volume group "vg_jcmolinos" using metadata type lvm2
lvm> lvscan
inactive          '/dev/fedora/vol' [88,83 GiB] inherit
inactive          '/dev/fedora/swap' [2,93 GiB] inherit
inactive          '/dev/fedora/root' [19,53 GiB] inherit
ACTIVE            '/dev/vg_jcmolinos/lv_vol' [640,34 GiB] inherit
ACTIVE            '/dev/vg_jcmolinos/lv_swap' [7,78 GiB] inherit
ACTIVE            '/dev/vg_jcmolinos/lv_root' [50,00 GiB] inherit
lvm> lvchange -ay fedora/root
lvm> lvscan
inactive          '/dev/fedora/vol' [88,83 GiB] inherit
inactive          '/dev/fedora/swap' [2,93 GiB] inherit
ACTIVE            '/dev/fedora/root' [19,53 GiB] inherit
ACTIVE            '/dev/vg_jcmolinos/lv_vol' [640,34 GiB] inherit
ACTIVE            '/dev/vg_jcmolinos/lv_swap' [7,78 GiB] inherit
ACTIVE            '/dev/vg_jcmolinos/lv_root' [50,00 GiB] inherit
lvm> lvchange -ay fedora/vol
lvm> lvscan
ACTIVE            '/dev/fedora/vol' [88,83 GiB] inherit
inactive          '/dev/fedora/swap' [2,93 GiB] inherit
ACTIVE            '/dev/fedora/root' [19,53 GiB] inherit
ACTIVE            '/dev/vg_jcmolinos/lv_vol' [640,34 GiB] inherit
ACTIVE            '/dev/vg_jcmolinos/lv_swap' [7,78 GiB] inherit
ACTIVE            '/dev/vg_jcmolinos/lv_root' [50,00 GiB] inherit
lvm> exit
Exiting

You may indicate vgscan command something like:

Source   
lvm> vgscan
Reading all physical volumes.  This may take a while...
Found exported volume group "vgprueba" using metadata type lvm2
Found volume group "VolGroup" using metadata type lvm2

This means that the volume group “test” has been exported in order to access the data to be imported before the vg with:

Source   
lvm> vgimport vgprueba
Volume group "vgprueba" successfully imported
lvm> vgscan
Reading all physical volumes.  This may take a while...
Found volume group "vgprueba" using metadata type lvm2
Found volume group "VolGroup" using metadata type lvm2

Now we can mount the volume:

Source   
sudo mount /dev/fedora/vol /mnt

We can now access the files.

To extract HDD we have to umount:

Source   
sudo umount /mnt

And disable volumes before:

Source   
[jcmolinos@sulaco ~]$ sudo lvm
lvm> lvchange -an fedora/vol
lvm> lvchange -an fedora/root
lvm> lvscan
inactive          '/dev/fedora/vol' [88,83 GiB] inherit
inactive          '/dev/fedora/swap' [2,93 GiB] inherit
inactive          '/dev/fedora/root' [19,53 GiB] inherit
ACTIVE            '/dev/vg_jcmolinos/lv_vol' [640,34 GiB] inherit
ACTIVE            '/dev/vg_jcmolinos/lv_swap' [7,78 GiB] inherit
ACTIVE            '/dev/vg_jcmolinos/lv_root' [50,00 GiB] inherit
lvm> exit
Exiting

Now you can safely remove the HDD.

Leave a Reply