0

I have a Debian Jessie VM in VirtualBox that I use for C++ programming. The primary virtual disk is set to be dynamically allocated 32GB. Over time, I have gradually used more space on the virtual disk, but recently I cleared my Bazel cache and removed other extraneous files.

Running df -h on the VM yields:

Filesystem Size Used Avail Use% Mounted on 
/dev/sda1 31G 14G 15G 48% / 
udev 10M 0 10M 0% /dev 
tmpfs 403M 5.9M 397M 2% /run 
tmpfs 1006M 68K 1006M 1% /dev/shm 
tmpfs 5.0M 4.0K 5.0M 1% /run/lock 
tmpfs 1006M 0 1006M 0% /sys/fs/cgroup 
tmpfs 202M 4.0K 202M 1% /run/user/117 
tmpfs 202M 8.0K 202M 1% /run/user/1000

From the command output, it appears as if I have only 14GB of space used on the virtual disk, but the VDI file still has a size of 24.2GB. Is there any way to shrink the VDI to the current size of the virtual disk?

EDIT: I have looked at the tools that were recommended by the other questions. None of them work for me, as I cannot figure out how to make zerofree run on my system and sfill -fvz (from secure-delete) only makes VirtualBox think the VM uses all of the 32 GB virtual disk. I don't know where to go from here.

Thanks, Neil

ifconfig
  • 622
  • 3
  • 10
  • 23
  • It is brute force, but cloning the VM to another VDI will usually do the trick. But treat it in procedure and complication like you are replacing a physical hard disk just virtually. You will need to pre format and partition, change UUIDs and configuration files and such, and for simplicity, you could even use disk cloning software. – Damon Jan 22 '18 at 19:11
  • 1
    "how to make `zerofree` run" -- You cannot install it or what? How about this solution with `dd`: [*How to make ext4 filesystem sparse?*](https://unix.stackexchange.com/a/11248/108618) (don't forget to `sync`, see comments there). "I don't know where to go from here." -- basic question, but your statement begs for it: did you try `vboxmanage modifyhd ... --compact`? If this `dd` solution works for you, then please make it a nice answer to [this other question](https://superuser.com/q/429170/432690). After that you can leave me a comment here below and I will upvote your answer there. – Kamil Maciorowski Jan 23 '18 at 06:31
  • +KamilMaciorowski I was able to install it, but I couldn't run `zerofree`. That is the correct command, right? The `sync` command might've been my issue, I didn't know to run that. Does that command finalize the zeroed bits? – ifconfig Jan 23 '18 at 17:23
  • After what I had done, I did run `vboxmanage modifyhd ... --compact`. That recovered the space up until what it was before I started: ~24GB. – ifconfig Jan 23 '18 at 17:24
  • +KamilMaciorowski Yes, the `dd` method works quite well indeed. It recovered all of the storage space. I posted an answer to the question you said. Thanks for your help! – ifconfig Jan 23 '18 at 17:42
  • Answer upvoted. Side note: I didn't get notifications you addressed me in your comments; I'm here only because I tend to monitor my recent comments. The right syntax is like @ifconfig , the plus sign doesn't work. – Kamil Maciorowski Jan 24 '18 at 03:44

0 Answers0