This page is a bit of an update from my last post on expanding Linux volumes.
The scenario is a pre-existing VHDX file that is mounted within a Debian virtual machine, which has used LVM to create volumes.
Now we want to expand that VHDX file, and then extend the pre-existing volumes without spanning new partitions.
- Expand the disk in the Hypervisor
- Reboot the VM to recognize the change (there’s specific commands to do this as well)
- Run parted on your disk: parted /dev/sdb
- Change display unit to sectors: unit s
- Print current partition table and note the start sector for your partition: p
- Delete your partition (won’t delete the data or filesystem): rm <number>
- Recreate the partition with the starting sector from step 5 above: mkpart primary <start> -1
- Exit parted: quit
- Reboot the VM to recognize the new partition size
- Type the following to resize the physical volume: pvresize /dev/sdb1
- Now you can re-allocate size to a logical volume by using the following (this adds 20G to existing size): lvextend -L+20G /dev/volumegroup1/mylogicalvolume
- For any logical volume that you resized, you need to extend the ext4 partition: resize2fs /dev/volumegroup1/mylogicalvolume