So if I have a dynamical storage in virtualbox guest, how can I reduce the VDI's size, if there are many unused place in the guest?

So I mean I know the virtualbox guest in reallity is about ~3 GByte's large, but the VDI file is 10 GByte, because once a while the guest was that big. But it's now only 3 GByte's big. How can I reduce the VDI's size? So that it would be only 3 GByte's big? (and no, there aren't any snapshot's about the guest)


Take a look at vboxmanage modifyhd: it allows you to make an image more compact.

With the --compact option, can be used to compact disk images, i.e. remove blocks that only contains zeroes. This will shrink a dynamically allocated image again; it will reduce the physical size of the image without affecting the logical size of the virtual disk. Compaction works both for base images and for diff images created as part of a snapshot.

For this operation to be effective, it is required that free space in the guest system first be zeroed out using a suitable software tool. For Windows guests, you can use the sdelete tool provided by Microsoft. Execute sdelete -c in the guest to zero the free disk space before compressing the virtual disk image. For Linux, use the zerofree utility which supports ext2/ext3 filesystems.

  • 2
    Use sdelete -z not -c! See superuser.com/questions/747820/… -- the -c option just overwrites with random data for a "secure wipe" (slightly wearing SSDs).
    – Luc
    Jun 17 '17 at 15:01

Be careful -- MS changed the meaning of "-c" (clean) and "-z" (zero) at some point. To be safe, run "sdelete /?" to see which option you should use:

C:\> sdelete /?

SDelete - Secure Delete v1.6
Copyright (C) 1999-2010 Mark Russinovich
Sysinternals - www.sysinternals.com

usage: sdelete [-p passes] [-s] [-q] <file or directory> ...
       sdelete [-p passes] [-z|-c] [drive letter] ...
   -a         Remove Read-Only attribute
   -c         Clean free space
   -p passes  Specifies number of overwrite passes (default is 1)
   -q         Don't print errors (Quiet)
   -s or -r   Recurse subdirectories
   -z         Zero free space (good for virtual disk optimization)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.