Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

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

January 19, 2022 Hyper-VPowerShellWindows 10Windows Server 2016

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
1
Facebook Twitter Google + Pinterest
previous post
Take a Screenshot of a User’s Desktop with PowerShell
next post
Copy AD Group Membership to Another User in PowerShell

Related Reading

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

October 15, 2023

How to Query and Change Teams User Presence...

October 8, 2023

How to Use Ansible to Manage Windows Machines

September 25, 2023

1 comment

DANILO March 18, 2016 - 12:26 pm

How to shrink  vhdx with IDE controller ?

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Windows Server Licensing for Virtual Environments
  • USB Device Passthrough (Redirect) to Hyper-V Virtual Machine
  • How to Install VMWare ESXi in a Hyper-V Virtual Machine?
  • Selecting the Number of vCPUs and Cores for a Virtual Machine
  • Import, Export and Clone Virtual Machines in Hyper-V
  • Hyper-V: Enabling Routing Between Internal Networks (Subnets)
  • How to Backup Hyper-V Virtual Machines?
Footer Logo

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


Back To Top