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 ?

Thanks,

Guillaume
ti-guyAsked:
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.
0
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.
0
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..
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Benjamin VoglarIT ProCommented:
Hi.

Do the folowing steps:

1. Shutdown VM
2. Mount the VHD. (duble click on it)
3. Download the sdelete tool: https://technet.microsoft.com/en-us/sysinternals/bb897443.aspx
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 :)
0

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.
0
Benjamin VoglarIT ProCommented:
Yes, I know ;)
0
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
Hyper-V

From novice to tech pro — start learning today.