Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

blkdiscard

Discard sectors on a block device.

Synopsis

blkdiscard [options] device

Operation

Sends a discard, secure discard, or zero-out command to a block device. This tells the storage device that a range of blocks is no longer in use and can be reclaimed (for SSDs) or zeroed (for thin provisioning).

By default, discards the entire device in one ioctl call. With --step, breaks the operation into chunks.

Inputs

SourcePurpose
Block device pathTarget device
BLKGETSIZE64 ioctlGet device size for default length
BLKSSZGET ioctlGet sector size for alignment validation

Outputs

  • BLKDISCARD / BLKSECDISCARD / BLKZEROOUT ioctl on the device

Ioctls

IoctlValueArgumentUsed when
BLKDISCARD0x1277u64[2] = [offset, length]Default mode
BLKSECDISCARD0x127du64[2] = [offset, length]--secure
BLKZEROOUT0x127fu64[2] = [offset, length]--zeroout
BLKGETSIZE640x80081272u64Get device size
BLKSSZGET0x1268intGet sector size

Command-line options

OptionDescription
-f, --forceDisable O_EXCL exclusive mode
-o, --offset <N>Byte offset to start (default: 0, must be sector-aligned)
-l, --length <N>Number of bytes to discard (default: to end of device)
-p, --step <N>Bytes per ioctl iteration (default: all at once)
-q, --quietSuppress warnings
-s, --secureSecure discard (BLKSECDISCARD)
-z, --zerooutZero-fill (BLKZEROOUT)
-v, --verboseShow progress
-h, --helpDisplay help
-V, --versionDisplay version

Exit codes

CodeMeaning
0Success
1Failure
2Device does not support discard

Permissions

Requires write access to the block device (typically root).

Notes

  • All data in the discarded range is permanently destroyed.
  • Offset and length must be aligned to the device sector size.
  • --secure and --zeroout are mutually exclusive.
  • Device is opened with O_EXCL by default to prevent collisions with mounted filesystems. Use --force to override.