Seriously, how to compact a vdi?

Discussions related to using VirtualBox on Linux hosts.

Seriously, how to compact a vdi?

Postby nvivo » 29. Oct 2007, 14:27

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.
nvivo
 
Posts: 57
Joined: 4. Aug 2007, 17:08

Postby Ingo » 29. Oct 2007, 16:28

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?

Postby Ingo » 29. Oct 2007, 16:40

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?
Ingo
Volunteer
 
Posts: 731
Joined: 22. Aug 2007, 10:13
Location: Germany

Re: Seriously, how to compact a vdi?

Postby nvivo » 30. Oct 2007, 03:36

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?
nvivo
 
Posts: 57
Joined: 4. Aug 2007, 17:08

Postby Ingo » 30. Oct 2007, 09:13

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.
Ingo
Volunteer
 
Posts: 731
Joined: 22. Aug 2007, 10:13
Location: Germany

Postby nvivo » 31. Oct 2007, 14:48

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?
nvivo
 
Posts: 57
Joined: 4. Aug 2007, 17:08

Postby Hancoque » 5. Dec 2007, 06:48

You have to use "sdelete -c" and not "sdelete -z" to prepare a disk for compaction.
Hancoque
 
Posts: 2
Joined: 5. Dec 2007, 03:54

Postby FrankVdb » 10. Dec 2007, 22:52

Have you tried to restore the VDI afterwards?
Install Windows Vista in two minutes!
http://www.youtube.com/watch?v=FVbf9tOGwno
FrankVdb
 
Posts: 17
Joined: 6. Nov 2007, 23:04
Location: Flanders

Postby the_camel » 16. Dec 2007, 19:37

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
the_camel
 
Posts: 4
Joined: 11. Aug 2007, 12:36

Re: Seriously, how to compact a vdi?

Postby birdie » 21. Jun 2010, 19:31

dd works both on linux and Windows hosts.

Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
VBoxManage modifyhd Disk.vdi --compact


dd for windows can be downloaded here: http://www.chrysocome.net/dd
birdie
 
Posts: 194
Joined: 2. May 2010, 14:19
Primary OS: Linux other
VBox Version: PUEL
Guest OSses: Windows, Linux, other Unixes

Re: Seriously, how to compact a vdi?

Postby stefan.becker » 21. Jun 2010, 20:22

CloneVDI works faster as every other solution.
stefan.becker
Volunteer
 
Posts: 7169
Joined: 7. Jun 2007, 21:53

Re: Seriously, how to compact a vdi?

Postby Perryg » 21. Jun 2010, 20:27

You can run CloneVDI in Linux but it requires that you install Wine.
Perryg
Site Moderator
 
Posts: 29579
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX - Other

Re: Seriously, how to compact a vdi?

Postby kernelOfTruth » 23. Jan 2011, 21:31

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/sysinternals/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 ! :)
kernelOfTruth
 
Posts: 15
Joined: 4. Sep 2007, 23:41
Location: Vienna, Austria; Germany; hello world :)

Re: Seriously, how to compact a vdi?

Postby perkas » 25. Jan 2011, 10:46

Thank you for your help!! :wink:
perkas
 
Posts: 4
Joined: 2. Dec 2010, 09:57
Location: Spain
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: Windows7, MSDOS, Windows95, DRDOS, WINDOWS98, LINUX

Re: Seriously, how to compact a vdi?

Postby gammatwo » 14. Feb 2011, 12:48

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/nullfilenet-nullfile-in-net-way-or-zeroing-disk/ you can find all.

Bye

P.S.: For defragging I use UltraDefrag , it's open source.
gammatwo
 
Posts: 1
Joined: 14. Feb 2011, 12:18
Primary OS: Ubuntu other
VBox Version: PUEL
Guest OSses: Windows

Next

Return to VirtualBox on Linux Hosts

Who is online

Users browsing this forum: Google [Bot] and 12 guests