Complete Guide on How to Shrink and Compact Virtual Hard Disks in Hyper-V

When working with Hyper-V dynamically expanding disks, there is always a risk that those disks will grow uncontrollably and reach their maximum size in no time. The only way to deal with this issue is to regularly monitor disk size changes and then manually reconfigure the virtual hard disk properties. To ensure effective storage space allocation, you can either shrink or compact virtual hard disks.

In a nutshell, in order to shrink or compact virtual hard disks, you should do the following:

  1. Open Hyper-V Manager.
  2. Launch the Edit Virtual Hard Disk Wizard.
  3. Specify the virtual hard disk whose size you want to reduce.
  4. Select the action you want to perform (Shrink or Compact).
  5. Click Finish to accept the changes.

Read today’s blog post to learn more about Hyper-V dynamically expanding disks, which steps should be taken to shrink or compact virtual hard disks, and how NAKIVO Backup & Replication can protect your virtual infrastructure.

All You Need to Know About Hyper-V Dynamically Expanding Disks

What is a dynamically expanding disk? – Dynamically expanding disks are a type of disk which allows you to effectively use physical storage space. When you first create a dynamically expanding disk, it is small in size and only takes up the storage space that it actually needs.

A dynamically expanding disk grows when new data is added to it, thus allowing you to minimize storage costs. Moreover, dynamically expanding disks work well in testing and development environments, and are greatly compatible with servers running non-disk intensive applications.

How can you reduce the disk size? – If not monitored properly, a virtual hard disk can expand to its maximum size, thus consuming a lot of physical storage space. However, deleting files from the virtual hard disk will not resolve this issue. The only way to do this is to manually reconfigure the disk through shrinking or compacting.

When the disk has reached its maximum size, you should open the Edit Disk wizard in Hyper-V Manager and select whether you want to shrink or compact a virtual hard disk. Remember that the virtual machine (VM) should be turned off for these operations to work.

What is the difference between shrinking and compacting virtual hard disks? – When shrinking a Hyper-V disk, you reduce its maximum size limit. When compacting a Hyper-V disk, the physical disk space consumed by a virtual disk is reduced and unused physical disk space gets reclaimed.

The shrink option reduces the storage capacity of the virtual hard disk, while the compact option allows you to compact the file size of a virtual hard disk, leaving the storage capacity intact.

How to Change the Disk Size of a Hyper-V VM

In Hyper-V environment, you can shrink, convert, expand, merge, reconnect or compact a virtual hard disk by editing the corresponding file using either the GUI or CLI tools. Below, I am going to demonstrate how you can shrink or compact virtual hard disks using the Edit Virtual Hard Disk Wizard, found in Hyper-V Manager.

How to shrink virtual hard disks in Hyper-V

Any virtual hard disk type (fixed, differencing, and dynamically expanding) has a fixed upper size limit, which can be reduced using the shrink operation. To shrink the virtual hard disk of the selected VM, you should do the following:

1. In Hyper-V Manager, connect to the VM.Connecting to the VM (Hyper-V Shrink VHD)

2. After logging into the VM, launch the Disk Management utility by typing msc in the search bar.

3. Right-click the disk volume you would like to shrink, and select the Shrink Volume option.Shrink Volume (Hyper-V Shrink VHD)4. The next step is to enter the amount of space you wish to shrink in MB.Enter the Amount of Space to Shrink In MB (Hyper-V Shrink VHD)

As you fill out this property, the Total size after shrink in MB value will change automatically, thus showing you what the disk storage capacity will be after the shrink operation is complete.

5. Click Shrink to start shrinking the disk volume. As a result, you will have roughly 25 GB of unallocated disk space.

Unallocated Space (Hyper-V Shrink VHD)

6. After that, shut down the VM.

7. In Hyper-V Manager, right-click the VM and select Settings.

Virtual Machine Settings (Hyper-V Shrink VHD)

8. In the Hardware section, click Hard Drive to get access to the virtual hard disk settings.

Hard Drive Settings (Hyper-V Shrink VHD)

9. Select Edit to launch the Edit Virtual Hard Disk Wizard.

10. You can skip the Locate Disk step, as you have already selected which disk you would like to shrink. Click Next. 

Locate Disk (Hyper-V Shrink VHD)

11. In the Choose Action section, select Shrink and click Next.

