Tuesday, February 24, 2015

LVM - Exporting and Importing the Volume Group - the Correct way


There could be a need to move the entire LVM Volume group from one system to another system. Following are the steps to it in the proper way;

1. Check the mount info of the LVM  (Showing only the relevant mount point):
/dev/mapper/vg--1-lv--1 on /bijitLVM type ext4 (rw)

2. Unmount the LV:
# umount /bijitLVM/

3. Deactivate the Volume Group (VG):
# lvs
 LV   VG   Attr   LSize Origin Snap%  Move Log Copy%  Convert
 lv-1 vg-1 -wi-a- 2.00g

# vgchange -an vg-1
 0 logical volume(s) in volume group "vg-1" now active
 The link /dev/vg-1/lv-1 should have been removed by udev but it is still present. Falling back to
   direct link removal.

# lvs
 LV   VG   Attr   LSize Origin Snap%  Move Log Copy%  Convert
 lv-1 vg-1 -wi--- 2.00g

4. Export the Volume Group:
# vgexport -v vg-1
   Using volume group(s) on command line
   Finding volume group "vg-1"
 Volume group vg-1 is exported

5. PVScan to check PV status:
# pvscan
 PV /dev/sda6    is in exported VG vg-1 [3.71 GiB / 1.71 GiB free]
 PV /dev/sda7    is in exported VG vg-1 [3.72 GiB / 3.72 GiB free]
 Total: 2 [7.43 GiB] / in use: 2 [7.43 GiB] / in no VG: 0 [0   ]

Now, one may detach the physical drives associated with the Volume Group from the system (on shutdown). Attach the drives to another system and perform the sequence of steps below;

6. Import the VG:
# vgimport -v vg-1
   Using volume group(s) on command line
   Finding volume group "vg-1"
   Archiving volume group "vg-1" metadata (seqno 4).
   Creating volume group backup "/etc/lvm/backup/vg-1" (seqno 5).
 Volume group "vg-1" successfully imported

7. PVScan to check PV status
# pvscan
 PV /dev/sda6   VG vg-1   lvm2 [3.71 GiB / 1.71 GiB free]
 PV /dev/sda7   VG vg-1   lvm2 [3.72 GiB / 3.72 GiB free]
 Total: 2 [7.43 GiB] / in use: 2 [7.43 GiB] / in no VG: 0 [0   ]

8. Activate the VG
# vgchange -ay vg-1
 1 logical volume(s) in volume group "vg-1" now active
 /dev/mapper/vg--1-lv--1 not set up by udev: Falling back to direct node creation.
 The link /dev/vg-1/lv-1 should had been created by udev but it was not found. Falling back to
   direct link creation.

# lvs
 LV   VG   Attr   LSize Origin Snap%  Move Log Copy%  Convert
 lv-1 vg-1 -wi-a- 2.00g