VHD won't compact/shrink
- I have a brand new VM with a Dyamic VHD which I just built which I'm intending to use as a base image. Loaded up the O/S and applications - updated everything. I then went and deleted all of the $NTUNINSTALL directories, set the SFC Cache to 0 and purged it, and deleted all temp files. This freed up over 2 gig of space on the drive.
I shutdown the VM and proceeded to run the Compact routine on the VHD. It mounts - runs for a bit - then exits. However - the VHD file has not shrunk at all.
Running W2K8 Enterprise (RTM) with Hyper-V RC-1
Joseph W. Leathlean
Answers
Hi Joseph,
Before compacting the virtual hard disk, have you ever tried to defragment the volumes from virtual machines and compact the volumes using a tool such as the virtual hard disk precompactor? If not, would you please try this as follows and see if it can help:
1. Start the virtual machine and in the virtual machine, run the Disk Defragmenter tool.
2. Get a tool that can be used to change all empty space on a virtual hard disk to zero, such as virtual hard disk precompactor. Run this tool in the virtual machine to prepare the virtual hard disk. This may take a few minutes as it needs to overwrite all the blank space.
3. After the above two steps, try compacting the virtual hard disk from the Hyper-V Manager console and see how it goes.
Here is an article just for your reference:
http://support.microsoft.com/kb/888760
I hope this can help.
Best regards,
Chang Yin
- Marked As Answer byChang Yin Monday, June 09, 2008 7:46 AM
- Yes - that might cause an issue. Can you convert the disk back to basic, or create another VM with a basic disk and repeat the steps?
This posting is provided "AS IS" with no warranties, and confers no rights.- Marked As Answer byChang Yin Monday, June 09, 2008 7:46 AM
- Proposed As Answer byMike Sterling [MSFT]MSFT, OwnerMonday, June 02, 2008 3:42 PM
All Replies
- What was the size before and after?
This posting is provided "AS IS" with no warranties, and confers no rights. - It was approx 7.5 gig both before and after. If there was any shrinkage - it wasn't noticable...
I was reading some other threads. When I was installing the O/S - I converted the partition to Dynamic - could that be the cause?
Joseph W. Leathlean - Yes - that might cause an issue. Can you convert the disk back to basic, or create another VM with a basic disk and repeat the steps?
This posting is provided "AS IS" with no warranties, and confers no rights.- Marked As Answer byChang Yin Monday, June 09, 2008 7:46 AM
- Proposed As Answer byMike Sterling [MSFT]MSFT, OwnerMonday, June 02, 2008 3:42 PM
Hi Joseph,
Before compacting the virtual hard disk, have you ever tried to defragment the volumes from virtual machines and compact the volumes using a tool such as the virtual hard disk precompactor? If not, would you please try this as follows and see if it can help:
1. Start the virtual machine and in the virtual machine, run the Disk Defragmenter tool.
2. Get a tool that can be used to change all empty space on a virtual hard disk to zero, such as virtual hard disk precompactor. Run this tool in the virtual machine to prepare the virtual hard disk. This may take a few minutes as it needs to overwrite all the blank space.
3. After the above two steps, try compacting the virtual hard disk from the Hyper-V Manager console and see how it goes.
Here is an article just for your reference:
http://support.microsoft.com/kb/888760
I hope this can help.
Best regards,
Chang Yin
- Marked As Answer byChang Yin Monday, June 09, 2008 7:46 AM
- Yes - I had run the degragmenter prior to trying to compact the VHD. I actually ran it twice.
I'm in the process of rebuilding the base VHD now without converting it to Dynamic - I'll see if that solves the issue. If not - I'll try the steps listed and let you know.
Thanks
Joseph W. Leathlean - Ok - I built a quick 2003 image with a Basic Drive, defragged twice, shutdown the O/S, made a copy of the VHD, Shrank the VHD - it worked.
Restored the VHD using the copy - restarted 2003 - converted to dynamic - shutdown - tried to shrink the VHD - no affect.
It appears that VHD's where the disk is converted to Dynamic will not shrink. Don't know if this is a bug or as designed.
Not a big problem - I had previously just used dynamic disks in case I wanted to experiment with raid options. I'll just build my images with basic disks.
Joseph W. Leathlean

