LVM allows you to hot add devices to expand volume space. It also allows you to hot remove devices, as long as there are enough free extents in the volume group (vgdisplay) to move data around. Here I’m going to replace a 400 GB drive (sdg) with a 750 GB one (sdh) from logical volume “backup” on volume group “disks”. It does not matter how many hard drives are in the volume group, and the filesystem can stay mounted.
- Partition and create a physical volume on the device
1
$ sudo pvcreate /dev/sdh1
- Add the new drive to the volume group
1
$ sudo vgextend disks /dev/sdh1
- Move all extents from the old drive to the new one (this step may take hours)
1
$ sudo pvmove -v /dev/sdg1
- Remove the old drive
1
$ sudo vgreduce disks /dev/sdg1
- Expand the logical volume to use the rest of the disk. In this case, another 350GB.
1
$ sudo lvextend -l+83463 /dev/disks/backup
- Expand the file system
1 2
$ sudo resize2fs /dev/disks/backup $ sudo xfs_growfs /dev/disks/backup
Hmm. You state: “…replace a 400 GB drive (sdg) with a 750 GB one (sdf) …”. Don’t you really mean (sdh)?
Yes. Fixed, thanks.