Home › Linux & shell

Read-only file system — how to fix

touch: cannot touch 'test.txt': Read-only file system
cp: cannot create regular file '/etc/hosts': Read-only file system
OSError: [Errno 30] Read-only file system: '/app/data'

Quick fix: Check the mount: findmnt -no OPTIONS --target /path. If the kernel remounted it due to errors (dmesg | grep -i 'remount\|error'), back up, then run fsck from a rescue/unmounted state. If it's just mounted ro, remount: sudo mount -o remount,rw /mountpoint. In containers, write to a mounted volume or tmpfs instead.

What it means

The write failed with EROFS: the filesystem itself is read-only, regardless of file permissions — even root can't write. Find which mount the path is on and its options:

findmnt --target /path/you/tried
mount | grep ' ro[ ,]'

The cause decides the fix. Don't just remount read-write before checking the kernel log.

Cause 1: the kernel remounted it after disk errors

ext4 is usually mounted with errors=remount-ro: on a detected corruption or I/O error, the kernel flips it to read-only to prevent damage. Check:

sudo dmesg -T | grep -iE 'remount|EXT4-fs error|I/O error|xfs|btrfs'
sudo journalctl -k -b | grep -i error

Messages like EXT4-fs error ... Remounting filesystem read-only or blk_update_request: I/O error mean a filesystem or hardware problem.

What to do:

  1. Back up anything important now (it's still readable).
  2. Check the disk's health: sudo smartctl -a /dev/sda (package smartmontools).
  3. Run a filesystem check while it's unmounted. For the root filesystem, reboot into recovery mode or a live USB:
sudo umount /dev/sdb1
sudo fsck -f /dev/sdb1          # ext4: e2fsck; xfs: xfs_repair; never fsck a mounted fs

For root on ext4 you can also schedule a check at boot by adding fsck.mode=force to the kernel command line once.

On VMs/cloud instances this often follows a storage hiccup (network disk timeout); a reboot plus fsck usually fixes it.

Cause 2: mounted read-only on purpose

Check /etc/fstab for ro, or a recovery-mode boot (root is ro until remounted). Remount:

sudo mount -o remount,rw /
sudo mount -o remount,rw /mnt/data

Then fix /etc/fstab if it's set to ro there.

Cause 3: NTFS / USB drives

Cause 4: containers

Docker with --read-only, Kubernetes with readOnlyRootFilesystem: true, and many serverless platforms (AWS Lambda — only /tmp is writable) make the root filesystem read-only. Write to a volume or tmpfs:

docker run --read-only --tmpfs /tmp -v appdata:/app/data myimage
# Kubernetes
volumeMounts:
  - { name: tmp, mountPath: /tmp }
volumes:
  - { name: tmp, emptyDir: {} }

Bind mounts with :ro (-v ./conf:/etc/app:ro) are read-only too. Inside a container, /proc/sys and /sys are read-only — set sysctls with docker run --sysctl instead.

Cause 5: system paths protected by design

Last updated 2026-11-03.