Expanding Ubuntu disk size in Hyper-V
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.
Turn off the Virtual Machine
Remove all checkpoints for the Virtual Machine
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)
A dialog window will allow you to adjust the drive size. Select the size you want to expand to.
Start the Virtual Machine
Start Terminal and install Guest Utils using this command
sudo apt install cloud-guest-utils
Expand the sda1 partition into the free space using this command (Note the space between the sda and 1)
sudo growpart /dev/sda 1
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!
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.