Expanding The Size of a Hyper-V Virtual Disk

Introduction

There are tasks that we all do, but rarely. It’s helpful to have a reference to go back to.

Expanding the size of a Virtual Hard Disk, or VHDX file, is one of those. I use Hyper-V quite a bit to create virtual machines for testing, development, and the like. Every so often though I’ll underestimate the amount of space I’ll need for a machine.

As it turns out expanding the drive size isn’t terribly difficult, but there’s quite a few steps involved. This post will server as a reminder to myself, and hopefully guide others, in expanding the size of a VM drive.

I’ll break this into two parts. In the first half, we’ll see how to expand the drive within Hyper-V. This will expand the VHDX file to a new larger size.

In the second half, we’ll go into the Windows running in the VM to tell it to use the newly expanded space.

Expanding the Drive in Hyper-V

Begin by opening Hyper-V. In the Hyper-V manager, click on Edit Disk in the Actions.

This will open the Edit Virtual Hard Disk Wizard.

If this is the first time you’ve run the wizard, you’ll see a welcoming screen. If you see this, I’d suggest clicking on “Do not show this page again” and clicking Next.

Now use the Browse… button to locate the VHDX file you wish to modify. Once you’ve done that, click Next.

Now we’ll select the action, in this case we’ll pick the Expand option and click Next.

Now we’ll enter a new size for the drive. It shows the current size as 250 GB, so I’ve entered 500 so I can double the size. Obviously you’ll enter a size appropriate to your needs.

Once done, click Next.

On the final page of the wizard it shows what is about to happen. It lists the name of the VHDX file we’re working on, what the action is (Expand), and what the size will be of the new drive.

Just click Finish and the VHDX file will be updated.

Accessing The Expanded Space in Windows

In this example we’ll be using Windows 10 inside our Virtual Machine. Go ahead and start, then connect to your Windows 10 Virtual Machine.

If you go into File Explorer you’ll see something interesting.

Even though we expanded the VHDX to 500 GB, our virtual machine still thinks the C drive is 249 GB.

What we need to do is expand the already existing drive into the newly allocated space.

In the Windows 10 menu, go down to Windows Administrative Tools, then pick Computer Management.

The Computer Management window has a tree on the left. If the Storage tree is not expanded, do so and click on the Disk Management branch.

In the screen capture above, you can see the orange arrow is pointing to the existing C drive area. To the right of that a green arrow points to the newly added but still unallocated space.

Right click in the C: drive area, and in the menu that appears select Extend Volume…

The Extend Volume Wizard now appears, just click Next to proceed past the welcome screen.

By default the wizard will put the only unallocated partition in the selected area, but if you have more than one unallocated partition you can select a different one.

At the bottom, the “Total volume size will” show the total amount of space on the new drive, once the unallocated space has been added.

The next line shows the maximum space in the unallocated partition.

The final line allows you to select the total amount of space to pull from the unallocated area. By default it is set to the max space in the unallocated area, but if for some reason you want to save some of that you can lower the amount.

In this case I’ll take the default options and click Next.

You’ve now reached the final screen of the wizard, just click Finish to have it do its work.

The Computer Management window now shows the expanded C drive. You can now close the Computer Management window.

If you go back to the File Explorer and refresh it, your C drive will now show the new size.

Conclusion

In this article, we expanded the size of a Hyper-V virtual hard disk (VHDX) that hosted a Windows 10 installation. As you saw, it was pretty simple to do, but did require a few steps.

Hopefully you’ll find this useful in working with your Hyper-V machines.

Advertisement

Adjust the Screen Resolution of an Ubuntu Hyper-V Virtual Machine

I use Ubuntu for a lot of the courses I teach, due to its popularity. While I have some computers running it “bare metal” as they say, in order to test different scenarios, as well as record my Pluralsight courses, I also setup virtual machines within Hyper-V.

It’s a bit annoying though, as it doesn’t seem to allow the guest extensions to easily resize the VM. (I create my VMs from the downloaded ISOs as opposed to using the pre-built images in the Hyper-V store). But it can be done! All you need is a few quick edits to the grub file.

Start by opening up a terminal window. Then you can use your favorite editor to open the grub file. I’m using VIM in this example, but you could substitute nano or another text editor of your choice. (I’ll assume you know how to use your editor to edit and save changes.)

sudo vim /etc/default/grub

Now scroll down and find the line that begins with GRUB_CMDLINE_LINUX_DEFAULT. To the end of it, append the following string:

video=hyperv_fb:1280x720

Or use 1920×1080, 2560×1440, or whatever resolution you prefer. The line should look something like the following, all on one line without any wrapping.

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash video=hyperv_fb:1280x720"

Looking good, but you’re not quite done yet. You’ll need to append the same to the next line so it looks similar to the following, again all on one line with no wrapping.

GRUB_CMDLINE_LINUX="quiet splash video=hyperv_fb:1280x720"

Of course, you’ll want to make sure the resolution you select matches on both lines, 1920×1080, etc.

Now save the contents and exit your editor.

Next, and this is an important step, you have to update grub using the following command:

sudo update-grub

If you skip this step, you won’t see your resolution updated.

Finally, you’ll need to reboot. I’ve not had great success with doing a reboot of Ubuntu running in Hyper-V, it frequently hangs, so I suggest doing a power off, then start Ubuntu again in Hyper-V.

When it does reboot, you should be running at your new resolution.