Extend the default Ubuntu virtual disk in Hyper-V

Published by Rhein-Ruhr-Informatik on

Overview

Prior to commencing the expansion process, it is imperative to comprehend that extending a virtual disk within the Hyper-V environment entails augmenting its allocated capacity. This action does not inherently result in the automatic population of the supplementary space with data. To effectively utilize the additional storage, it is necessary to manually extend the virtual machine's partitions and file systems, thereby enabling them to occupy the newly allocated space.

Before we dive into the steps, let's clarify why we might want to expand a Hyper-V VM's hard disk. This action is typically necessary when the virtual machine's existing storage capacity is insufficient to accommodate growing data or applications.


Access Hyper-V Manager

Windows 10/11: Search for "Hyper-V Manager" in the Start menu and open it.

First we need to shutdown the server:

On the virtual computer we click on the settings to configure the disk:

Under the Hardware menu we select the storage and on the right hand side we click on the Edit button to be able to continue this the next steps.


On the left hand side screen we select the Action, select Expand and then Continue:


As we see in the picture below under the Configure Data in the right-hand side there are 50GB. Here we can increase the size of the storage.


It is increased to 60GB as shown in the picture below:


After clickin OK, we have this picture in which we click again OK.


I have started the virtual machine:

After this steps in Hyper-V Manager, we start the virtual machine and going to extend LVM.

Via Putty tool we have to access our virtual machine:


Start by checking your root filesystem free space with df -hT. Our root disc is 62%. Now we gonna follow the steps to allocate 10 more GB to increase the percentage of our filesystem.


We enter the following commands parted -l adm type Fix to display the list of disks and partitions:


In the picture below we see that there is an error named: GPT PMBR size mismatchFirst we can fix it by typing the command correctin the error.


Now everything sims to be fine.


Now we can continue to extend our logical volume on /dev/sda3 filesystem as shown below:


First we use the command fdisk /dev/sda and continue with the other command showing below.

Now it is required to reboot the system

To check for existing free space on your Volume Group (where it is left by the installer default settings), run the command vgdisplay and lvdisplay check for free space.


After the computer has been restarted, we can use the command
lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
to extend the partition.


At this point you have increased the size of the block volume where your root filesystem resides, but you still need to extend the filesystem on top of it. First, run lsblk aus:


To verify our root file system, then run
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
to extend our filesystem:


Now as we see our LVM's size has increased to 48GB.


Conclusion


Overall, this guide provides a step-by-step process for expanding a Hyper-V VM's disk, addressing common challenges and ensuring optimal storage utilization

en_USEnglish