Inspect Block Devices Safely with blockdev
Read a disk's sector size, capacity and read-only flag with blockdev, without touching a byte of data. You will also learn which options change live kernel settings, so you know where to stop before they hit a mounted filesystem. It takes about 10 minutes and needs util-linux, a shell and the path of a real block device.
The route
Jump straight to the step you need, or tick off Done means at the end.
The examples were checked against util-linux 2.41.3. The installed manual is generated from 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 options 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. Identify the device
Check the version and available options first:
$ blockdev --version
blockdev from util-linux 2.41.3
$ blockdev --help
The command takes one or more operations, then one or more devices. Use block-device paths only:
- Whole disks:
/dev/sda. - Partitions:
/dev/sda1. - Device-mapper paths: these work too.
- Never a regular file or directory. The kernel ioctl may fail with an unhelpful error, and a path that looks valid does not prove you picked 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 basic properties
Run several read-only queries in one go. Multiple operations 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, in the order you asked:
- Read-only state:
--getroprints1for read-only and0otherwise. - Logical sector size:
--getss, in bytes. - Physical block size:
--getpbsz, in bytes. - Capacity:
--getsize64, also in bytes. Keep units explicit when you put the value in a report or script.
The example numbers show the shape of the output, not a promise about your hardware. For values 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. Build a quick inventory with --report
--report prints 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 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 deciding which unit your report needs.
On the test machine, blockdev --report with no arguments printed the header but no rows, because the command's view of /proc/partitions gave it no usable entries in that environment. That is not evidence that a production host has no block devices. Try an explicit path and read the error text if a row is missing.
Checkpoint
Save the report or the labelled queries alongside the host name and date. That gives you a baseline before you change a disk setting or chase an I/O problem.
4. Check readahead and topology
Use the getter that matches your 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. 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 is the odd one out. It reports the block size the kernel uses internally, and the manual warns that it does not describe device topology and can be changed by a filesystem driver while a filesystem is mounted. When you are documenting I/O requirements, use --getss, --getpbsz and the topology getters instead.
5. Treat setters as changes
Some options do more than inspect state:
--setra SECTORSand--setfra SECTORS: change readahead, measured in 512-byte sectors.--setbsz BYTES: changes the block size for the file descriptor opened byblockdev. The manual says the change lasts only while that descriptor is open, so it is lost whenblockdevexits.--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.
Warning
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. 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
Recovery
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. Keep 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.
Warning
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 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
Read the error before you react:
- Permission denied: an access policy problem.
- ioctl error: the path may not be a usable block device for that query, or the device does not implement the requested operation.
- Never 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
- Version and device confirmed. You know the installed
blockdevversion and identified the intended device withlsblk. - Baseline recorded. Read-only state, logical sector size and capacity came from labelled, read-only queries.
- Units understood. Report
StartSecand readahead use 512-byte sectors. - Disruptive options avoided. Setters, buffer flushing and partition-table rereads stayed out of unplanned work.
- Changes reversible. Any temporary readahead change has a recorded old value and an explicit restore command.