blkdiscard
Discard device blocks, securely erase data
TLDR
Discard all sectors on a device, removing all data
Securely discard all blocks on a device, removing all data
Discard the first 100 MB of a device
SYNOPSIS
blkdiscard [options] device
PARAMETERS
-o
Offset: Discard from -l
Length: Discard -s
Secure: Perform a secure discard operation.-v
Verbose: Print more information during the discard operation.-z
Zeroes: Before discarding, write zeroes to the specified range.-V
Version: Display version information.-h
Help: Display help message.
DESCRIPTION
The blkdiscard
command is a crucial utility in Linux for securely erasing data on block devices, such as SSDs and HDDs. It sends a discard or trim command to the underlying device, effectively informing it that certain blocks are no longer in use. This allows the device to optimize its internal operations, improve performance, and potentially extend its lifespan. For SSDs, discarding unused blocks enables the flash controller to erase those blocks asynchronously, leading to faster write speeds in the future. For HDDs, while the impact is less significant, discarding can still help the drive manage its resources more efficiently. blkdiscard
is particularly important for security-sensitive environments where data remanence is a concern, as it helps to ensure that deleted data is truly irrecoverable.
CAVEATS
Using blkdiscard
can permanently erase data. Ensure you are targeting the correct device and understand the implications before executing the command.
Some devices might not fully support the discard command, so the actual behavior may vary.
EXIT STATUS
blkdiscard
exits with 0 on success, 1 on failure (e.g., invalid arguments, permission issues, or device errors).
SECURITY CONSIDERATIONS
Important: Always double-check the device name to prevent accidental data loss on the wrong device. Using the secure option (-s
) might take significantly longer, but it provides a stronger guarantee of data erasure, although the exact implementation and effectiveness are device-dependent.
HISTORY
blkdiscard
emerged as a dedicated tool to manage the discard operation on block devices, mainly SSDs. Before its existence, the discard operation was commonly managed indirectly via filesystem commands like fstrim
. blkdiscard
offers more direct and fine-grained control over the discard process, becoming a standard utility for securely and efficiently erasing data on block devices.