Page 1 of 1

Reduce physical size of dynamic vdi - VM must fit usb stick

Posted: 22. Dec 2017, 18:01
by jcdole
Hello.
Host : opensuse leap 42.3
Guest : windows 7
I have just created a windows 7 VM by specifying a dynamic VDI file of size 40 Gb ( to fit a 64 Gb USB stick ).
The VM is fully configured and every things has been installed.
The size of the windows 7 guest is 15 Gb ( windows 7 partition size )
The size of the vdi files has been reduce from 25 Gb to 16 Gb

Code: Select all

1 defrag
2 reduce partition size using windows partition manager tools (computer administration)
3 defrag again
4 zeroes free space with sdelete 1.61
5 reboot with disk verification during boot
6 shutdown and return to linux environment.
7 reduce size of VM with vboxmanage --compact
So I plan to put the VDI on a 32 Gb usb stick.
As the vdi file size is still fixed to its initial size of 40 Gb, Where/How can I fix the size to 25Gb.

Re: Reduce physical size of dynamic vdi - VM must fit usb stick

Posted: 22. Dec 2017, 18:20
by mpack
There is no official way to do that.

You can try the unofficial tool CloneVDI. It will run under Wine on a Linux host.

I suggest that you enable CloneVDI's "compact" option while cloning the drive, since the long procedure you described above was (a) largely not necessary, (b) not effective (the latter because sdelete can't zero fill unpartitioned space, so reducing partition size and then running sdelete was not useful).

A more correct sequence would have been:-
  1. Reduce partition size.
  2. Defrag (optional - probably of marginal benefit)
  3. Run CloneVDI with compact option and resize options enabled (the latter choosing a smaller size).
I should also mention that reducing the logical capacity of the drive may not be necessary: guest apps should not be writing into unpartitioned areas, though naughty ones might.