Page 1 of 1
[solved] How to shrink my VDI HD
Posted: 27. Sep 2020, 16:04
by Plagrö
I have a "windows XP" guest in a Linux host.
I have already run defrag in Win XP.
This is how it looks at the moment:

- HD c WinXP.png (21.31 KiB) Viewed 17773 times
36 GB free of 76 GB.
The VDI itself is about 67 GB.
I have done the steps ...
-Run in a cmd windows in your guest "sdelete c: -z"
and
-Run "VBoxManage modifymedium <path.VDI> --compact' from the Host
But my VDI has still the same size! ?
How can I now get a VDI of about 46 GB.
Thank you.
Re: How to shrink my VDI HD
Posted: 27. Sep 2020, 18:14
by scottgus1
Compact does not change the VDI's final size. It only dumps no-longer-used sectors out of the guest disk file on the host drive.
Your guest disk shows 76GB size with 36GB free. The guest disk file on the host drive is 67GB, and it can increase to the full 76GB. After compacting, your guest disk file should have been about 40GB (76 - 36) on the host drive. Did this happen?
If it did, then the compact command worked.
If it did not, please try Mpack's
CloneVDI. CloneVDI does not require 'sdelete' zero-filling, and has the extremely important benefit of making a compacted copy of the disk file, rather than working on the original and possibly bunging it up. I strongly recommend CloneVDI instead of the vboxmanage 'compact' command.
If your guest disk file did shrink to ~40GB, and you now want it to not increase past 46GB, you must change the partition size inside the XP guest. Shrink the guest OS's C drive partition to 46GB and the guest disk file on the host won't get bigger than 46GB.
Virtualbox does not come with a tool to edit guest OS partitions. XP also does not have a way to edit its partitions. The bootable 'Gparted' ISO can be used as a boot ISO on the XP guest's CD drive to edit the C drive partition to a smaller size. Web-search 'Gparted' for a download and instructions. Explaining Gparted usage is beyond the scope of the Virtualbox forum.
Re: How to shrink my VDI HD
Posted: 27. Sep 2020, 20:46
by Plagrö
Thank you.
I think I'll start all over again.
Do we have to defrag the VDI in the guest first before running CloneVDI? Or does CloneVDI do that anyway?
Re: How to shrink my VDI HD
Posted: 28. Sep 2020, 02:39
by scottgus1
Defrag gets any little chunks of files together. It should not affect the final size outcome of CloneVDI or vboxmanage compacted disk files. If the disk file is stored on an SSD, then Defrag is unnecessary at any time. If your XP guest is on an SSD and has any automatic defragging going on, disable it, it will reduce the lifespan of the SSD.
Re: How to shrink my VDI HD
Posted: 28. Sep 2020, 21:01
by fth0
scottgus1 wrote:Defrag gets any little chunks of files together. It should not affect the final size outcome of CloneVDI or vboxmanage compacted disk files.
I beg to differ:
The VDI format uses
blocks of 1 MiB (MB for
mpack 
), which represent 2048 consecutive
sectors of 512 bytes each. According to the documentation, CloneVDI uses its knowledge of the guest's file system to recognize unused
clusters or
sectors, thereby eliminating the need to fill those
sectors with zeroes beforehand. But it still only eliminates completely unused or zeroed
blocks when compacting, as
VBoxManage modifymedium --compact does with completely zeroed
blocks.
If you let Defrag consolidate the free space, you'll probably note the difference. The defragmentation may take some hours, though.

Re: How to shrink my VDI HD
Posted: 29. Sep 2020, 16:56
by Plagrö
scottgus1 wrote:Compact does not change the VDI's final size. It only dumps no-longer-used sectors out of the guest disk file on the host drive.
If it did not, please try Mpack's
CloneVDI. forum.
I read this:
Q. How do I install it?
A. It came as a .zip, just create a folder and unzip the contents into it. After that you can
optionally create a shortcut to link your desktop to the CloneVDI.exe file inside the target
folder.
But I did not find any exe in the zip:

- Clone.png (17.83 KiB) Viewed 17694 times
(?)
additional question:
Is CloneVDI 32 bit or 64 bit? I must know it, because I have to know if I must make a 32 bit wine prefix or a 64 bit wine prefix.
Thank you.
Re: How to shrink my VDI HD
Posted: 29. Sep 2020, 17:05
by scottgus1
It appears that you got hold of the source code somehow. This is the link the the zipped EXE:
download/file.php?id=37667
I suspect CloneVDI is 32-bit. Since you're using Wine, see
viewtopic.php?f=7&t=22437.
Re: How to shrink my VDI HD
Posted: 30. Sep 2020, 10:43
by Plagrö
Thank you. I was successful with this tool.
Ye, it's 32 bit.
Re: [solved] How to shrink my VDI HD
Posted: 30. Sep 2020, 14:46
by scottgus1
Great! Glad you're up and running.
fth0 wrote:blocks of 1 MiB (MB for mpack ), which represent 2048 consecutive sectors of 512 bytes each.
Good point, thanks! Defrag would put the sectors together, which might move them out of and thereby empty a block, letting the block get deleted, resulting in a possibly smaller compact.