Thursday, August 15, 2013

Compacting a VirtualBox VDI

I'm running Fedora on my Dell Studio 1555 on a 64GB Crucial M4 SSD. I really don't need more than 64GB for this box, but I had a Virtual Machine I copied over that was using a bunch of space unnecessarily. I went through the VM and deleted and cleaned up a bunch of stuff, but it was still using 12G of space on my drive.

I made a couple of tweaks to allow me to shrink this down a bit by letting VirtualBox know this was an SSD and enabling Trim to the VM.

First, open Virtual Box, and then Settings for the machine in question. Go to the "Storage" settings page, select your vdi and ensure that "Solid-state Drive" is selected:


Next, fire up a terminal. You'll do better by going ahead and navigating to the directory where the VM is stored. The first command will enable TRIM for the controller:



For my machine, that command looked like this:



Now, issue the fstrim command inside of the Virtual Machine, for example:




Next, you can compact your vdi file using this command:



Again, for my specific case, it looked like this:



By doing this, I was able to reduce the size of my vdi from 12G to 7G.

No comments:

Post a Comment