Storage performance optimisation, partition alignment diagnostics, and disk imaging workflows in Linux require accurate inspection of raw block device architecture. While standard utilities like lsblk and fdisk report general device topologies and partition boundaries, low-level kernel driver parameters—such as readahead buffer sizes, physical sector geometries, and device-level read-only locks—are queried and manipulated using the blockdev utility. By communicating directly with the kernel block layer via ioctl system calls, blockdev provides system administrators and storage engineers with immediate control over storage devices.
Understanding Low-Level Block Device Architecture
The Linux kernel abstracts physical hard drives, solid-state drives, NVMe namespaces, and logical device-mapper volumes as block devices. When applications request data from these devices, the kernel block subsystem manages read and write requests using internal queues, readahead caches, and hardware sector calculations.
The blockdev command performs direct input/output control (ioctl) operations against block device nodes located under /dev/ (such as /dev/sda, /dev/nvme0n1, or /dev/mapper/data-vol). It allows administrators to query hardware sector alignments, modify driver buffers, and enforce kernel-level write protection without unmounting active filesystems.
Querying Sector Sizes, Geometry, and Capacity
Storage devices define sector sizes at the hardware and logical abstraction layers. Ensuring alignment between filesystem clusters and physical sectors is essential to prevent write amplification on modern Advanced Format (4Kn and 512e) drives.
Inspecting Logical and Physical Sector Sizes
To query the logical sector size (the smallest addressable unit exposed to the operating system):
sudo blockdev --getss /dev/nvme0n1
The output reports the sector size in bytes (commonly 512 or 4096).
To inspect the physical sector size of the underlying flash memory or magnetic platters:
sudo blockdev --getpbsz /dev/nvme0n1
If --getss reports 512 while --getpbsz reports 4096, the storage drive uses 512-byte emulation (512e). Partitions created on this device must align with multiples of 4096 bytes (typically 1 MiB or 2048 sectors) to maintain optimal throughput.
Calculating Total Device Capacity in Sectors and Bytes
To retrieve the exact total number of 512-byte sectors on a block device:
sudo blockdev --getsz /dev/nvme0n1
To calculate the absolute capacity in bytes directly from the kernel driver:
sudo blockdev --getsize64 /dev/nvme0n1
This byte-exact calculation is critical when scripting storage carving, low-level disk duplication with dd, or validating snapshot image sizes.
Inspecting and Tuning Readahead Buffer Sizes
Readahead is a kernel memory optimisation that anticipates sequential read requests. When an application reads data sequentially from a block device, the kernel pre-emptively fetches subsequent sectors into the page cache ahead of time, dramatically accelerating read speeds on large sequential workloads (such as video streaming, database backups, and large log processing).
To inspect the current readahead value of a block device:
sudo blockdev --getra /dev/sda
The output represents the readahead buffer measured in 512-byte sectors. For example, a value of 256 corresponds to a 128 KiB readahead buffer (256 * 512 bytes).
Tuning Readahead for Specific Workloads
For high-throughput sequential data transfers, increasing the readahead cache to 1024 or 2048 sectors (512 KiB or 1 MiB) often yields substantial performance gains:
sudo blockdev --setra 2048 /dev/sda
Conversely, for random I/O database workloads (such as PostgreSQL or transactional NoSQL databases) running on ultra-fast NVMe storage, large readahead values can cause cache pollution by reading unneeded sectors into RAM. In these scenarios, reducing the readahead buffer minimises memory bus saturation:
sudo blockdev --setra 64 /dev/nvme0n1
Setting Device-Level Read-Only and Read-Write Flags
During forensic data acquisition, hardware maintenance, or filesystem integrity verification, you may need to ensure that no application or background process can modify a block device.
To place a block device into read-only mode at the kernel driver layer:
sudo blockdev --setro /dev/sdb1
To verify the active write status of the device:
sudo blockdev --getro /dev/sdb1
The command returns 1 for read-only mode and 0 for read-write mode. While --setro is active, any attempt to write data or format the partition will return an immediate Operation not permitted or Read-only file system error, regardless of root privileges.
To restore normal read-write operation:
sudo blockdev --setrw /dev/sdb1
Flushing Storage Buffers and Rereading Partition Geometry
When detaching external drives, creating raw virtual machine disk backups, or testing unmount procedures, ensuring all unwritten data is flushed from kernel memory to physical non-volatile storage is crucial.
To command the kernel to flush dirty cache buffers for a specific block device:
sudo blockdev --flushbufs /dev/sdb
If you have modified partition boundaries on a disk and need to notify the kernel without rebooting:
sudo blockdev --rereadpt /dev/sdb
Generating a Comprehensive Block Device Report
To audit all low-level parameters across all block devices connected to the system in a clean tabular view, use the --report switch:
sudo blockdev --report
The output presents a structured overview of all devices:
RO RA SSZ BSZ StartSec Size Device
rw 256 512 4096 0 1000204886 /dev/sda
rw 256 512 4096 2048 999155712 /dev/sda1
rw 128 4096 4096 0 2000398934 /dev/nvme0n1
This comprehensive summary enables storage engineers to audit read-only flags (RO), readahead buffers (RA), sector sizes (SSZ), and block sizes (BSZ) across the entire Linux storage fabric in a single command.