As in most if not all Volume managers, it is possible to move data (Physical Extents) from one disk to another in LVM and is quite simple to do. Also, we can move data from multiple disks or partitions (PVs) onto a single or multiple disks
Here we assume, we have the ability to add an additional disk(s) while the current disk(s) are still in place. This should not be a problem in a Virtual server while in physical you would need to have spare disk slots available.
I’m using a Virtual server here and use a small file system (/fstest) laid out on a single 1GB disk as follows:
[root@pulpserver1 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sdb lvm2 a-- 20.00g 20.00g /dev/sdc vgtest lvm2 a-- 1020.00m 0 [root@pulpserver1 ~]# vgs VG #PV #LV #SN Attr VSize VFree vgtest 1 1 0 wz--n- 1020.00m 0 [root@pulpserver1 ~]# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert lvtest vgtest -wi-ao--- 1020.00m [root@pulpserver1 ~]# df -h /fstest/ Filesystem Size Used Avail Use% Mounted on /dev/mapper/vgtest-lvtest 1004M 18M 936M 2% /fstest
NOTE: vgcreate or vgextend will automatically initiate a new disk when used to create or extend a volume so lets save ourselves from having to run pvcreate.
The task here is to move all data for the source volume group “vgtest” from device to /dev/sdc to /dev/sdd. Ensure the new disk is atleast of the same size or bigger than the disk we are replacing.
NOTE: I’ve already scanned for the new disk and is now visible to the OS. To know how to, click here
[root@pulpserver1 ~]# vgextend vgtest /dev/sdd No physical volume label read from /dev/sdd Physical volume "/dev/sdd" successfully created Volume group "vgtest" successfully extended [root@pulpserver1 ~]# vgs VG #PV #LV #SN Attr VSize VFree vgtest 2 1 0 wz--n- 2.99g 2.00g
You can see the additional disk space visisble in the volume size
2. Now, lets move the PEs from source disk to the new disk
[root@pulpserver1 ~]# pvmove /dev/sdc /dev/sdd /dev/sdc: Moved: 4.3% /dev/sdc: Moved: 100.0%
This should move the PEs and will show the progress in % as above
3. Once done, we can remove the old disk from the volume group
[root@pulpserver1 ~]# vgreduce vgtest /dev/sdc Removed "/dev/sdc" from volume group "vgtest" [root@pulpserver1 ~]# vgs VG #PV #LV #SN Attr VSize VFree vgtest 1 1 0 wz--n- 2.00g 1.00g
4. Now that the disk is no longer a part of the volume group, lets remove it from LVM altogethor (unless you plan to re-purpose it)
[root@pulpserver1 ~]# pvremove /dev/sdc Labels on physical volume "/dev/sdc" successfully wiped
It is a good practice to remove the disk from server completely unless it is going to be repurposed. To see how you can remove the disk from the host, click here