Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / Virtualization / Hyper-V / How to Extend or Shrink Virtual Hard Disks on Hyper-V?

January 19, 2022

How to Extend or Shrink Virtual Hard Disks on Hyper-V?

Dynamic resizing of virtual machine hard disks is available starting with Hyper-V in Windows Server 2012 R2. Online VHDX Resize feature allows you to increase or shrink the size of the vhdx file of a virtual machine online (without stopping the VM). In this article, we will look at how to extend or reduce (shrink) the size of a virtual machine hard disk in Hyper-V running on Windows 10 or Windows Server 2016 (instructions apply to all supported versions of Hyper-V, including free Hyper-V Server).

Contents:
  • Expanding VM Hard Disk in Hyper-V
  • How to Shrink the Size of Hyper-V Virtual Disk (VHDX)?
  • Resizing Virtual Hard Disk Files in Hyper-V with PowerShell

Key features and limitations of Online VHDX Resize in Hyper-V:

  • You can resize any type of Hyper-V virtual disk: fixed, dynamic, and differential;
  • You can resize the VHDX disk (including the system drive of the guest OS) on the fly. You don’t need to stop the VM;
    Only VHDXs can be dynamically resized. VHDs are not supported and have to be converted into the VHDX format.
  • VHDX disk must be connected to the VM through a virtual SCSI controller (online extension of disks on the IDE controller is not supported, such a VM will have to be turned off to change the disk size);
  • Online VHDX Resize works both on the first and the second generation of virtual machines Hyper-V;
  • Both Windows and Linux can act as a guest OS;
  • Both extension and shrinking of virtual disks are supported;
  • You can resize vhdx disk from Hyper-V graphical console, PowerShell or Windows Admin Center;
  • Resizing of shared VHDX (AVHDX) disks used in clusters is not supported;
  • You cannot change the size of the virtual disk for which the snapshot was created (for example, during a backup).

Expanding VM Hard Disk in Hyper-V

You can increase the size of the virtual VHDX disk using the Hyper-V Manager console.

  1. Select the virtual machine in the Hyper-V virtual machine manager, go to VM Settings -> expand SCSI Controller;
  2. Choose the virtual disk and click the Edit button;resize virtual disk on hyper-v
    If the Edit button is inactive, and the warning says “Edit is not available because checkpoint exist for this virtual machine”, you need to delete all snapshots. It may be necessary to disable the Production Checkpoint option in VM properties. vhdx Edit is not available because checkpoint exist for this virtual machine
  3. In the appearing Edit Virtual Hard Disk wizard choose Expand;expand vhdx file on windows hyper-v host
  4. Specify the new size of the virtual hard disk (in our example we’ll expand the disk size to 170 GB);expand vhdx file set new size
  5. Go to the console of the guest OS, which disk was extended. Let’s take a look at how to increase a system partition in a Windows guest OS. Open the Disk Manager console. As you can see, extra 43 GB of unallocated space appeared on the disk;unallocated space on virtual disk inside virtual machine
  6. Right-click the partition you want to extend and choose Extend Volume (you can only expand the volume to the left of the unallocated area). Specify how much you want to increase the current volume size;windows server - extend volume
    Sometimes volume extending can be blocked by the Windows recovery partition.
  7. After completing the Extend procedure, the volume size will be increased.
    In a guest Linux OS, you can expand the disk using the parted tool.

How to Shrink the Size of Hyper-V Virtual Disk (VHDX)?

Now let’s look at how to reduce the size of a virtual vhdx disk on Hyper-V.

  1. Before shrinking a virtual disk from the Hyper-V console, it is necessary to reduce the size of the logical partition on the disk inside the guest OS. Free up some space and convert it to the unallocated volume. To do it, open the Disk Manager in the guest OS, select a volume and click  Shrink Volume;how shrink volume in windows
    Note.  Shrink Volume option becomes available only if there is some free space on the partition.
  2. Specify the amount of space to shrink the partition by (in our example we specified 50GB);Shrink partition in guest windows os
  3. After reducing the size of the partition in the guest OS, you need to open the Hyper-V console and go to the virtual disk settings. Press the Edit button;
  4. In the Edit Virtual Hard Disk wizard, select Shrink, then specify a new size for the vhdx file. Please note that you cannot make the disk smaller than the data on it (check the Minimum value). In our case, you can reduce the disk size from 40 to 31 GB; shrink virtual hard disk file using hyper-v manager
    Before shrinking the VHDX file, try defragmenting it with Hyper-V Optimization. In the previous form, select the Compact option. Alternatively, you can use the PowerShell command to optimize and defragment a Hyper-V dynamic virtual disk.: Optimize-VHD -Path 'C:\VM\VHDHyper-V\fs01.vhdx' compact virtual disk in windows 
  5. Done.

