Clearing free space in linux

By | February 6, 2018

Sometimes you need to export a virtual machine, if this machine has been used extensively it tends to be larger than the actual free space on the machine, in order for you to remove this delete space from being exported run the following commands

dd if=/dev/zero of=zerofill bs=1M

The command above will zerofill all free disk space on the virtual machine

  • if= input file;
  • /dev/zero indicates a bit-stream of zeros
  • of= the output file
  • zerofill name of the file containing the bit-stream of zeros
  • bs= the block size
  • 1M  the block size will be 1 megabyte

Once the dd has command has finished, you will have no free space on your device, you need to run the following command to delete the file you created

rm zerofill

shutdown your vm

shutdown -h now

export your vm, the size should now be significantly smaller

Leave a Reply

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

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