Linux block-device read-only flag
The Linux block-device read-only flag is a software-controlled device state exposed through block-device ioctls to restrict write access.
The util-linux v2.41.1 manual warns that changing the flag may leave existing active access unaffected, including a filesystem already in read-write use. [1] In Linux v7.3, BLKROSET and BLKROGET are ioctl numbers 93 and 94, and BLKROSET without CAP_SYS_ADMIN returns EACCES. [5] A device also counts as read-only when the whole-disk flag is set or the driver reports write protection. [6] A flag value alone is not evidence of a validated forensic write-blocking workflow; NIST publishes software write-blocker test resources, so software and unvalidated are not synonyms. [3]
Relations
Advantages
- blockdev --getro prints 1 or 0, so the state can be checked from a shell without a custom ioctl program. [1]
- A driver hook can refuse the change before the flag is set, so a device that cannot honor the request can reject it. [5]
- Because the flag is kept per block device, one partition can be read-only while the whole disk stays writable. blockdev --report gives each partition start as StartSec in 512-byte sectors, which ties a read-only partition to its disk offset. [1, 6]
Limitations
- Device state, filesystem state and subvolume properties have distinct scopes. [1, 2]
- The flag is a kernel software state and does not by itself prove that the drive firmware rejects write commands. [5, 6]
Citations
- util-linux v2.41.1: blockdev(8), read-only flag and active-access caveat
- util-linux v2.41.1: mount(8), Read-only Setting Notes
- NIST CFTT: Software Write Block testing resources
- Linux v7.3 block/ioctl.c: BLKROSET permission check and read-only flag
- Linux v7.3 include/linux/blkdev.h: per-device and whole-disk read-only tests
Further reading
Sources & caveats
- blockdev is the util-linux v2.41.1 blockdev(8) source at the cited tag, re-read for --setro, --getro, the active-access caveat and the 512-byte StartSec unit of --report.
- linux-blk-ioctl is block/ioctl.c at v7.3, read for the CAP_SYS_ADMIN check, the driver hook and the flag update. The ioctl numbers were checked in include/uapi/linux/fs.h at v7.3.
- linux-blkdev-h is include/linux/blkdev.h at v7.3, read for the combined per-device and whole-disk test. block/genhd.c at v7.3 was read for the sysfs ro attribute and driver write protection.
- The btrfs-send-stream entry links here because send needs a read-only source subvolume, a scope distinct from this device-level state.