Linux Administration: Expand LVM

Background:

This Ubuntu server (Hyper-V VM) in question is a Docker host that was partitioned using the default layout (50/50 split of available disk space) when Ubuntu was installed. After a few month one of the logic volumes /dev/mapper/ubuntu--vg-ubuntu--lv ran out of space. Since there is no GUI for partition management, a few steps will be needed to properly expand the volume size.

Related article:

Solution:

1. Expand the virtual disk size in Hyper-V manager.

2. On the Ubuntu server, use fdisk -l to identify the disk and df -h to check the disk usage, here we use /dev/sdf (disk) and /dev/mapper/ubuntu--vg-ubuntu--lv (logic volume) as an example.

3. Run parted /dev/sdf print to view partition layout. You’ll probably get a warning message like the following. Which one you choose doesn’t really matter because we’ll be doing the process manually.

Warning: Not all of the space available to /dev/sdf appears to be used, you can fix the GPT to use all of the space (an extra ______ blocks) or continue with the current setting?
Fix/Ignore?

4. After you see the list of partitions, run this command on the partition that you need to expand to resize the partition to use the additional space, here we use partition 3 as an example: parted /dev/sdf resizepart 3 100%

5. Resize the Physical Volume using command: pvresize /dev/sdf3

6. Now that if you run vgdisplay , you should see the free space listed under Free PE / Size. And make sure you have your volume group name ubuntu-vg ready.

7. Run lvdisplay to identify the logical volume we need to expand, as we discussed above, the one needs expanding is the /dev/ubuntu-vg/ubuntu-lv volume.

8. Run lvextend -l +100%FREE -r /dev/ubuntu-vg/ubuntu-lv to expand the volume.

9. Now run vgdisplay , lvdisplay, and df -h again to verify that the /dev/mapper/ubuntu--vg-ubuntu--lv volume has been successfully expanded. Reboot the system if needed.