Expanding Ubuntu disk size in Hyper-V

DoufuDoufu
1 min read

A few months ago, I created a Ubuntu virtual machine using Hyper-V quick create feature in Windows 11. It was a seamless and hassle-free experience. Unfortunately, I had not anticipated that I would be out of disk space in such a short space of time. In hindsight, I should have allocated more disk space when I first started. Thankfully, it is not too difficult to expand the virtual disk size.

Here are the steps to increase the size of your disk.

  1. Turn off the Virtual Machine

  2. Remove all checkpoints for the Virtual Machine

  3. In Hyper-V Manager, select the settings of the Virtual Machine, then select and edit the Virtual hard disk that you want to expand. (If you had not removed the checkpoints for the VM, this option is disabled)

  4. A dialog window will allow you to adjust the drive size. Select the size you want to expand to.

  5. Start the Virtual Machine

  6. Start Terminal and install Guest Utils using this command
    sudo apt install cloud-guest-utils

  7. Expand the sda1 partition into the free space using this command (Note the space between the sda and 1)
    sudo growpart /dev/sda 1

  8. Lastly, run resize2fs command (Note no space between sda and 1)
    sudo resize2fs /dev/sda1

Now you have completed expanding your Virtual Machine disk size!

0
Subscribe to my newsletter

Read articles from Doufu directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Doufu
Doufu

Current project developments on Microsoft platforms such as Business Central, Dynamics 365 Sales, Power Platform and occasionally Python. Used to get my paws dirty on Android and Web development.