5

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
2
  • 1
    Just curious: What is the output of df -ih ? – Steven Monday May 27 '12 at 1:52
  • @StevenMonday There, I updated my post. And learned something new =) – HappyDeveloper May 27 '12 at 5:12
8

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.

2
1

With respect to the original answer that had this solution:

In the VM:

  1. dd if=/dev/zero of=test.file
  2. sync
  3. rm test.file

On the host machine:

  1. VBoxManage modifyhd --compact your_image_path.vdi

This is the only solution that I have tried that works. The zerofree and sfill (from secure-delete) don't work on my Debian VM (Windows 10 host).

0

I think the core of your problem is that your root filesystem (/) is 2TB in size. With a filesystem that large, the relatively small overhead (inodes and such) is still quite large (>32GB, in your case).

If you want to shrink your virtual disk, you'll need to shrink your root filesystem first.

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.