This article will describe on how to move or migrate LVM and volume group from one server to another.
If you are working in a production environment then you have to know about the software disk management and all the methods to provide flexibility in storage management.
LVM stand for logical volume management. It is a tool to manage and provides a higher-level view of the disk storage.
Below tutorial will be very useful for system administrators who have problems on the linux operating system and want to mount the mounted partition to other systems.
This should be the most simple recovery strategy if we run Linux in VMware virtual machines.
Migrating LVM or Volume Group to new server should be the fastest way to access the important linux partition that may contains user’s data or important configuration files.
How to Migrate LVM or Volume Group to New Server
1. Add vdisk to new virtual machine.
a) Click “Add” to proceed :
b) Select “Hard Disk” device type :
c) Please choose “Use and existing virtual disk” :
d) Browse to vdisk location :
e) Click Next to proceed :
f) Click finish :
g) Finally click “OK” to complete :
2. Once the vdisk as been added to new Linux server, please proceed to rescan the linux VM.
a) Identify host bus number :
# ls /sys/class/scsi_host/ host0 host1 host2
b) Rescan the SCSI Bus to Add a SCSI Devices :
# echo "- - -" > /sys/class/scsi_host/host0/scan # echo "- - -" > /sys/class/scsi_host/host1/scan # echo "- - -" > /sys/class/scsi_host/host2/scan
3. Check the new disk. The second vdisk by default will be recognised as /dev/sdb. Since the partition type has been formatted as LVM on the previous system, it will show Id “8e” if you run fdisk command.
# fdisk -l .. .. Disk /dev/sdb: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xce931872 Device Boot Start End Blocks Id System /dev/sdb1 1 1305 10482381 8e Linux LVM
There are two method to register and activate the LVM and volume group into new linux server. Proceed to steps 4 – 9 for Method 1. Go to step 10 for Method 2.
4. Use lvscan to scans all known volume groups or all supported LVM block devices in the system for defined Logical Volumes. The output consists of one line for each Logical Volume indicating whether it is active or inactive :
# lvscan inactive '/dev/vg_newlvm/newvol' [9.99 GiB] inherit ACTIVE '/dev/vg_centos66/lv_root' [30.00 GiB] inherit ACTIVE '/dev/vg_centos66/lv_swap' [8.00 GiB] inherit
5. Check existing volume group and logical volume:
# vgscan Reading all physical volumes. This may take a while... Found volume group "vg_newlvm" using metadata type lvm2 Found volume group "vg_centos66" using metadata type lvm2
One of the logical volume in “vg_newlvm” volume group still inactive status.
# lvscan inactive '/dev/vg_newlvm/newvol' [9.99 GiB] inherit ACTIVE '/dev/vg_centos66/lv_root' [17.51 GiB] inherit ACTIVE '/dev/vg_centos66/lv_swap' [2.00 GiB] inherit
6. Export the volume group “vg_newlvm” :
# vgexport vg_newlvm Volume group "vg_newlvm" successfully exported
7. Then import volume group “vg_newlvm”:
# vgimport vg_newlvm Volume group "vg_newlvm" successfully imported
8. To activate volume groups “vg_newlvm”, run the following command :
# vgchange -ay vg_newlvm 1 logical volume(s) in volume group "vg_newlvm" now active
9. Check again updated logical volume and volume group status :
# lvscan ACTIVE '/dev/vg_newlvm/newvol' [9.99 GiB] inherit ACTIVE '/dev/vg_centos66/lv_root' [17.51 GiB] inherit ACTIVE '/dev/vg_centos66/lv_swap' [2.00 GiB] inherit
Method 2 :
10. The fastest method to activate the migrated LVM or Volume Group are as below :
# lvscan inactive '/dev/vg_newlvm/newvol' [9.99 GiB] inherit ACTIVE '/dev/vg_centos66/lv_root' [17.51 GiB] inherit ACTIVE '/dev/vg_centos66/lv_swap' [2.00 GiB] inherit
Use lvchange command to activate the LVM.
# lvchange -ay /dev/vg_newlvm/newvol
# lvscan ACTIVE '/dev/vg_newlvm/newvol' [9.99 GiB] inherit ACTIVE '/dev/vg_centos66/lv_root' [17.51 GiB] inherit ACTIVE '/dev/vg_centos66/lv_swap' [2.00 GiB] inherit
11. Create /data folder :
# mkdir -p /data
12. Mount the migrated LVM to /data
# mount /dev/vg_newlvm/newvol /data
13. Verify /date to use migrated LVM :
# df -lh Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos66-lv_root 18G 5.2G 12G 32% / tmpfs 939M 0 939M 0% /dev/shm /dev/sda1 477M 67M 385M 15% /boot /dev/mapper/vg_newlvm-newvol 9.8G 32M 9.2G 1% /data
2 Comments
Hello Dmitri,
Nice article. See your mastering in LVM is top notch!
Could you share the answer on the one question, please :
Is it possible to migrate physical LVM RH8 OS to Virtual VMware VM ?
VMware Converter cannot do that… Maybe any other tools/ways you can advise ?
Thanks and have a nice NY!
Hi Dmitri,
This has been a really great document for us.
Thanks a lot!
Regards, John