Kickstart Storage Migration using LVM

ComputerCarriage > Posts > Howto > Migration > Kickstart Storage Migration using LVM
Kickstart Storage Migration using LVM

1. Introduction

There are several of methods to migrate  from old to new storage,  in this section we are going to migrate using pvmove for the migration, we use pvmove in physical server storage migration.

Step-byStep Storage Migration using LVM is the easy method to migrate from old to new storage, we can do to physical server as well as virtual server. 

Consider if 2GB lun has been assigned to the server, that has  to be migrated from old storage device. Using LVM Partition disks we can migrate from old storage  to new storage without any downtime. In this section we are going to migrate using pvmove.

2. Check the New Disk

To check newly added disk visible in operating system(Added disk sdd). we could see sdb and sdc are existing disk that are used for the database_vg

[root@control ~]# lsblk 
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 31.7G 0 disk
|-sda1 8:1 0 1G 0 part /boot
`-sda2 8:2 0 30.7G 0 part
  |-cl-root 253:0 0 28.6G 0 lvm /
  `-cl-swap 253:1 0 2.2G 0 lvm [SWAP]
sdb 8:16 0 1G 0 disk `-database_vg-database_lv 253:2 0 2G 0 lvm /database
sdc 8:32 0 1G 0 disk `-database_vg-database_lv 253:2 0 2G 0 lvm /database
sdd 8:48 0 2G 0 disk
sr0 11:0 1 1024M 0 rom

3. Add the disk to physical volume

Add the Newly added disk to the physical volume, in this example we are using /dev/sdd.

[root@control ~]# pvcreate /dev/sdd 
Physical volume "/dev/sdd" successfully created.

4. Extend existing Volume Group

Extend the Volume Group by adding new disk /dev/sdd, in this example we have a database_vg Volume Group.

[root@control ~]# vgextend database_vg /dev/sdd 
Volume group "database_vg" successfully extended

A. Verify the VG

Using vgs command we can able to see the free available space is 1.99GB which comes from newly added disk  /dev/sdd.

[root@control ~]# vgs
VG #PV #LV #SN Attr VSize VFree
cl 1 2 0 wz--n- 30.71g 0
database_vg 2 0 0 wz--n- 3.99g 1.99g
[root@control ~]#

5. Monitor the progress

Using lvs command we can able to monitor the storage progress migration

[root@control ~]# lvs -a -o+devices
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert Devices
root cl -wi-ao---- <28.55g /dev/sda2(555)
swap cl -wi-ao---- <2.17g /dev/sda2(0)
database_lv database_vg -wi-ao---- 1.99g /dev/sdb(0)
database_lv database_vg -wi-ao---- 1.99g /dev/sdc(0)

6. Start the migration

Before starting the migration necessary to take backup of the server

Start migrating the disk from old device to new device, in our example we are going to migrate two of the old disk (sdb,sdc) to new disk /dev/sdd.

pvmove command is used to migration the data from old to new disk.

pvmove <old disk> <new disk>

A. Migrate first disk

[root@control ~]# nohup pvmove /dev/sdb /dev/sdd &
[1] 6923
[root@control ~]# nohup: ignoring input and appending output to 'nohup.out'

nohup is to ignore the HUP (hangup) signal, the output will be writes in a file called nohup.out.

B. Monitor the progress

With the lvs command we can monitor the progress.

[root@control ~]# lvs -a -o +devices
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert Devices
root cl -wi-ao---- <28.55g /dev/sda2(555)
swap cl -wi-ao---- <2.17g /dev/sda2(0)
database_lv database_vg -wI-ao---- 1.99g pvmove0(0)
database_lv database_vg -wI-ao---- 1.99g /dev/sdc(0)
[pvmove0] database_vg p-C-aom--- 1020.00m /dev/sdb 100.00 /dev/sdb(0),/dev/sdd(0)
[root@control ~]#

C. Migrate the Second disk

The second disk is /dev/sdc migrate to the /dev/sdd

[root@control ~]# nohup pvmove /dev/sdc /dev/sdd &
[2] 7007
[root@control ~]# nohup: ignoring input and appending output to 'nohup.out'

D. Monitor the progress

We could see the migration jobs has been completed.

[root@control ~]# lvs -a -o +devices
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert Devices
root cl -wi-ao---- <28.55g /dev/sda2(555)
swap cl -wi-ao---- <2.17g /dev/sda2(0)
database_lv database_vg -wI-ao---- 1.99g /dev/sdd(0)
database_lv database_vg -wI-ao---- 1.99g pvmove0(0)
[pvmove0] database_vg p-C-aom--- 1020.00m /dev/sdc 100.00 /dev/sdc(0),/dev/sdd(255)
[1]- Done nohup pvmove /dev/sdb /dev/sdd
[root@control ~]#

7. Remove the old disk

After the successful migration we need to remove the old disk, make sure provide WWN lun id’s to remove the disk.

Using the vgreduce command we are going to remove the two old disk.

[root@control ~]# vgreduce database_vg /dev/sdb
Removed "/dev/sdb" from volume group "database_vg"
[2]+ Done nohup pvmove /dev/sdc /dev/sdd

[root@control ~]# vgreduce database_vg /dev/sdc
Removed "/dev/sdc" from volume group "database_vg"

8. Validate the migration

Now you can see the sdd is mapped to /database partition, the old device sdb and sdc are unused.

[root@control ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 31.7G 0 disk
|-sda1 8:1 0 1G 0 part /boot
`sda2 8:2 0 30.7G 0 part
|-cl-root 253:0 0 28.6G 0 lvm
`-cl-swap 253:1 0 2.2G 0 lvm [SWAP]
sdb 8:16 0 1G 0 disk
sdc 8:32 0 1G 0 disk
sdd 8:48 0 2G 0 disk
`-database_vg-database_lv 253:2 0 2G 0 lvm /database
sr0 11:0 1 1024M 0 rom
[root@control ~]#

Check now the total size of the vg and size of the physical volume added are same.

[root@control ~]# vgs
VG #PV #LV #SN Attr VSize VFree
cl 1 2 0 wz--n- 30.71g 0
database_vg 1 1 0 wz--n- <2.00g 4.00m
[root@control ~]#

A. Remove the Old Disks

Now we can remove the old disk from the physical volume.

[root@control ~]# pvremove /dev/sdb
Labels on physical volume "/dev/sdb" successfully wiped.

Remove the second disk

[root@control ~]# pvremove /dev/sdc
Labels on physical volume "/dev/sdc" successfully wiped.

B. Validate the physical volume

Recommended to reboot the server for the final validation, pvs command to display the physical volume

[root@control ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 cl lvm2 a-- 30.71g 0
/dev/sdd database_vg lvm2 a-- <2.00g 4.00m
[root@control ~]#

Hope you have understood Storage Migration using LVM, we can use it to large disk migrations, we will have minimal downtime with no impacts

Also refer LVM Howto https://computercarriage.com/2020/05/12/lvm-howto/https://computercarriage.com/2020/05/12/lvm-howto/

Refer LVM Configuration https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/logical_volume_manager_administration/lvm_overview

2 thoughts on “Kickstart Storage Migration using LVM

Leave a Reply