shrink a VHD file

Hi, I have a VHD file with server 2012 on it. There is a 120GB drive in it, with 20GB used. The VHD is 44GB. I tried to compact it with Hyper-V and powershell (Resize-VHD –Path "C:\xxx.vhd" –ToMinimumSize) without any success.

Is it possible to bring it closer to its actual size, 20GB ?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

andreasSystem AdminCommented:
Before compacting the drive you need to zero out unused space. The compacting algo can only remove space that contains zeros.
Muhammad BurhanManager I.T.Commented:
what os you are using in VM?
If it windows so go in Disk Management shrink the volume as desired.
Left that space as unallocated.
shut down VM
at Hyper-V manager click on edit disk, select that VM's disk an edit/shrink it.
Muhammad BurhanManager I.T.Commented:
a 120GB VHD wont actually occupied 120GB as it created dynamically expanded disk by default.
so you dont have to worry about the space, if it 20gb used as VM's storage it just took physically 20GB too..
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Benjamin VoglarIT ProCommented:

Do the folowing steps:

1. Shutdown VM
2. Mount the VHD. (duble click on it)
3. Download the sdelete tool:
4. run cmd with admin rights and enter command: sdelete -s -z e:  (e: if vhd is mounted on E)
5. dismount e:  (right click on e: and eject)
6. run hyper-v console and select edit disk, browse to vhd and choose "Compact disk"
7. END :)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ti-guyAuthor Commented:
Thanks, this method worked perfectly.
Benjamin VoglarIT ProCommented:
Yes, I know ;)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.