Expand Linux LVM with free space from Hyper-V

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.

  1. Expand the disk in the Hypervisor
  2. Reboot the VM to recognize the change (there’s specific commands to do this as well)
  3. Run parted on your disk: parted /dev/sdb
  4. Change display unit to sectors: unit s
  5. Print current partition table and note the start sector for your partition: p
  6. Delete your partition (won’t delete the data or filesystem): rm <number>
  7. Recreate the partition with the starting sector from step 5 above: mkpart primary <start> -1
  8. Exit parted: quit
  9. Reboot the VM to recognize the new partition size
  10. Type the following to resize the physical volume: pvresize /dev/sdb1
  11. 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
  12. For any logical volume that you resized, you need to extend the ext4 partition: resize2fs /dev/volumegroup1/mylogicalvolume

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.