LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

zerofree

zero free blocks on ext2/3/4 filesystems

TLDR

Zero the free blocks of an unmounted filesystem
$ sudo zerofree /dev/[sda1]
copy
Show progress while clearing
$ sudo zerofree -v /dev/[sda1]
copy
Dry run: count non-zero free blocks without writing
$ sudo zerofree -n /dev/[sda1]
copy
Remount the root filesystem read-only first, then clear
$ sudo mount -o remount,ro / && sudo zerofree /dev/[sda1]
copy

SYNOPSIS

zerofree [OPTIONS] device

DESCRIPTION

zerofree scans an ext2, ext3, or ext4 filesystem and overwrites every unallocated block that is not already zero with zeros (or a chosen fill byte). Data in allocated files is left untouched.Zeroing free space is mainly useful before imaging or compressing a disk. A virtual machine image or sparse file shrinks dramatically once its free blocks are zero, and the unused space can then be reclaimed by the host or by sparse-aware tools.The target filesystem must be unmounted or mounted read-only, since zerofree reads and writes the block device directly and cannot run safely while the kernel is also modifying it.

PARAMETERS

-n

Dry run: report how many free blocks are non-zero without writing anything.
-v
Verbose: print progress as a percentage while clearing.
-f fillval
Fill free blocks with the byte value fillval (0-255) instead of zero.

INSTALL

sudo apt install zerofree
copy
sudo dnf install zerofree
copy
sudo apk add zerofree
copy
sudo zypper install zerofree
copy
nix profile install nixpkgs#zerofree
copy

CAVEATS

The filesystem must not be mounted read-write. Run zerofree from a live/rescue environment, or remount the device read-only first (the root filesystem usually needs single-user or recovery mode). Only ext2/3/4 are supported. Zeroing is not a secure erase; it only makes free space compress well. Use shred or blkdiscard to destroy previously written data.

HISTORY

zerofree was written by Ron Yorston to help shrink User-Mode Linux and virtual machine disk images. It is packaged as zerofree on most distributions.

SEE ALSO

e2fsck(8), fstrim(8), blkdiscard(8), shred(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid