← 返回命令列表

Linux command

blkdiscard 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Discard

blkdiscard /dev/device

Secure

blkdiscard -s /dev/device

Example

blkdiscard -l 100M /dev/device

Example

blkdiscard -p 512M /dev/device

说明

blkdiscard sends TRIM/DISCARD commands to a block device to mark sectors as unused. Unlike fstrim(8), it operates directly on the block device rather than a mounted filesystem. This is particularly useful for SSDs and thinly-provisioned storage. All data in the discarded region will be lost.

参数

-o, --offset _offset_
Byte offset into the device to start discarding. Must be aligned to the device sector size. Default is 0.
-l, --length _size_
Number of bytes to discard from the offset. Must be aligned to the device sector size.
-p, --step _size_
Discard this many bytes per iteration instead of all at once. Useful for avoiding long uninterruptible operations on large devices.
-s, --secure
Perform a secure discard. This tells the device to also erase any copies of the discarded data (e.g. in garbage collection). Requires device support.
-z, --zeroout
Zero-fill the specified region rather than discarding it.
-f, --force
Disable exclusive-open check, allowing operation on mounted devices. Use with caution.
-q, --quiet
Suppress warning messages.
-v, --verbose
Print aligned offset and length values and progress information.

FAQ

What is the blkdiscard command used for?

blkdiscard sends TRIM/DISCARD commands to a block device to mark sectors as unused. Unlike fstrim(8), it operates directly on the block device rather than a mounted filesystem. This is particularly useful for SSDs and thinly-provisioned storage. All data in the discarded region will be lost.

How do I run a basic blkdiscard example?

Run `blkdiscard /dev/device` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -o, --offset _offset_ do in blkdiscard?

Byte offset into the device to start discarding. Must be aligned to the device sector size. Default is 0.