Post date: Jan 13, 2015 9:32:17 PM
The method described here has five steps:
The corresponding sequence of commands is as follows:
pvcreate /dev/sdc
vgextend vg0 /dev/sdc
pvmove /dev/sdb /dev/sdc
vgreduce vg0 /dev/sdb
pvremove /dev/sdb
Optionally, initialise the new storage device as a physical volume
With older versions of LVM it was necessary for physical volumes to be explicitly initialised using pvcreate before being added to a volume group:
pvcreate /dev/sdc
As of version 2.02.54 this is no longer necessary because initialisation will occur automatically if required. Prior initialisation may still be desirable in order to deviate from the default settings used by pvcreate, obtain better diagnostics by proceeding one step at a time, or retain compatibility with older versions of LVM.
Add the new physical volume to the volume group
A physical volume can be added to a volume group using the vgextend command:
vgextend vg0 /dev/sdc
The first argument is the name of the volume group to be extended. This can be written as a pathname if you prefer (/dev/vg0). Subsequent arguments are the physical volumes to be added.
If successful you should see a response of the form:
Volume group "vg0" successfully extended
If the physical volumes have not previously been initialised using pvcreate then there will be some additional diagnostic messages, for example:
No physical volume label read from /dev/sdc
Physical volume "/dev/sdc" successfully created
Volume group "vg0" successfully extended
You can check that the physical volume has been added using the pvs command:
pvs
If successful then you should see a response of the form:
PV VG Fmt Attr PSize PFree
/dev/sdb vg0 lvm2 a- 100.00g 0
/dev/sdc vg0 lvm2 a- 200.00g 200.00g
The VG column indicates which volume group each physical volume is a member of (if any). In this instance it shows (as expected) that both /dev/sdb and /dev/sdc are members of vg0.
Migrate all data located on the old physical volume to the new physical volume.
Data can be transferred from one physical volume to another using the pvmove command:
pvmove /dev/sdb /dev/sdc
The first argument is the physical volume to be emptied. The second argument is the physical volume to which the content should be moved. For large storage devices the transfer can take a considerable amount of time, however the machine should remain usable during this period so pvmove can be left to run in the background. It is safe to continue using filing systems that are wholly or partly located within the physical volume that is being moved.
pvmove periodically reports the progress it has made as a percentage, returning control when the transfer is complete. If it is interrupted for any reason then the transfer can be resumed by executing pvmove again with no arguments.
You can check that the migration was successful using the pvs command again. The response should show that the source physical volume contains no data (and therefore that PFree is equal to PSize):
PV VG Fmt Attr PSize PFree
/dev/sdb vg0 lvm2 a- 100.00g 100.00g
/dev/sdc vg0 lvm2 a- 200.00g 100.00g
Remove the old physical volume from the volume group.
A Physical volume can be removed from a volume group using the vgreduce command:
vgreduce vg0 /dev/sdb
The first argument is the name of the volume group. Subsequent arguments are the names of physical volumes to be removed. If successful you should see a response of the form:
Removed "/dev/sdb" from volume group "vg0"
You can check that the physical volume has been removed using the pvs command again. The response should show that the source physical volume is no longer a member of any volume group:
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 a- 100.00g 100.00g
/dev/sdc vg0 lvm2 a- 200.00g 100.00g
Optionally, wipe the label from the old storage device to prevent it from being detected as a physical volume
LVM will continue to recognise the old storage device as a physical volume (albeit an empty one) unless you take explicit action to wipe the label that was written by pvcreate. This can be done using the pvremove command:
pvremove /dev/sdb
If successful you should see a response of the form:
Labels on physical volume "/dev/sdb" successfully wiped
Leaving the label in place is not necessarily harmful, but it can cause confusion in some circumstances. For example, repartitioning a hard drive can result in LVM discovering physical volumes that are the wrong size for the drive layout. Use of pvremove is therefore recommended unless there is a reason not to.