2012年4月28日 上午 02:17Ok so i ran gparted on my suse linux vm in hyper-v. Now i want to shrink the vhd file. compact doesn't work unless i zero the free space. How does one do that? is there a tool for it?
2012年4月28日 上午 04:52
Is it a dynamic or Fixed VHD?
The structure of a fixed VHD is fairly simple. You can read the partition table and determine where the end of the last partition is, then just truncate the VHD and calculate a new footer. Dynamic VHDs are a bit more complex.
2012年4月28日 下午 12:48版主Hi,
If you are using a fixed VHD, there is no way to compact it. If it’s a dynamic extending VHD, you can delete the unneeded files within the VHD, power off the virtual machine(you can also detach the VHD file if you can), compact the VHD file with Hyper-V Manager.
2012年4月28日 下午 12:52
Remember this is linux not windows vm. In Linux i ave shrank the partition down to 25 GB from 50 GB. Then when i run compact from hyper-v it never shrinks since the extra space in the linux vhd needs to have zeros written to it before hyper-v can truly compact that space. That is my issue. hyper-v still sees that part of the vhd as begin used even though it is an unallocated partition.
2012年4月30日 下午 12:37版主Hi,
Did you use fixed VHD or dynamic extending VHD for the Linux virtual machine? If it’s a dynamic extending VHD, you may also try to perform some operating like disk defragment within the virtual machine before you compact it.
2012年4月30日 下午 01:56i used gparted to shrink the disk itself and when you do into the linux os it says it has the reduced disk space but the vhd is the original size. then when i go in and run compact it never compacts it.
2012年4月30日 下午 02:53版主Hi,
Did you use fixed VHD or dynamic extending VHD for the Linux virtual machine?
2012年4月30日 下午 05:35
If the vhd is a fixed size vhd file, the size will be as a large as the virtual drive, not the partition within.
2012年4月30日 下午 07:37dynamic
2012年5月2日 上午 09:08I have experience with compact a Linux VHD on Hyper-V. A new installed Ubuntu 10.10, and the size of the VHD is 50MB smaller than the original one after compact.
2012年5月2日 下午 12:18
well here is what i did.
1. in my linux VM i booted to gparted and reduced the size of my partition to 25 GB form 50 GB.
2. Restarted my linux vm and it reported only 25GB. I then shut it down.
3. on hyper-v host I right clicked my linux vm and clicked on settings.
4. clicked on the linux vm vhd file under hard drive and chose edit.
5. next i choose compact and it went through editing the virtual disk.
6. When it was done it isstill the same size 50 GB.
2012年5月22日 下午 07:57
General directions can be found
It sounds like you will need to actually create a new partiton in the free space under linux so that you can write out a file to zero the space. Then delete the zeroed partition and shrunk the disk in linux. Then compact the VHD with the VM shut down.