Shrink Action (Hyper-V Shrink VHD)

12. The next step is to configure the new size of the virtual hard disk.

Configure Disk (Hyper-V Shrink VHD)

As you may notice, the difference between the current disk size and the minimum size is equal to the amount of extra disk space we have previously created inside the VM.

13. In the Summary section, you can look through the changes you are about to implement. Click Finish to complete the action and close the wizard.

Summary (Hyper-V Shrink VHD)

14. Click Inspect to verify that the disk size has actually changed and you have successfully shrunk the virtual hard disk.

Maximum Disk Size (Hyper-V Shrink VHD)

As you can see, the maximum disk size has been successfully reduced to 115 GB.

How to compact virtual hard disks in Hyper-V

Unlike shrinking, the compact operation doesn’t reduce the storage capacity of the virtual hard disk. This action reduces the file size of a virtual hard disk by removing empty blocks from the file. Note that you cannot compact fixed virtual hard disks.

Before compacting or shrinking a virtual hard disk, it is recommended that you empty the Recycle Bin, defragment the disk, and then create its backup to protect critical data in case of disk failure. Remember that the VM using the disk needs to be turned off for the compact operation to work.

1. Open Hyper-V Manager.

2. Right-click the VM and select Settings.

VM Settings (How to Compact Virtual Hard Disks)

3. Click Hard Drive to get access to the virtual hard disk attached to this VM.

4. Click Edit to launch the Edit Virtual Hard Disk Wizard.

Edit Virtual Hard Disk (How to Compact Virtual Hard Disks)

5. Skip the Locate Disk step as you have already selected the required virtual hard disk file, and click Next.

Locate Disk (How to Compact Virtual Hard Disks)

6. Select the Compact action.

Compact Action (How to Compact Virtual Hard Disks)

7. In the Summary section, you can verify the changes that are about to be made to the virtual hard disk. Click Finish to complete the action and close the wizard.

Summary (How to Compact Virtual Hard Disks)

8. Click Inspect to verify that the disk file size has been actually reduced.

So, why do you need to shrink or compact virtual hard disks? The answer is simple. The size of the virtual hard disk can be reduced only manually. If you decide to simply delete content, you will clear up space on the virtual hard disk, and not on the physical disk. To free up physical disk space, you need to either shrink or compact virtual hard disks, depending on your needs.

Data Protection with NAKIVO Backup & Replication

Before you can start with shrinking or compacting the virtual hard disk, it is always better to prepare for the worst-case scenario. An unexpected system error or bug can make your infrastructure entirely inaccessible. For this purpose, you need to ensure that data stored on the disk is securely protected and can be successfully recovered in case of disk failure.

NAKIVO Backup & Replication is a simple, yet powerful data protection solution, which can help you protect your VMware, Hyper-V, Nutanix, and AWS EC2 environments from anywhere and at any time. To be more precise, with NAKIVO Backup & Replication, you can:

  • Create image-based, agentless, incremental and application-aware backups of running VMs.
  • Save up to 1,000 recovery points for each data backup, which can be rotated on a daily, weekly, monthly, and yearly basis.
  • Reduce storage space requirements using swap file exclusion, deduplication, and compression.
  • Create copies of your existing backups and store these copies offsite or on the Cloud (Amazon or Azure).
  • Create and keep exact copies of source Hyper-V VMs on a target host using Hyper-V Replication. You can use these VM replicas for failover during a disaster recovery (DR) event.
  • Automate and orchestrate the entire disaster recovery process using Site Recovery (SR) workflows. By arranging various actions and conditions into an automated algorithm, you can address different DR scenarios of any complexity.
  • Run non-disruptive recovery testing of your SR jobs to ensure that your DR plan is workable and your recovery objectives can be met.
  • View all past, current, and future data protection jobs and easily schedule them in a few clicks using NAKIVO’s intuitive web interface.
  • Simplify data protection management by setting up policies that regularly scan your Hyper-V environment and automatically protect the VMs which match these policy rules.

Request a live demo by one of our engineers or download a full-featured free trial to test the product in your virtual environment today and see for yourself the multiple benefits that the NAKIVO Backup & Replication solution provides.

Complete Guide on How to Shrink and Compact Virtual Hard Disks in Hyper-V
5 (100%) 1 vote

Share: