Freeing up space

Let the world know ...Tweet about this on TwitterShare on Google+0Share on Facebook0Email this to someoneShare on LinkedIn0

I like VMs. Sure, everything should be cloud, and AWS, Azure, etc are great (if you can afford them). But nothing beats having a local VM running with 6GB RAM even when you are not online. Cost? 0 $. I am just electively using the laptop I already use. Put a VM on an external USB drive is not a problem. With USB 3.0 the performance is quite good, even with USB 2.0 you can run a VM; starting and stopping takes a while, but once the services are started, they work quite nicely.

To not occupy all the disk space at once, my VMs are configured to dynamically allocate space. This allows me to run VMs from the SSD of the laptop, speeding things up even more. A normal VM takes only a few GB: the OS + software.

A problem is the ext4 file system used by my Linux VMs. Once a space was allocated, it stays allocated. The effect is that a VM is occupying internally 30 GB consumes 100 GB on my hard drive. Why? Adding and deleting files, caches, etc. The DB may take only 20 GB, but adding and deleting 10GB results that the VM occupies 30 GB. Do that for some time and suddenly the VM eats up 100 GB of your hard drive instead of 30GB.

How to regain hard drive space?

VMWare comes with a compact tool to recover space, but that only works ootb with Windows VMs. For Linux VMs with a journaling file system like ext4 some preparations are needed. In short, the preparation is to create huge empty file that only contains 0.

First, stop the running services. The file going to be created will consume the free space of the virtual disk. Running services will get into trouble when they cannot write anymore to the disk. Like log files or real data. To not let your database or Tomcat server crash uncontrolled, stop them before creating the file.

Command to create the file:

dd if=/dev/zero of=/dummy bs=4096

This command lets dd create a file named dummy in /. The file size will be the entire free space of the virtual disk. If you configured your virtual disk to be 500GB and you have 400GB free, the resulting file size will be 400GB. You do not need to have 400GB free on your physical disk where the VM is stored on. As you write zeros, the real space needed will be 0 MB.

After dd filled you file system, it will exit. Delete the dummy file

rm /dummy

Shut down your VM. Open VM Player, open the properties of the VM, select the hard disk you want to compact and start the Compact tool from the Utilities drop down.

This will start the compact tool. After a while you’ll see a success message, informing you that the disk was compacted.

 

Let the world know ...Tweet about this on TwitterShare on Google+0Share on Facebook0Email this to someoneShare on LinkedIn0

One thought on “Freeing up space

  1. Pingback: Shrinking a Linux VMDK disk under VMWare Player 7 | It`s full of stars!

Leave a Reply

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