Ubuntu – How to reduce VM size

Ubuntuvirtualbox

I have a Virtualbox VM, with a .vdi that is taking 49gb in the host machine.

I may have used that much space inside the VM once, but now I'm only really using about 6gb.

I tried this command for virtualbox:

vboxmanage modifyhd /path/to/disk.vdi --compact

It started working 0%..10%…..100%. But nothing really happened, the .vdi was still 49gb.

Then I run 'df -h' in the VM and found this:

root@mypc# df -h
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/mypc-root       2.0T   38G  1.9T   2% /
udev                        1.3G  4.0K  1.3G   1% /dev
tmpfs                       502M  784K  501M   1% /run
none                        5.0M     0  5.0M   0% /run/lock
none                        1.3G  160K  1.3G   1% /run/shm
/dev/sda1                   228M   31M  185M  15% /boot
/home/someuser/.Private     2.0T   38G  1.9T   2% /home/someuser

I don't know why it is using 38gb there.

I cleaned the Trash but it didn't help.

Any ideas on what else I can do?

The VM has Ubuntu 12, with encrypted LVM and home (that's the .Private dir).
The host has Windows 7.

UPDATE

I was able to free space for /dev/sda1, but not for /dev/mapper/mypc-root. Zerofree starts and never ends, though I can tell the disk has stopped writting because it stops doing noise after a minute.

Here's the output for 'df -ih'

root@mypc:/home/someuser# df -ih
Filesystem                 Inodes IUsed IFree IUse% Mounted on
/dev/mapper/mypc-root        128M  208K  128M    1% /
udev                         311K   495  310K    1% /dev
tmpfs                        314K   428  314K    1% /run
none                         314K     4  314K    1% /run/lock
none                         314K     7  314K    1% /run/shm
/dev/sda1                    122K   230  122K    1% /boot
/home/someuser/.Private      128M  208K  128M    1% /home/someuser

Best Answer

From the manual:

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.

Related Question