Page 1 of 1

[Solved] Shrink VDI size

Posted: 23. Sep 2009, 11:59
by Geolilli
Hi!

I have a WinXP guest (host Vista) and I want to shrink the VDI. It has grown strongly because I accidentally produced large files within the guest system. I deleted the files, but, however, the VDI size was not reduced.
How can I shrink the VDI?

Regards
Lilli

Re: Shrink VDI size

Posted: 23. Sep 2009, 12:18
by Sasquatch
You can use the VBoxManage modifyhd --compact method, but check the sticky here first. The Clone VDI tool from mpack does a good job. If you don't want to have to register the new VDI, untick the 'New UUID' checkbox, save the file as a new one, rename the original for backup purposes and rename the clone to the original VDI name. VB won't notice the change. If everything works properly with the clone, you can remove the original file.

Re: Shrink VDI size

Posted: 23. Sep 2009, 12:25
by mpack
Sasquatch wrote:save the file as a new one, rename the original for backup purposes and rename the clone to the original VDI name.
Hi Sasquatch: actually, if you just give CloneVDI the same complete (path and tail) filename for both source and destination then the tool does exactly all of that for you. It will initially write the clone to a temp filename, then if (and only if) the cloning process was successful it renames the original file to "Original xyz", and renames the new file to "xyz" (where "xyz" is a placeholder for whatever the original tail name was). If the cloning process fails then the temp file is deleted and your original file remains unaltered. I specifically put this in to save myself from typing (and typos!) - try it! :-)

Re: Shrink VDI size

Posted: 23. Sep 2009, 12:41
by Sasquatch
Hi mpack, I read that in the topic or release notes. I'm sure you took the utmost care to make sure it won't fail. I described these steps in case the user wasn't too sure if it would work properly. I'm sure it will.

Re: Shrink VDI size

Posted: 23. Sep 2009, 13:59
by mpack
Sasquatch wrote:I described these steps in case the user wasn't too sure if it would work properly. I'm sure it will.
I can fully understand anyones reluctance to do something so obviously crazy as to write to the same file you are reading from. :-) In fact I was busy writing code to detect this case and give the traditional error message, but then I thought... instead of the error, why not just find a way to do what the user wants?! :-) Obviously, given the apparant danger, the feature has been thoroughly tested.

For future reference: when you do this it writes the clone to a temp file first. If the cloning process is completed without errors then it renames the original file to "Original <name>", then renames the temp file to <name>. If the cloning process fails then the temp file is deleted and the original is left in the folder untouched. The only thing that can trip me up is if "Original <name>" already existed, meaning I can't do the first rename. In that case you will get an error message, but the clone will be left in the folder with its temp name. You then have to sort out the filenames yourself manually, but the clone itself is good.

Re: Shrink VDI size

Posted: 23. Sep 2009, 14:35
by Geolilli
Thanks to you both!
The shrinking was successful (13GB > 4.5GB).
:D