Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
Linux

Read-only file system on Linux: causes and safe fixes

Fix the Read-only file system error on Linux: find which mount went read-only and why, from ext4 errors to systemd sandboxing, then repair without data loss.

CloudSat teamNovember 18, 20266 min read
A folder shape sealed behind a translucent pane of glass with a small padlock, floating over a dark grid
On this pageMeasure the scope first

"Read-only file system" is the kernel's way of refusing a write. The refusal can come from four different places: the storage device, the filesystem's own error handling, the way something was mounted, or a sandbox wrapped around a single program. The fix depends entirely on which one said no, and the most common reflex, remounting read-write straight away, can turn a recoverable problem into lost data. Work through it in order: measure the scope, read the reason, protect the data, then repair.

Measure the scope first

Start by finding out whether the whole system is affected or just one program:

sudo touch /rw-test && sudo rm /rw-test && echo "root filesystem is writable"
findmnt -o TARGET,SOURCE,FSTYPE,OPTIONS /
findmnt -O ro

findmnt -O ro lists every read-only mount. Ignore the ones that are read-only by design, such as snap packages under /snap and some pseudo filesystems. If the root filesystem or a data volume shows ro and you never asked for it, the kernel probably made that decision for you. If your shell can write but one service cannot, skip ahead to the sandbox section.

What you see Most likely cause
Every write fails; the kernel log shows EXT4-fs error and "Remounting filesystem read-only" ext4 found damage and protected itself
Writes fail; the log shows I/O error or Buffer I/O error lines The storage device or its connection
Btrfs reports it was "forced readonly" Btrfs hit metadata damage or a failed transaction
XFS says the filesystem "has been shut down" XFS stopped after a serious error (you see I/O errors, not EROFS)
Only one service fails, the shell writes fine systemd sandboxing such as ProtectSystem
Only inside a container A read-only container or a :ro bind mount
An NTFS disk from a Windows machine Windows hibernation or Fast Startup left the volume in use

Read the reason in the kernel log

sudo dmesg -T | grep -iE 'ext4|xfs|btrfs|i/o error|read-only|remount' | tail -n 30
sudo journalctl -k -b -1 | grep -iE 'error|read-only'    # previous boot, if the journal is kept on disk

On Ubuntu and Debian, the root entry in /etc/fstab carries errors=remount-ro. When ext4 detects an inconsistency, it flips the filesystem to read-only instead of carrying on and writing over damaged structures. That is a protection, not the fault itself. The lines just before "Remounting filesystem read-only" tell you whether the trigger was a corrupted structure or a failing device underneath.

I/O errors change the plan. A filesystem check on a device that keeps failing makes matters worse, so on a VPS, send the timestamps and messages to your provider, and on your own hardware read the drive's health first with sudo smartctl -a /dev/sda or sudo nvme smart-log /dev/nvme0.

Protect the data before any repair

A read-only filesystem is still readable, which makes this the best moment to copy what matters. Dump databases, then copy application data to another machine:

rsync -aHAX --info=progress2 /srv/app/ backup@198.51.100.20:/backups/app/

A repair tool can move damaged files into lost+found or drop them altogether, so copy first and repair second. On a CloudSat server, also take a snapshot before you start, and use the VNC console or a rescue boot from the recovery tools when the root filesystem has to be checked while unmounted.

Repair the filesystem

The one firm rule: never run a repair tool on a filesystem mounted read-write.

A data volume you can unmount is the easy case. Stop the services that use it, then check it with the tool for its type:

sudo umount /srv/data
sudo e2fsck -f /dev/vdb1        # ext4
sudo xfs_repair /dev/vdb1       # XFS
sudo btrfs check --readonly /dev/vdb1   # Btrfs: report only, change nothing
sudo mount /srv/data

To see how bad things are before changing anything, run ext4's check in no-change mode first: sudo e2fsck -fn /dev/vdb1 answers "no" to every question and only reports. A handful of fixed counts and bitmaps is routine; hundreds of damaged inodes mean you should restore from backup rather than trust the repaired copy. After a real repair, look in the volume's lost+found directory for recovered fragments, and run your application's own consistency checks, such as a database's integrity check, before you put the volume back into service.

For XFS, mount the filesystem once first if xfs_repair complains about a dirty log, so the log replays. xfs_repair -L throws the log away and is a last resort. For Btrfs, btrfs check --repair is also a last resort, to try only with backups in hand.

The root filesystem cannot be unmounted while the system runs from it. Two clean options:

  1. Boot a rescue system, then run e2fsck -f /dev/vda1 (or the tool for your filesystem) on the unmounted root partition.
  2. Ask the next boot to check and repair: at the GRUB menu, press e, add fsck.mode=force fsck.repair=yes to the line that starts with linux, and boot with Ctrl+X. systemd runs the check before mounting root read-write.

After a clean check, reboot. Run mount -o remount,rw / only once you know why the filesystem went read-only and that the cause is gone.

When the disk is fine

systemd sandboxing

Hardened units restrict where a service may write. ProtectSystem=strict makes the whole filesystem read-only for that service except paths listed in ReadWritePaths=, and ProtectSystem=full covers /usr, /boot and /etc. A service that tries to write elsewhere gets "Read-only file system" while your shell writes the same path without trouble. Inspect the unit, then grant exactly the path it needs:

systemctl show myapp -p ProtectSystem -p ProtectHome -p ReadWritePaths -p ReadOnlyPaths
sudo systemctl edit myapp
[Service]
ReadWritePaths=/var/lib/myapp

Save the override, then run sudo systemctl restart myapp. Granting one directory keeps the rest of the protection in place, which is better than deleting the hardening line.

Containers

A container started with --read-only (or read_only: true in Compose) can only write to volumes and tmpfs mounts, and a bind mount ending in :ro is read-only inside the container. Check both with:

docker inspect -f '{{.HostConfig.ReadonlyRootfs}} {{json .Mounts}}' web

Media that is read-only by design

Snap packages are squashfs images, and ISO files mount read-only, so writes there always fail. An NTFS disk last used by Windows with Fast Startup or hibernation is locked as "in use": shut Windows down fully, or turn off Fast Startup, then mount it again on Linux.

Keep it from coming back

  • Alert on kernel messages containing EXT4-fs error, I/O error or forced readonly, so the next event reaches you before users do.
  • Check sudo tune2fs -l /dev/vda1 | grep -iE 'state|error count' after an incident: a filesystem state other than clean or a growing error count means the problem is not over.
  • Keep backups on another machine and test a restore; the backup and restore plan covers the routine.
  • Leave errors=remount-ro in place. Read-only is inconvenient, but it stops damage from spreading.

FAQ

Can I just run mount -o remount,rw / and carry on?

Sometimes it works, but if the kernel forced read-only because of errors, writing again risks deeper damage. Read the log and check the filesystem first.

Does a full disk make the filesystem read-only?

Not on ext4 or XFS: a full disk returns "No space left on device", and so do exhausted inodes. Btrfs is different, and can switch to read-only when it runs out of space in the middle of a transaction.

Why is the system read-only right after boot?

Either /etc/fstab asks for ro, or the boot stopped in emergency mode because a filesystem check or a mount failed, which leaves root read-only. Run systemctl --failed and journalctl -b -p err to see which step failed.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.