Expanding your Ubuntu disk running in a Virtual Machine in Windows Hyper-V

Expanding your Ubuntu disk running in a Virtual Machine in Windows Hyper-V

Expanding the size of a virtual hard disk for an Ubuntu instance running on Windows Hyper-V involves several steps. Here's a detailed guide to help you increase the disk space:

1. Shut Down the Ubuntu VM

Before modifying the disk, it's safest to shut down the virtual machine (VM). You can do this from within Ubuntu or using the Hyper-V Manager.

2. Expand the Virtual Hard Disk

  1. Open Hyper-V Manager: On your Windows host, open Hyper-V Manager.
  2. Select Your VM: Click on your Ubuntu VM in the list of virtual machines.
  3. Edit Virtual Hard Disk: With the VM selected, in the right-hand actions panel, click on Settings. Under the Hardware list, find and select the Hard Drive that you want to expand.
    1. If you are unable to click Edit, you likely have Checkpoints enabled in Hyper-V. To edit the hard drive you will need to merge or delete any existing checkpoints.
    2. To Delete Checkpoints:
      1. Open Hyper-V Manager: Start Hyper-V Manager on your Windows host.
      2. Select the Virtual Machine: Click on the virtual machine you want to modify.
      3. Inspect Checkpoints: In the lower right section of the Hyper-V Manager, you will see the Checkpoints section. Select the checkpoint you want to manage.
      4. Delete Checkpoint: Right-click on the checkpoint and choose Delete Checkpoint or Delete Checkpoint Subtree if you want to delete a checkpoint and all its descendants. This action merges the checkpoint data into the base virtual disk or into the next checkpoint in the hierarchy.
      5. Caution: Make sure that deleting the checkpoint won’t cause you to lose important data.
  4. Modify Disk: Click on the Edit button on the right side of the Virtual hard disk path. This opens the Edit Virtual Hard Disk Wizard.
  5. Choose Action: Select Expand and then click Next.
  6. Specify New Size: Enter the new size for your virtual disk. Make sure it's larger than the current size.
  7. Complete the Wizard: Follow through the wizard and apply the changes.

3. Start the Ubuntu VM

After the disk has been expanded, start your Ubuntu VM to make the operating system recognize the change.

4. Resize the Partition Within Ubuntu

To make use of the newly added space, you need to resize the partition and filesystem within Ubuntu.

  1. Identify the Disk: First, you need to identify the disk name and partition. Open a terminal and use the command: lsblk. This will list all the disks and partitions. Identify the partition you want to expand (commonly something like /dev/sda1).
  2. Check and Repair the Filesystem (if needed): It's good practice to check the filesystem integrity before resizing. You can do this with the command:
    sudo e2fsck -f /dev/sda1
    Replace /dev/sda1 with your partition identifier.
  3. Resize the Partition: If your root partition is directly resizable, you can use growpart:
    sudo apt update && sudo apt install cloud-guest-utils
    sudo growpart /dev/sda1

    This resizes the first partition on /dev/sda.
  4. Resize the Filesystem: Finally, resize the filesystem:
    sudo resize2fs /dev/sda1
    . This command expands the filesystem on the partition to use all available space.

5. Verify the Changes

Check that the filesystem now uses the new space:

 

df -h

 

This will show the disk space usage, and you should see that the available space has increased according to the changes you made.

Following these steps will allow you to successfully increase the disk size of your Ubuntu VM running on Windows Hyper-V.

Recent Comments

There are currently no comments. Be the first to make a comment.

Add Comment

Please add your comment by filling out the field(s) below. Your comment may need to be approved before it becomes visible.
Enter your first name for display with the comment
Enter your last name for display with the comment.
Enter your comment here.
If you can't type DNNRocks in, you can't post, plain and simple.
Submit Comment Cancel

Chris Hammond

Chris Hammond is a father, husband, leader, software developer, photographer and car guy. Chris focuses on the latest in technology including artificial intelligence (AI) and has spent decades becoming an expert in ASP.NET and DotNetNuke (DNN) development. You will find a variety of posts relating to those topics here on the website. For more information check out the about Chris Hammond page.

Find me on Twitter, GitHub and LinkedIn.