When creating a new virtual machine in Hyper-V with Ubuntu Server using the default settings, the partition is only allocated 60 GB instead of 127 GB (the default virtual hard disk size). There may be a setup option I missed, but the fix is to resize the partition after installation using the following commands:
First, check the partition table to view the current disk and partition sizes:
Shell
sudo fdisk -l
Identify the logical volume to extend, then expand it to use all available free space:
Shell
sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
Finally, resize the filesystem to match the new size of the logical volume:
Shell
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
If you expanded the virtual hard disk in Hyper-V, you may also need to run the following command so the OS recognizes the new size:
Shell
sudo growpart /dev/sda 3 # replace 3 with the partition number you want to resize
Do you have a question or a suggestion about this post? Contact me!