Home / Alt manpages / blockdev(8)

  • blockdev(8)
  • Admin command
  • linux

Inspect Linux Block Devices Safely with blockdev

You will finish with a read-only inventory of a block device, including its logical sector size, capacity and read-only state. You will also know which blockdev options change live kernel settings and when to stop before they affect a mounted filesystem. Allow about 10 minutes. You need the util-linux package, a shell and the path of a real block device. The examples were checked against the installed util-linux 2.41.3 command; the installed manual is generated from util-linux 2.39.3, so the version difference is called out where it matters.

Safety boundary

Inspection commands below do not change the device. Commands beginning with sudo, and commands such as --setro, --setrw, --rereadpt and --flushbufs, can affect other users, mounts or storage state. Do not substitute a device path until you have positively identified it.

1. Confirm the command and identify a device

Check the version and available command names first:

$ blockdev --version
blockdev from util-linux 2.41.3
$ blockdev --help

The command accepts one or more operations followed by one or more devices. It works on block-device paths such as /dev/sda, a partition such as /dev/sda1, or a device-mapper path. Do not use a regular file, directory or arbitrary path as a test. The kernel ioctl may fail with an unhelpful error, and a successful-looking path check does not prove that you selected the intended disk.

List likely candidates without changing anything:

$ lsblk -dn -o NAME,TYPE,RO,SIZE
NAME TYPE RO  SIZE
sda  disk  0  3.6T
sdb  disk  0  3.6T

Your names and sizes will differ. Check mount points and model information with lsblk before working on a disk. If you cannot identify the device with confidence, stop here. A wrong path is a storage incident, not a small command-line mistake.

Checkpoint

Write down the exact device path you intend to inspect. For the remaining examples, replace /dev/DEVICE with that path only after checking it.

2. Read the device's basic properties

Run several read-only queries in one invocation. Multiple commands and devices are allowed, and each query prints its result on standard output:

$ blockdev --getro --getss --getpbsz --getsize64 /dev/DEVICE
0
512
4096
4000787030016

The output is positional: the first value is --getro, then logical sector size, physical block size and size in bytes. --getro prints 1 for read-only and 0 otherwise. Sector sizes are bytes. Capacity from --getsize64 is also bytes, so keep units explicit when placing the value in a report or script.

The example numbers are representative output shape, not a promise about your hardware. For a value you can reproduce on a particular host, run each query separately and label it:

$ printf 'read-only: '; blockdev --getro /dev/DEVICE
$ printf 'logical sector bytes: '; blockdev --getss /dev/DEVICE
$ printf 'size bytes: '; blockdev --getsize64 /dev/DEVICE

These commands normally need permission to open the device. Keep the check unprivileged when it works. If access is denied, inspect the path and permissions first; use elevated privileges only when your system policy permits it and you understand which device will be opened.

3. Use the report for a quick inventory

--report provides a compact table for named devices. With no device argument it reads the devices listed in /proc/partitions:

$ blockdev --report /dev/DEVICE
RO    RA   SSZ   BSZ        StartSec            Size   Device
 0  256   512  4096                 0  4000787030016   /dev/DEVICE

The columns are read-only state, readahead in 512-byte sectors, sector size, block size, partition start in 512-byte sectors, size and device name. The manual specifically defines StartSec in 512-byte sectors, even when the device has a different logical sector size. Do not multiply it by the logical sector size without first deciding which unit your report requires.

On this machine, running blockdev --report with no arguments produced the table header but no rows because the command's view of /proc/partitions did not provide usable device entries in this environment. That is not evidence that a production host has no block devices. Try an explicit path and check the error text if a row is missing.

Checkpoint

Save the report or the labelled queries alongside the host name and date. This gives you a baseline before changing a disk setting or investigating an I/O problem.

4. Check readahead and other topology values

Use the getter that matches the question rather than treating every number as a generic block size:

$ blockdev --getra /dev/DEVICE
$ blockdev --getfra /dev/DEVICE
$ blockdev --getiomin /dev/DEVICE
$ blockdev --getioopt /dev/DEVICE
$ blockdev --getalignoff /dev/DEVICE
$ blockdev --getmaxsect /dev/DEVICE

--getra and --getfra report readahead in 512-byte sectors. The minimum and optimal I/O sizes, alignment offset and maximum request sectors are separate properties. A large value is not automatically wrong: storage stacks, RAID, virtual disks and device-mapper targets can expose different topology from the physical drive.

--getbsz reports the block size used internally by the kernel. The manual warns that it does not describe device topology and can be changed by a filesystem driver while a filesystem is mounted. Use --getss, --getpbsz and the topology getters when you are documenting I/O requirements.

5. Treat setters as operational changes

Some commands do more than inspect state:

  • --setra SECTORS and --setfra SECTORS change readahead, measured in 512-byte sectors.
  • --setbsz BYTES changes the block size for the file descriptor opened by blockdev. The manual says the change lasts only while that descriptor is open, so it is lost when blockdev exits.
  • --setro requests read-only access for the device. Existing active access, such as a filesystem already mounted read-write, may not be affected until a remount.
  • --setrw requests read-write access. This can defeat a deliberate read-only protection.

Do not run a setter on a mounted production device as a casual experiment. Capture the old value first, record why the change is needed, check the mount and service impact, and arrange a maintenance window if the storage stack requires one. A typical reversible readahead test looks like this, but it still needs the correct device and privilege:

$ old_ra=$(blockdev --getra /dev/DEVICE) && printf 'old readahead: %s\n' "$old_ra"
$ sudo blockdev --setra 4096 /dev/DEVICE
$ blockdev --getra /dev/DEVICE
$ sudo blockdev --setra "$old_ra" /dev/DEVICE

The final command is the undo step. If any command fails, do not guess at the old value: rerun the getter and restore the recorded number only after confirming the same device path. Readahead tuning is not a substitute for fixing a failing disk, a poor workload pattern or an incorrect filesystem layout.

6. Reserve disruptive operations for planned work

--flushbufs flushes buffers. --rereadpt asks the kernel to reread a partition table. Both can interact with mounted filesystems, open file descriptors and storage management tools. They are not harmless ways to refresh a display. Before either operation, stop or quiesce relevant services, verify the target, confirm that the partition table change is complete, and follow the storage platform's recovery procedure. There is no universal undo command for a mistaken partition-table operation, so keep backups and a recovery path outside the live disk.

If an inspection fails, preserve the error and the command:

$ blockdev --getss /dev/DEVICE
$ printf 'exit status: %s\n' "$?"
$ lsblk -o NAME,TYPE,RO,SIZE,FSTYPE,MOUNTPOINTS /dev/DEVICE

An error such as permission denied points to access policy. An ioctl error can mean that the path is not a usable block device for that query, or that the device does not implement the requested operation. Do not turn a failed read into a write attempt. Compare the path with lsblk, check whether a device-mapper or virtual storage layer is involved, and consult that layer's documentation.

Done means

  • You confirmed the installed blockdev version and identified the intended device with lsblk.
  • You recorded read-only state, logical sector size and capacity with labelled, read-only queries.
  • You understood that report StartSec and readahead use 512-byte sectors.
  • You kept setters, buffer flushing and partition-table rereads out of unplanned work.
  • Any temporary readahead change has a recorded old value and an explicit restore command.