Resizing Virtual Hard Disk Files in Hyper-V with PowerShell

You can resize the VHDX disk on Hyper-V host using PowerShell. To do this, use the Resize-VHD cmdlet (not to be confused with Resize-VirtualDisk cmdlet, which belongs to the built-in Windows disk management cmdlets).

Note. You don’t need to turn off the virtual machine in order to resize a virtual disk using the Resize-VHD cmdlet in current versions of Hyper-V.

First, you need to get the full path to the VHDX disk of the virtual machine:

Get-VM -VMName fs01 | Select-Object VMId | Get-VHD

These cmdlets also returns the actual size of the VHDX file on the storage (FileSize) and the maximum size that it can take (Size). MinimumSize is the minimum VHDX disk size to which a virtual disk file can be reduced.

get vhdx virtual disk size on hyper-v via powershell

In order to increase the size of the VHDX disk, you need to specify its new size:

Resize-VHD -Path 'C:\VM\fs01\VHD\fs01.vhdx' -SizeBytes 50Gb

If you specified the new size of the virtual disk less than it takes on the disk, an error will appear: Resize-VHD : Failed to resize the virtual disk.

You just need to resize the partition in the guest OS.

You can expand a disk on Windows remotely using PowerShell Remoting. Connect to the remote VM using the Invoke-Command or Enter-PSSession cmdlet (over the network or via Hyper-V PowerShell Direct):

Enter-PSSession -ComputerName fs01
You need to get information on how much you can expand the partition and expand it to the maximum available size:

$MaxSize = (Get-PartitionSupportedSize -DriveLetter C).SizeMax
Resize-Partition -DriveLetter L -Size $MaxSize

If you need to shrink the size of the virtual disk to the smallest possible size, run:

Resize-VHD -Path 'C:\VM\fs01\VHD\fs01.vhdx' -ToMinimumSize

shrink vhdx disk on hyper-v with powershell

This command will reduce the maximum VHDX file size by 6 GB.

Instructions for resizing virtual disks in other hypervisors are available at the following links: KVM, VMWare.
1 comment
4
Facebook Twitter Google + Pinterest
Hyper-VPowerShellWindows 10Windows Server 2016
previous post
Taking User Desktop Screenshots with PowerShell
next post
Copy AD Group Membership to Another User in PowerShell

Related Reading

How to Enable and Configure Hyper-V Remote Management

June 8, 2023

How to Install and Configure Free Hyper-V Server...

March 16, 2024

Poor Network Performance on Hyper-V VMs in Windows...

February 20, 2023

USB Device Passthrough (Redirect) to Hyper-V Virtual Machine

March 15, 2024

Windows Cannot Find the Microsoft Software License Terms

April 19, 2023

Configure SR-IOV for Hyper-V Virtual Machines on Windows...

March 29, 2022

Import, Export and Clone Virtual Machines in Hyper-V

January 19, 2022

Hyper-V Virtual Machine Stuck in Stopping/Starting State

March 16, 2024

1 comment

DANILO March 18, 2016 - 12:26 pm

How to shrink  vhdx with IDE controller ?

Reply

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • Map a Network Drive over SSH (SSHFS) in Windows

    May 13, 2025
  • Configure NTP Time Source for Active Directory Domain

    May 6, 2025
  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • USB Device Passthrough (Redirect) to Hyper-V Virtual Machine
  • Hyper-V: Enabling Routing Between Internal Networks (Subnets)
  • How to Backup Hyper-V Virtual Machines (Tutorial)
  • Selecting the Number of vCPUs and Cores for a Virtual Machine
  • Import, Export and Clone Virtual Machines in Hyper-V
  • Hyper-V: Configuring Automatic Startup and Boot Order of VMs
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top