Seriously, how to compact a vdi?

Discussions related to using VirtualBox on Linux hosts.
nvivo
Posts: 57
Joined: 4. Aug 2007, 17:08

Seriously, how to compact a vdi?

Post by nvivo »

I have been delaying this question for some time thinking I was doing something wrong... I have tried many scenarios and I can't compact a VDI.

I use Ubuntu Gutsy as host, VirtualBox 1.5.2. I have XP/NTFS as guest, and the machine/disk never had a snapshot.

From windows explorer, the disk has 4.6Gb occupied. I run defrag, then JkDefrag to compact everything on the beginning of the disk. The file had 7Gb in size then.

Then I run SDELETE -Z, and the file went to ~15Gb.

The drive map from windows defrag and from jkdefrag shows a huge empty area on the end of the disk.

Tried to run VBoxManage modifyvdi <file> compact and there was absolutely no change on the file size. Not even one byte.

I have been seeing many posts and bug tickets open about this, but never saw an answer.

Is this really a bug? Am I doing something wrong?

Thanks in advance.
Ingo
Volunteer
Posts: 731
Joined: 22. Aug 2007, 10:13
Location: Germany

Post by Ingo »

You are doing something wrong.
From the User Manual:
8.13 VBoxManage modifyvdi
The modifyvdi command can be used to compact disk images, i.e. remove blocks
that only contains zeroes. For this operation to be effective, it is required to zero out
free space in the guest system using a suitable software tool.
I use this nice tiny program for "nullifying" my paritions within the virtual machine.
http://www.feyrer.de/g4u/nullfile-1.02.pas
http://www.feyrer.de/g4u/nullfile-1.02.exe
Ingo
Volunteer
Posts: 731
Joined: 22. Aug 2007, 10:13
Location: Germany

Re: Seriously, how to compact a vdi?

Post by Ingo »

Oh sorry, I've just seen:
nvivo wrote:Then I run SDELETE -Z, and the file went to ~15Gb.
Does it zero out with null or with random values?
nvivo
Posts: 57
Joined: 4. Aug 2007, 17:08

Re: Seriously, how to compact a vdi?

Post by nvivo »

Ingo wrote:Oh sorry, I've just seen:
nvivo wrote:Then I run SDELETE -Z, and the file went to ~15Gb.
Does it zero out with null or with random values?
From what I have read, it writes zero, and it is the recomendation from the people here.

And it seems I'm not the only one... There are open tickets with no response about if this is going to be fixed or not.

http://www.virtualbox.org/ticket/28
http://www.virtualbox.org/ticket/709
http://forums.virtualbox.org/viewtopic.php?t=2218
http://forums.virtualbox.org/viewtopic.php?t=2246

I have read the manual and I know what it says.

But have anyone actually used it in real life?
Ingo
Volunteer
Posts: 731
Joined: 22. Aug 2007, 10:13
Location: Germany

Post by Ingo »

I've just tested the nice tiny program nullfile-1.02.exe and my VDI was shrunken from 3.2GB to 1.6GB.
It works. Give it a try.
nvivo
Posts: 57
Joined: 4. Aug 2007, 17:08

Post by nvivo »

Ingo wrote:I've just tested the nice tiny program nullfile-1.02.exe and my VDI was shrunken from 3.2GB to 1.6GB.
It works. Give it a try.
Well, that finally works! Thanks.
Just recovered 35Gb of space =)

Have anyone tried to compile this on linux guests? From this ticket ( http://www.virtualbox.org/ticket/28 ), dd doesn't seem to work...

Also, this info should be on the manual.

Or better, there should be a tool included in the guest additions that does this. I believe that VMWare "Shrink" option that can shrink the disk while running the VM does something similiar, right?
Hancoque
Posts: 2
Joined: 5. Dec 2007, 03:54

Post by Hancoque »

You have to use "sdelete -c" and not "sdelete -z" to prepare a disk for compaction.
FrankVdb
Posts: 17
Joined: 6. Nov 2007, 23:04
Location: Flanders

Post by FrankVdb »

Have you tried to restore the VDI afterwards?
Install Windows Vista in two minutes!
http://www.youtube.com/watch?v=FVbf9tOGwno
the_camel
Posts: 4
Joined: 11. Aug 2007, 12:36

Post by the_camel »

nvivo wrote: Have anyone tried to compile this on linux guests? From this ticket ( http://www.virtualbox.org/ticket/28 ), dd doesn't seem to work...
Try zerofree. See also here: Tip: (Better) Shrinking of Ext(2/3) partitions
birdie
Posts: 428
Joined: 2. May 2010, 14:19
Primary OS: Fedora other
VBox Version: PUEL
Guest OSses: Windows, Linux, other Unixes
Location: Artem S. Tashkinov
Contact:

Re: Seriously, how to compact a vdi?

Post by birdie »

dd works both on linux and Windows hosts.

Code: Select all

dd if=/dev/zero of=EMPTY bs=1M
rm/del EMPTY
and after you've blanked your virtual HDD, stop VirtualBox and run this command to compact VDI storage file:

Code: Select all

VBoxManage modifyhd Disk.vdi --compact
dd for windows can be downloaded here: http://www.chrysocome.net/dd
stefan.becker
Volunteer
Posts: 7639
Joined: 7. Jun 2007, 21:53

Re: Seriously, how to compact a vdi?

Post by stefan.becker »

CloneVDI works faster as every other solution.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Seriously, how to compact a vdi?

Post by Perryg »

You can run CloneVDI in Linux but it requires that you install Wine.
kernelOfTruth
Posts: 15
Joined: 4. Sep 2007, 23:41
Location: Vienna, Austria; Germany; hello world :)

Re: Seriously, how to compact a vdi?

Post by kernelOfTruth »

so to wrap it up

inside of your virtual machine

1) pick the defragment tool of your choice and configure it to pack data as close together as possible - leaving large areas of free space

(I used http://www.oo-software.com/free/en O&O Defrag Free Edition - a very potent free defrag utility 8) )

2) zero the free space with http://technet.microsoft.com/en-us/sysi ... s/bb897443 sdelete

sdelete -c C:\ (on C:\)

or whatever other drive



outside of the virtual machine - on your host

3) VBoxManage modifyhd Disk.vdi --compact


disk worked like a charm and gained me 9 GiB worth of additional harddrive space on my /home partition - and that was only one of those harddisks :D

Thanks ! :)
perkas
Posts: 5
Joined: 2. Dec 2010, 09:57
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: Windows7, MSDOS, Windows95, DRDOS, WINDOWS98, LINUX
Location: Spain

Re: Seriously, how to compact a vdi?

Post by perkas »

Thank you for your help!! :wink:
gammatwo
Posts: 1
Joined: 14. Feb 2011, 12:18
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Windows

Re: Seriously, how to compact a vdi?

Post by gammatwo »

I would suggest to you to not use sdelete, and to use instead a NullFile .NET program that I've writed, based on pascal NullFile version of Matthias Jordan.
It's really faster and contain full source code.
Here http://www.gammatwo.com/2011/01/16/null ... oing-disk/ you can find all.

Bye

P.S.: For defragging I use UltraDefrag , it's open source.
Post Reply