VirtualBox | Free Up Disk Space on Debian Guest

Do you know the feeling when a pop up comes up and reminds you to clean up your hard disk? Today, it happened to me and I checked the disk manager. I saw that my virtual machines use a lot of space. So I decided to clean them up and I want to show you how I did it.

First, you have to check if your virtual machine has dynamic allocation storage. You can check the property under Settings -> Storage and click on the Storage connected to the SATA Controller. On the right side, you can check if the property is set dynamic allocation and how much storage space is used by your VM.

Storage Setting in Virtual Box. Check details property if your storage is dynamically allocated.

The next step is to clean up your VM. Delete all the stuff you don’t need. In my case I check the maven repository and delete all the old version I don’t need anymore and clean up the Download folder and so on. You can check the size by using the df -h command. After this work is done you have to call the following command:

sudo dd if=/dev/zero of=/var/dummy

The dd command copies all zero bits into the file /var/dummy. This is necessary to minimize the used space for the VM. If you wouldn’t take this step you don’t get the maximum free space, because the Virtual Box Manager can free up only bits, with the state 0. After a while, you get a notification that you don’t have enough space on your VM. Now you can delete the /var/dummy folder and turn off your VM.

Now navigate to the location of the virtual machine on your host system and run the following command:

 VBoxManage.exe modifymedium disk ./{path/to/vm}.vdi -compact

If your system doesn’t find VBoxManage.exe, navigate to the Virtual Box directory and find the VBoxManage.exe . Try to call the command from there and don’t forget to set the path to your .vdi file. Check out how much space you could save after the command is finished.

VirtualBox Storage Settings. Check how much space is free.

Special thanks to Tobias Hofmann. He described the steps in his blog. So the credits go to him 🙂 There is also a way to use a tool called zerofree, but it doesn’t work for me. I hope the article could help you and clean up your system a little bit to get some free space on your storage. Let me a comment if you like the article or if you know an easier way to free up space.

chevron_left
chevron_right

Leave a comment

Your email address will not be published. Required fields are marked *

Comment
Name
Email
Website

This site uses Akismet to reduce spam. Learn how your comment data is processed.