Save to My DOJO
Table of contents
- An Overview of Hyper-V Disk Resizing
- Requirements for VHD/VHDX Disk Resizing
- How to Resize a Virtual Hard Disk with PowerShell
- How to Resize a Disconnected Virtual Hard Disk with Hyper-V Manager
- How to Resize a Virtual Machine’s Virtual Hard Disk with Hyper-V Manager
- Following Up After a Virtual Hard Disk Resize Operation
- VHDX Shrink Operations
- What About VHD/VHDX Compact Operations?
We get lots of cool tricks with virtualization. Among them is the ability to change our minds about almost any provisioning decision. In this article, we’re going to examine Hyper-V’s ability to resize virtual hard disks. Both Hyper-V Server (2016+) and Client Hyper-V (Windows 10) have this capability.
An Overview of Hyper-V Disk Resizing
Hyper-V uses two different formats for virtual hard disk files: the original VHD and the newer VHDX. 2016 added a brokered form of VHDX called a “VHD Set”, which follows the same resize rules as VHDX. We can grow both the VHD and VHDX types easily. We can shrink VHDX files with only a bit of work. No supported way exists to shrink a VHD. Once upon a time, a tool was floating around the Internet that would do it. As far as I know, all links to it have gone stale.
You can resize any of Hyper-V’s three layout types (fixed, dynamically expanding, and differencing). However, you cannot resize an AVHDX file (a differencing disk automatically created by the checkpoint function).
Resizing a virtual disk file only changes the file. It does not impact its contents. The files, partitions, formatting — all of that remains the same. A VHD/X resize operation does not stand alone. You will need to perform additional steps for the contents.
Requirements for VHD/VHDX Disk Resizing
The shrink operation must occur on a system with Hyper-V installed. The tools rely on a service that only exists with Hyper-V.
If no virtual machine owns the virtual disk, then you can operate on it directly without any additional steps. Be aware that if a
If a virtual hard disk belongs to a virtual machine, the rules change a bit:
- If the virtual machine is Off, any of its disks can be resized as though no one owned them
- If the virtual machine is Saved or has checkpoints, none of its disks can be resized
- If the virtual machine is Running, then there are additional restrictions for resizing its virtual hard disks
Special Requirements for Shrinking VHDX
Growing a VHDX doesn’t require any changes inside the VHDX. Shrinking needs a bit more. Sometimes, quite a bit more. The resize directions that I show in this article will grow or shrink a virtual disk file, but you have to prepare the contents before a shrink operation. We have another article that goes into detail on this subject.
Can I Resize a Hyper-V Virtual Machine’s Virtual Hard Disks Online?
A very important question: do you need to turn off a Hyper-V virtual machine to resize its virtual hard disks? The answer: sometimes.
- If the virtual disk in question is the VHD type, then no, it cannot be resized online.
- If the VM attached the disk in question to its virtual IDE chain, then no, you cannot resize the virtual disk while the virtual machine is online.
- If the VM attached the disk in question to its virtual SCSI chain, then yes, you can resize the virtual disk while the virtual machine is online.
Does Online VHDX Resize Work with Generation 1 Hyper-V VMs?
The generation of the virtual machine does not matter for virtual hard disk resizing. If the virtual disk is on the virtual SCSI chain, then you can resize it online.
Does Hyper-V Virtual Disk Resize Work with Linux Virtual Machines?
The guest operating system and file system do not matter. Different guest operating systems might react differently to a resize event, and the steps that you take for the guest’s file system will vary. However, the act of resizing the virtual disk does not change.
Do I Need to Connect the Virtual Disk to a Virtual Machine to Resize It?
Most guides show you how to use a virtual machine’s property sheet to resize a virtual hard disk. That might lead to the impression that you can only resize a virtual hard disk while a virtual machine owns it. Fortunately, you can easily resize a disconnected virtual disk. Both PowerShell and the GUI provide suitable methods.
How to Resize a Virtual Hard Disk with PowerShell
PowerShell is the preferred method for all virtual hard disk resize operations. It’s universal, flexible, scriptable, and, once you get the hang of it, much faster than the GUI.
The cmdlet to use is Resize-VHD:
Resize-VHD -Path '\svstore01VMsVirtual Hard Diskstest.vhdx' -SizeBytes 30gb
The VHDX that I used in the sample began life at 20GB. Therefore, the above cmdlet will work as long as I did at least one of the following:
- Left it unconnected
- Connected it to a VM’s virtual SCSI controller
- Turned the connected VM off
Notice the gb suffix on the SizeBytes parameter. PowerShell natively provides that feature; the cmdlet itself has nothing to do with it. PowerShell will automatically translate suffixes as necessary. Be aware that 1kb equals 1,024, not 1,000 (although both b and B both mean “byte”).
Had I used a number for SizeBytes smaller than the current size of the virtual hard disk file, I might have had some trouble. Each VHDX has a specific minimum size dictated by the contents of the file. See the discussion on shrinking at the end of this article for more information. Quickly speaking, the output of Get-VHD includes a MinimumSize field that shows how far you shrink the disk without taking additional actions.
This cmdlet only affects the virtual hard disk’s size. It does not affect the contained file system(s). We will cover that part in an upcoming section.
How to Resize a Disconnected Virtual Hard Disk with Hyper-V Manager
Hyper-V Manager allows you to resize a virtual hard disk whether or not a virtual machine owns it.
- From the main screen of Hyper-V Manager, first, select a host in the left pane. All VHD/X actions are carried out by the hypervisor’s subsystems, even if the target virtual hard disk does not belong to a specific virtual machine. Ensure that you pick a host that can reach the VHD/X. If the file resides on SMB storage, delegation may be necessary.
- In the far right Actions pane, click Edit Disk.
- The first page is information. Click Next.
- Browse to (or type) the location of the disk to edit.
- The directions from this point are the same as for a connected disk, so go to the next section and pick up at step 6.
Note: Even though these directions specify disconnected virtual hard disks, they can be used on connected virtual disks. All of the rules mentioned earlier apply.
How to Resize a Virtual Machine’s Virtual Hard Disk with Hyper-V Manager
Hyper-V Manager can also resize virtual hard disks that are attached to virtual machines.
- If the virtual hard disk is attached to the VM’s virtual IDE controller, turn off the virtual machine. If the VM is saved, start it. If the VM has checkpoints, remove them.
- Open the virtual machine’s Settings dialog.
- In the left pane, choose the virtual disk to resize.
- In the right pane, click the Edit button in the Media block.
- The wizard will start by displaying the location of the virtual hard disk file, but the page will be grayed out. Otherwise, it will look just like the screenshot from step 4 of the preceding section. Click Next.
- Choose to Expand or Shrink the virtual hard disk. Shrink only appears for VHDXs or VHDSs, and only if they have unallocated space at the end of the file. If the VM is off, you will see additional options. Choose the desired operation and click Next.
- If you chose Expand, it will show you the current size and give you a New Size field to fill in. It will display the maximum possible size for this VHD/X’s file type. All values are in GB, so you can only change in GB increments (use PowerShell if that’s not acceptable).
If you chose Shrink (VHDX only), it will show you the current size and give you a New Size field to fill in. It will display the minimum possible size for this file, based on the contents. All values are in GB, so you can only change in GB increments (use PowerShell if that’s not acceptable).
- Enter the desired size and click Next.
- The wizard will show a summary screen. Review it to ensure accuracy. Click Finish when ready.
The wizard will show a progress bar. That might happen so briefly that you don’t see it, or it may take some time. The variance will depend on what you selected and the speed of your hardware. Growing fixed disks will take some time; shrinking disks usually happens almost instantaneously. Assuming that all is well, you’ll be quietly returned to the screen that you started on.
This change only affects the virtual hard disk’s size. It does not affect the contained file system(s). We will cover that in the next sections.
Following Up After a Virtual Hard Disk Resize Operation
When you grow a virtual hard disk, only the disk’s parameters change. Nothing happens to the file system(s) inside the VHD/X. For a growth operation, you’ll need to perform some additional action. For a Windows guest, that typically means using Disk Management to extend a partition:
Note: You might need to use the Rescan Disks operation on the Action menu to see the added space.
Of course, you could also create a new partition (or partitions) if you prefer.
Linux distributions have a wide variety of file systems with their own requirements for partitions and sizing. They also have a plenitude of tools to perform the necessary tasks. Perform an Internet search for your distribution and file system.
VHDX Shrink Operations
As previously mentioned, you can’t shrink a VHDX without making changes to the contained file system first. Review our separate article for steps.
What About VHD/VHDX Compact Operations?
I often see confusion between shrinking a VHD/X and compacting a VHD/X. These operations are unrelated. When we talk about resizing, then the proper term for reducing the size of a virtual hard disk is “shrink”. That changes the total allocated space of the contained partitions. “Compact” refers to removing the zeroed blocks of a dynamically expanding VHD/VHDX so that it consumes less space on physical storage. Compact makes no changes to the contained data or partitions. We have an article on compacting VHD/Xs that contain Microsoft file systems and another for compacting VHD/Xs with Linux file systems.
Note: this page was originally published in January 2018 and has been updated to be relevant as of December 2019.
Not a DOJO Member yet?
Join thousands of other IT pros and receive a weekly roundup email with the latest content & updates!
15 thoughts on "How to Resize Virtual Hard Disks in Hyper-V"
That was an good guide for VHDX expansion though you haven’t touched upon Shared VHDX resize. Can you add that to this article or create one new. I understand Shared VHDX expansion was not possible in 2012 R2 but 2016 supports same. Would be good if you can shed some light on same.
what if you followed these kind of steps but the expanded, unallocated space does not appear in disk manager?
Because I struggled so much to resize a VM with CheckPoints, I’m sharing how I finally did it. Export the last CheckPoint. Redirect the VM to that checkpoint hard disk. This VM hard disk will be able to edit size. Start the VM, then expand the hard drive in disk manager. Good luck!
Hi Neil, that was super helpful. Much appreciated!
Now if I can just figure out how to resize the partition in my Ubuntu VM. Unless with a dynamic VHD will it expand the linux partition for me? Doesn’t seem to be doing that.
This was really helpful. Thanks!
Do you have any thoughts about resizing VHDX that used for a native boot(is it a right term)? My Win Server 2016 booted from vhdx, no VM, when I turn on my server instead of using a HDD, the system gets booted from vhdx. The problem is that I set the size of that vhdx – 40gb, and now I need to expend it to 100 gb. So my windows booted from vhdx that lay at hard drive F. When I open Hyper-V->edit disk I can choose that vhdx and it looks like I can change the size of it, but I’m afraid to proceed ’cause I don’t know what would happen. I assume the system kinda doesn’t know that that vhdx is the same vhdx it booted from. What is the worst scenario if I proceed? Would it work at all? For now server works quite stable and I don’t wanna risk doing it yet, but eventually, I’d need to do something with it.
Argh I hate boot from VHDX just because of this sort of thing.
I have not ever done it. However, VHDX resize works with an online VHDX and it will stop if it doesn’t like something. The boot portion doesn’t care about the size of the VHDX.
I suppose worst case scenario is that it renders the VHDX inoperative so your host won’t boot. The odds of that seem quite small due to resize’s architecture. The risk profile should not be any different than resizing the boot VHDX of a running virtual machine.
All the same, make sure that you have good backups.
I have run into what seems to be a limitation on expanding. I have a 600GB vhdx on a 1TB drive with around 300GB free. I thought great I just need to expand it but 100GB (700GB total) since I had 300 GB free. Nope it said “not enough space to perform the operation. It appears you need 2x the space to do it.
Does it make a new 700GB disk then copy from the original 600GB disk into the new 700GB?
Any ideas on how I resize it? Or do I need to put it on a larger drive (say 2TB) then perform the resize?
For a standard grow operation, it does not create a copy. To be honest, I’m not sure what the blocker is here. I’ve done things like this often. Moving it to a larger drive would probably work, but I can’t tell you why it doesn’t work now.