2

I have a virtual machine running Ubuntu 12.04 which I created using Hyper-V in a Windows 8.1 host. At one point, I had a very large file in my virtual machine which caused my dynamically expanding hard drive to grow to almost 200 GB. Since then, I have removed the file and I am trying to shrink the hard drive file back down. As you can see from this screenshot of GParted from within Ubuntu, I am not using a lot of disk storage:

192 GiB unused

I tried using the "compact disk" option within Hyper-V settings; however, this did not affect the size of the vhdx file in the host which remains close to 200 GB in size. I also tried following these instructions for using Windows' diskpart utility, but this also had no effect. Am I missing something? Is there something else I can try?

Daniel
  • 171

1 Answers1

0

I strongly suggest you take steps to make a copy of the .vhdx before you modify it. In order to change the size of an existing .vhdx file, you should first mount the virtual hdd by using the command: mount-vhd in an elevated PowerShell command prompt.

mount-vhd \\FS01\vmdata\AS02_C.vhdx -passthru | get-disk | get-partition | get-volume

The output of the command will look like

enter image description here

If you want to change the size of one of the partitions by using: resize-partition in an elevated PowerShell command prompt.

resize-partition -driveletter E -size 35GB

Before you can change the size of the virtual hdd you will have to use the command: dismount-vhd in an elevated PowerShell command prompt.

dismount-vhd \\FS01\vmdata\AS02_C.vhdx

Once you have modified the partition size and dismounted the virtual HDD, you can modify the size of the virtual hdd by using the command: resize-vhd in an elevated PowerShell command prompt.

resize-vhd \FS01\vmdata\AS02_C.vhdx -ToMinimumSize

Source: Resize-VHD

Ramhound
  • 44,080