How to clear unused space with zeros ? (ext3,ext4)
I'm looking for something smarter than
cat /dev/zero > /mnt/X/big_zero ; sync; rm /mnt/X/big_zero
Like FSArchiver is looking for "used space" and ignores unused, but opposite site.
Purpose: I'd like to compress partition images, so filling unused space with zeros is highly recommended.
Btw. For btrfs : Clear unused space with zeros (btrfs)
Best Answer
Such an utility is
zerofree
.From its description:
UPDATE #1
The description of the .deb package contains the following paragraph now which would imply this will work fine with ext4 too.
Other uses
Another application this utility is to compress disk images that are a backup of a real disk. A typical example of this is the dump of the SD card in a BeagleBone or a Raspberry Pi. Once empty spaces have been zeroed, backup images can be compressed more efficiently.