shrink linux guest vm in hyper-v
-
samedi 28 avril 2012 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?
Toutes les réponses
-
samedi 28 avril 2012 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.
-
samedi 28 avril 2012 12:48ModérateurHi,
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.
-
samedi 28 avril 2012 12:52
Vincent,
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.
-
lundi 30 avril 2012 12:37ModérateurHi,
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.
-
lundi 30 avril 2012 13: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.
-
lundi 30 avril 2012 14:53ModérateurHi,
Did you use fixed VHD or dynamic extending VHD for the Linux virtual machine?
-
lundi 30 avril 2012 17:35
Hi!
If the vhd is a fixed size vhd file, the size will be as a large as the virtual drive, not the partition within.
-
lundi 30 avril 2012 19:37dynamic
-
mercredi 2 mai 2012 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.
-
mercredi 2 mai 2012 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.
-
mardi 22 mai 2012 19:57
General directions can be found
http://blogs.msdn.com/b/virtual_pc_guy/archive/2005/08/23/454846.aspx
or http://thompsonng.blogspot.com/2011/04/ms-virtual-pc-compact-dynamic-virtual.html
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.

