Skip to content
ohsudo, Home
Linux

"Read-only file system" on Linux: why the disk went read-only, and how to fix it safely

Fix "Read-only file system" errors: find the read-only mount, read dmesg to see why the kernel did it, then repair with fsck — and check whether the disk is failing.

Intermediate4 min readApplies to Ubuntu · Debian · RHEL / Rocky / AlmaLinux · ext4 · XFS · Docker · Kubernetes

by OhSudo ··

Not sure this is your cause?Find it step by step: Disk full or out of memory →

Writes that worked yesterday now fail — for every user, root included:

$ touch /data/reports/new.csv
touch: cannot touch '/data/reports/new.csv': Read-only file system

Applications report the same thing as EROFS: read-only file system or OSError: [Errno 30] Read-only file system. It’s not a permission problem: the whole filesystem is mounted read-only. Often the kernel did that on purpose — it found errors on the disk and stopped all writes before they could make things worse. So before you make it writable again, find out why.

  1. Disk or filesystem error(breaks here)
  2. The kernelremounts it read-only
  3. Every write failsfor every user, root included
It isn't a permission: the whole filesystem is mounted read-only. Often the kernel did it on purpose, after finding errors, to stop the damage from spreading.

TL;DR

Terminal window
findmnt /data # mounted "ro"?
sudo dmesg | tail -n 4 # why: filesystem errors? I/O errors from the disk?
Terminal window
sudo umount /data # stop what uses it first
sudo fsck -y /dev/sdb1 # repair — only on an unmounted filesystem
sudo mount /data # mount it again, read-write, from /etc/fstab

1. Confirm it’s mounted read-only

Terminal window
findmnt /data
TARGET SOURCE FSTYPE OPTIONS
/data /dev/sdb1 ext4 ro,relatime

ro at the start of the options is the answer. To see every read-only mount: grep ' ro,' /proc/mounts. Note the device (/dev/sdb1) — you’ll need it.

2. Find out why: the kernel log

Terminal window
sudo dmesg | tail -n 4
[ 8421.553012] EXT4-fs error (device sdb1): ext4_lookup:1855: inode #131074: comm rsync: deleted inode referenced: 131090
[ 8421.553219] Aborting journal on device sdb1-8.
[ 8421.554901] EXT4-fs (sdb1): Remounting filesystem read-only

(On Ubuntu, reading dmesg needs sudo. sudo journalctl -k shows the same, from earlier boots too.)

  • EXT4-fs error … Remounting filesystem read-only — ext4 found an inconsistency, and the mount option errors=remount-ro (the default for root filesystems in Ubuntu’s /etc/fstab) told it to stop writing. The filesystem needs a check (section 3).
  • I/O error, blk_update_request, Buffer I/O error, critical medium error — the disk itself is failing, or a cloud volume / SAN path is gone. Copy off important data first, while you can still read it (section 4).
  • Nothing like that — maybe it was mounted read-only on purpose (section 5).

3. Repair the filesystem

fsck must run on an unmounted filesystem — on a mounted one it refuses, and forcing it can destroy data:

/dev/sdb1 is mounted.
e2fsck: Cannot continue, aborting.

Stop what uses the filesystem, unmount, check, mount again:

Terminal window
sudo umount /data
sudo fsck -y /dev/sdb1
sudo mount /data

umount: /data: target is busy. means some process (or a shell whose current folder is there) still uses it. sudo fuser -vm /data lists them; stop those services and cd out of the folder.

fsck -y answers “yes” to every repair question. Read the output: lines like Clear? yes and FILE SYSTEM WAS MODIFIED mean it fixed something. Files it couldn’t place end up in lost+found on that filesystem. Then check that the app’s data is complete.

XFS uses sudo xfs_repair /dev/sdb1 instead of fsck (also unmounted). When XFS finds corruption it shuts the filesystem down, and you see Input/output error rather than “read-only”.

The root filesystem can’t be unmounted while the system runs. Schedule the check for the next boot: in the GRUB menu press e, add fsck.mode=force fsck.repair=yes at the end of the linux line, and boot with Ctrl+X (it applies to that boot only). On a cloud server without console access, attach the disk to another machine and check it there.

Warning

mount -o remount,rw is not a fix. It works — ext4 allows it, with a warning in dmesg — but the errors are still on the disk, and the next write that hits them can make the damage bigger, or send the filesystem read-only again. Use it only to get something urgent off the system, then repair.

4. When the disk is failing

If the log shows I/O errors, the filesystem is only the messenger. Check the disk’s own health (package smartmontools):

Terminal window
sudo smartctl -H -a /dev/sdb

SMART overall-health self-assessment test result: FAILED, or growing Reallocated_Sector_Ct / Current_Pending_Sector values, mean: copy the data elsewhere now, and replace the disk. Running fsck on a dying disk can speed up the end. On SD cards (Raspberry Pi) and cheap USB sticks, read-only is often how a worn-out card announces itself. In the cloud, check the volume’s status in the provider’s console.

5. Read-only on purpose

Not every read-only mount is an accident:

  • /etc/fstab has ro for that filesystem — someone set it up that way. Change the option and remount.
  • ISO images, snapshots, squashfs (including snap packages under /snap) are always read-only.
  • Docker: a volume mounted with :ro, or a container started with --read-only / read_only: true. Write to a separate volume or a tmpfs instead.
  • Kubernetes: readOnlyRootFilesystem: true in the security context. Give the app an emptyDir volume for the folders it must write to.

Shell, we have a problem!

Similar, but different: No space left on device — the disk is full, not read-only; see No space left on device. Permission denied — the filesystem is writable, but not for this user. Input/output error — the read itself failed: a disk or storage problem (section 4). If unmounting it fails, see target is busy. If mounting it again fails, see wrong fs type, bad option, bad superblock. Structure needs cleaning is a damaged filesystem: unmount it and run fsck.

$ ./practice.sh

Practice this in the terminal

Open the Terminal Playground with this article’s scenario loaded. It is safe and runs in your browser.

Open the terminal →

Found this useful? Share it.

Found a mistake? Let us know at contact@ohsudo.com.

Tools

Try it yourself

Articles

Related articles