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

blockdev

Call block device ioctls from the command line.

Synopsis

blockdev [-q] [-v] command [command...] device [device...]
blockdev --report [device...]

Operation

Each command performs a single ioctl on the specified block device(s). Multiple commands can be given and will be applied to each device in sequence. Set commands that take an argument consume the next positional parameter.

Report mode

--report prints a summary table for the specified devices, or all block devices from /proc/partitions if none are specified.

Columns: RO (read-only), RA (readahead), SSZ (sector size), BSZ (block size), StartSec (start sector), Size (bytes), Device.

Inputs

SourcePurpose
/dev/*Block device to operate on
/proc/partitionsEnumerate all block devices (for --report with no args)
/sys/dev/block/MAJ:MIN/startStart sector for partitions

Outputs

  • stdout: Values from get commands, report table
  • Block device ioctls for set commands

Ioctls

Get commands

CommandioctlValueReturns
--getroBLKROGET0x125eRead-only status (0 or 1)
--getbszBLKBSZGET0x80081270Block size in bytes
--getssBLKSSZGET0x1268Logical sector size
--getpbszBLKPBSZGET0x127bPhysical block size
--getsizeBLKGETSIZE0x126032-bit sector count (deprecated)
--getsize64BLKGETSIZE640x80081272Size in bytes (u64)
--getszBLKGETSIZE640x80081272Size in 512-byte sectors (getsize64/512)
--getraBLKRAGET0x1263Readahead in 512-byte sectors
--getfraBLKFRAGET0x1265Filesystem readahead
--getiominBLKIOMIN0x1278Minimum I/O size
--getiooptBLKIOOPT0x1279Optimal I/O size
--getalignoffBLKALIGNOFF0x127aAlignment offset
--getmaxsectBLKSECTGET0x1267Max sectors per request
--getdiscardzeroesBLKDISCARDZEROES0x127cDiscard zeroes support

Set commands

CommandArgumentioctlValueDescription
--setroBLKROSET0x125dSet read-only (arg=1)
--setrwBLKROSET0x125dSet read-write (arg=0)
--setbszbytesBLKBSZSET0x40081271Set block size
--setrasectorsBLKRASET0x1262Set readahead
--setfrasectorsBLKFRASET0x1264Set filesystem readahead
--flushbufsBLKFLSBUF0x1261Flush buffer cache
--rereadptBLKRRPART0x125fRe-read partition table

Command-line options

OptionDescription
-qQuiet mode
-vVerbose mode
--reportPrint summary table
-h, --helpDisplay help
-V, --versionDisplay version

Exit codes

CodeMeaning
0Success
1Failure

Permissions

Get commands typically work without root. Set commands, --flushbufs, and --rereadpt require root or CAP_SYS_ADMIN.

Notes

  • --setbsz is ephemeral: the block size reverts when the fd is closed.
  • --getsize is deprecated; use --getsz instead.
  • --getsz computes BLKGETSIZE64 / 512 for a 64-bit sector count.

Not yet implemented

  • --getdiskseq (requires newer kernel header)
  • --getzonesz (zoned block devices)