Posts Tagged zeros
Filling unused drive space with zeros is useful for cleaning a drive and for preparing a drive image for compression. A drive whose unused space is filled with zeros will compress to a much smaller size than one that is not. There are two methods typically used to fill a Linux drive with zeros:
A simple shell script
The following shell script simply creates a file and fills it with zeros until all drive space in exhausted, then it deletes the file. This isn’t a perfect solution, but it’s better than nothing.
#!/bin/bash cat /dev/zero > /zero.fill sync sleep 5 sync rm -f /zero.fill
The ‘zerofree’ utility.
The zerofree utility, written by Ron Yorston, only works on devices containing an ext2 or ext3 file system. It seems to work fairly well, however I have crashed one system with it so be careful. You should probably clone the drive you plan to zerofree before doing so.