shrink linux guest vm in hyper-v
-
28 Nisan 2012 Cumartesi 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?
Tüm Yanıtlar
-
28 Nisan 2012 Cumartesi 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.
-
28 Nisan 2012 Cumartesi 12:48ModeratörHi,
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.
-
28 Nisan 2012 Cumartesi 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.
-
30 Nisan 2012 Pazartesi 12:37ModeratörHi,
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.
-
30 Nisan 2012 Pazartesi 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.
-
30 Nisan 2012 Pazartesi 14:53ModeratörHi,
Did you use fixed VHD or dynamic extending VHD for the Linux virtual machine?
-
30 Nisan 2012 Pazartesi 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.
-
30 Nisan 2012 Pazartesi 19:37dynamic
-
02 Mayıs 2012 Çarşamba 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.
-
02 Mayıs 2012 Çarşamba 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.
-
22 Mayıs 2012 Salı 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.