How To Install zerofree on Ubuntu 18.04

In this tutorial we learn how to install zerofree on Ubuntu 18.04. zerofree is zero free blocks from ext2, ext3 and ext4 file-systems

Introduction

In this tutorial we learn how to install zerofree on Ubuntu 18.04.

What is zerofree

zerofree is:

Zerofree finds the unallocated blocks with non-zero value content in an ext2, ext3 or ext4 file-system and fills them with zeroes (zerofree can also work with another value than zero). This is mostly useful if the device on which this file-system resides is a disk image. In this case, depending on the type of disk image, a secondary utility may be able to reduce the size of the disk image after zerofree has been run. Zerofree requires the file-system to be unmounted or mounted read-only.

The usual way to achieve the same result (zeroing the unused blocks) is to run “dd” to create a file full of zeroes that takes up the entire free space on the drive, and then delete this file. This has many disadvantages, which zerofree alleviates:

  • it is slow;
  • it makes the disk image (temporarily) grow to its maximal extent;
  • it (temporarily) uses all free space on the disk, so other concurrent write actions may fail.

Zerofree has been written to be run from GNU/Linux systems installed as guest OSes inside a virtual machine. If this is not your case, you almost certainly don’t need this package. (One other use case would be to erase sensitive data a little bit more securely than with a simple “rm”).

There are three methods to install zerofree on Ubuntu 18.04. We can use apt-get, apt and aptitude. In the following sections we will describe each method. You can choose one of them.

Install zerofree Using apt-get

Update apt database with apt-get using the following command.

sudo apt-get update

After updating apt database, We can install zerofree using apt-get by running the following command:

sudo apt-get -y install zerofree

Install zerofree Using apt

Update apt database with apt using the following command.

sudo apt update

After updating apt database, We can install zerofree using apt by running the following command:

sudo apt -y install zerofree

Install zerofree Using aptitude

If you want to follow this method, you might need to install aptitude first since aptitude is usually not installed by default on Ubuntu. Update apt database with aptitude using the following command.

sudo aptitude update

After updating apt database, We can install zerofree using aptitude by running the following command:

sudo aptitude -y install zerofree

How To Uninstall zerofree on Ubuntu 18.04

To uninstall only the zerofree package we can use the following command:

sudo apt-get remove zerofree

Uninstall zerofree And Its Dependencies

To uninstall zerofree and its dependencies that are no longer needed by Ubuntu 18.04, we can use the command below:

sudo apt-get -y autoremove zerofree

Remove zerofree Configurations and Data

To remove zerofree configuration and data from Ubuntu 18.04 we can use the following command:

sudo apt-get -y purge zerofree

Remove zerofree configuration, data, and all of its dependencies

We can use the following command to remove zerofree configurations, data and all of its dependencies, we can use the following command:

sudo apt-get -y autoremove --purge zerofree

References

Summary

In this tutorial we learn how to install zerofree package on Ubuntu 18.04 using different package management tools: apt, apt-get and aptitude.