Dynamic disk resizing of virtual machines is available at Hyper-V in Windows Server 2012 R2. The online VHDX resizing function allows you to increase or decrease the size of the vhdx file of an online virtual machine (without stopping the VM). This article describes how to increase or decrease the disk size of a virtual machine in Hyper-V on Windows 10 or Windows Server 2016 (the instructions apply to all supported versions of Hyper-V, including the free Hyper-V server).
Main features and limitations of Hyper-V inline resizing of VHDX :
VMDrive extension in Hyper-V
You can increase the size of the VHDX virtual hard drive with the Hyper-V Manager console.
- Select the virtual machine in Hyper-V Virtual Machine Manager, go to VM settings -> Provision SCSI Controller ;
- Select the virtual hard drive and click Edit;
If the Edit button is inactive and the Edit alert is not available because there is a checkpoint for this virtual machine, you need to delete all snapshots. You may need to disable the Production checkpoint option in the VM properties. virtual machine.
- In the Virtual Disk Wizard that appears, select Extend; .
- Specify the new size of the virtual hard drive (in our example we increase the drive size to 170 GB);
- Navigate to the console of the guest operating system whose hard drive has been extended. Let’s see how to increase the system partition in a Windows guest operating system. Open the Disk Manager console. As you can see, there is 43 GB of additional unallocated hard disk space;
- Right click on the partition you want to expand and select Expand Volume (you can only expand the volume to the left of the unallocated space). Specify how much you want to increase the current volume;
- When the Expand operation is complete, the volume size is increased.
In the Linux guest operating system you can expand the disk using the parted utility.
How can I reduce the size of a Hyper-V virtual hard disk drive (VHDX)?
Now let’s see how you can reduce the size of the vhdx virtual disk on Hyper-V.
- Before reducing the size of the virtual disk through the Hyper-V console, you need to reduce the size of the logical partition on the disk in the guest operating system. Free up space and convert it to an unallocated volume. To do this, open Disk Manager in the guest operating system, select the disk and click Reduce volume;
Pay attention. The volume reduction option is only available if there is free space on the partitoid.
- Specify the space whose partition should be reduced (in our example we specified 50 GB); guest operating system
- After reducing the partition size in the guest OS, you need to open the Hyper-V console and go to the virtual disk settings. Click on the Edit button;
- In the virtual hard drive change wizard, select Shrink and specify the new vhdx file size. Note that you cannot make the disk smaller than the data it contains (check the minimum value). In our case, you can reduce the disk size from 40 GB to 31 GB; .
Try defragmenting the VHDX file with Hyper-V optimization before reducing it. In the previous form, select the option Compact. You can also use a PowerShell command to optimize and defragment a Hyper-V dynamic virtual hard drive. Optimize -VHD – path ‘C:VMVHDHyper-Vfs01.vhdx’
- It’s done.
Changing the file size of a Hyper-V virtual drive with PowerShell
You can resize a VHDX disk on a Hyper-V host using PowerShell. Use the Resize-VHD command (not to be confused with the Resize-VirtualDisk command, which is one of the built-in disk management commands in Windows).
Pay attention. It is not necessary to turn off the virtual machine to change the size of the virtual hard disk using the Resize-VHD command in recent versions of Hyper-V.
First, you need to determine the full path to the virtual machine’s VHDX disk:
Get-VM -VMName fs01 | Select VMId Object | Get-VHD
These commands also return the current size of the VHDX file in memory (FileSize) and the maximum size it can take (Size). MinimumSize is the minimum size of the VHDX drive to which the virtual hard drive file can be reduced.
To increase the size of the VHDX player, you need to specify the new size:
Resize-VHD – Path ‘C:VMfs01VHDfs01.vhdx’ – SizeByte 50GB
If you specify a new virtual disk size that is smaller than the size of the disk it occupies, an error occurs: Redimensioning the VHD: The size of the virtual hard disk cannot be changed.
Just adjust the partition size in the guest operating system.
You can remotely expand the drive in Windows using PowerShell Remoting. Use Invoke-Command or Enter-PSSession cmdletr to connect to the VM (on the network or via Hyper-V PowerShell Direct) :
Enter-PSSession -ComputerName fs01
We need information about expanding the partition to the maximum available size:
SizeMaxResize Partition -DriveLetter L – Size $MaxSize = (Get-PartitionSupportedSize -DriveLetter C).SizeMaxResize Partition -DriveLetter L – Size $MaxSize
If you need to minimize the size of the virtual hard drive, perform the following steps
Resize-VHD -Path ‘C:VMfs01VHDfs01.vhdx’ -Minimal size
This command reduces the maximum size of the VHDX file by 6 GB.
For instructions on adjusting the size of virtual disks in other hypervisors, see the following links: KVM, VMWare.
edit virtual hard disk,hyper v give vm more disk space,add drive to hyper-v virtual machine,hyper v expanding c drive,how to expand a vm hard drive,resize vhdx powershell,compact vhdx,reclaim unallocated disk space hyper-v,vhd resizer,hyper-v no shrink option,hyper-v compact vhdx not working,shrink vhd virtualbox,vhdresizer,increase vhd size virtualbox,resize-vhd is not recognized,expand vhdx without hyper-v,hyper-v disk format,expand vhdx,hyper-v extend volume greyed out,hyper-v remove checkpoints,expand virtual hard disk virtualbox,hyper-v resize disk ubuntu,edit is not available because checkpoints,hyper-v vm size,hyper-v volume,server 2016 shrink volume,hyper-v 2008 r2 shrink vhd,shrink static vhd,how to increase disk space on hyper-v virtual machine,hyper-v compact disk not working,hyper-v expand disk with checkpoints,how to expand hard drive hyper-v,hyper-v compact vhdx,hyper-v increase disk size ubuntu