How to quickly expand Linux VM space in Hyper-V

Hey everyone!

Hope you are safe and doing great!

Sometimes, Linux VM machines may run out of available space inside. Regardless of the situation where you tried to install some additional software, or maybe you collected enough data on the VM - this is not the way how we want things to be done.

In this guide, we will go through the pretty simple and short solution of expanding space on a Linux VM in Hyper-V. In our example, we will use the current last version of Ubuntu 22.04. But you may use any other Linux distro which you prefer.

1. Find and identify, and expand the virtual drive of the VM in Hyper-V

1.1. Open Hyper-V Manager
1.2. Delete the VMs Checkpoints if they are exists
(Note - it is the required step to expand the VM drive, but you should keep in mind that you will not be able to use your old checkpoints after the deletion)

1.3. Under Action menu, hit Edit Disk... button

1.4. Locate your VM drive

1.5. Choose the Expand checkbox and hit Next button

1.6. Set the new desired size for the drive and hit Next

1.7. Review the plan and confirm it via hitting Finish button

2. Now our VM drive expanded, let's boot our Linux VM and check this via Disks tool

2.1. Check the expanded space in Disks

2.2. Identify your main device partition name

(Note - on the example on the screenshot, we have sda2)

3. Now let rock and added this space to our VM partition

3.1. Open terminal
3.1.1. Install necessary packages

sudo apt install cloud-guest-utils

3.1.2. Expand our sda partition

sudo growpart /dev/sda 2

(Note - the space between sda and 2)

3.1.3. Complete the expanding

sudo resize2fs /dev/sda2

(Note - no space between sda and 2)

3.2. Now check the results in Disks

You are awesome!

That is it. Hope this short guide helped you and saved your time for the best.

Thank you for reading and see you soon.