What the message looks like
touch: cannot touch '/var/www/test': Read-only file systemCommon causes
- ext4 with
errors=remount-rodetected an error and switched to read-only. - Failing disk or SSD, I/O errors in the VM's storage backend.
- Mounted
roin/etc/fstab, or a deliberately read-only root (containers, appliances). - systemd hardening:
ProtectSystem=strictmakes everything exceptReadWritePathsread-only for the service. - Thin-provisioned storage full on the hypervisor.
Check
- Show mount options of the affected path
findmnt -o TARGET,SOURCE,FSTYPE,OPTIONS -T /var/www - Search kernel messages for filesystem and I/O errors
dmesg -T | grep -iE 'EXT4-fs error|I/O error|remount|read-only' | tail -n 20 - Check the disk's SMART status
smartctl -H -A /dev/sda - Show the service's systemd hardening
systemctl show nginx.service -p ProtectSystem -p ReadWritePaths -p ProtectHome
Fix
- Back up data first – while it can still be read.
- For filesystem errors run
fsck -fon the unmounted device from a rescue system. - Only if the cause is clear and harmless:
mount -o remount,rw /. - For systemd services allow the needed paths via override:
ReadWritePaths=/var/www/uploads. - With I/O or SMART errors replace the disk or contact the hoster.
Typical scenario
On a VM all write operations suddenly fail with 'Read-only file system' and applications report errors when saving. A storage hiccup on the hypervisor occurred shortly before. The kernel itself set the filesystem to read-only because of I/O errors, since /etc/fstab has the option errors=remount-ro. First search with dmesg -T | grep -iE 'remount|i/o error|ext4-fs error' for the triggering event before you remount anything.
FAQ
Can I just run remount,rw?
Technically yes, but if the kernel switched because of errors you are writing to a damaged filesystem. Check first, then remount.
Why can root write but the service cannot?
Then systemd hardening is usually active. ProtectSystem and ReadOnlyPaths only apply in the service's namespace, not in your shell.
Can I simply run mount -o remount,rw /?
Technically often yes, but only after the cause is clear. The filesystem was locked for a good reason. Forcing writes onto a damaged filesystem can make errors worse. Back up first, then if needed check with fsck while unmounted.
What does the errors= option control?
It defines how ext4 reacts to errors: continue ignores them, remount-ro switches to read-only, panic halts the system. Debian-based systems often use remount-ro as the default on the root partition.
How do I tell it was not the kernel?
Containers and orchestration also block writes: Docker with --read-only or Kubernetes with readOnlyRootFilesystem. mount | grep ' ro,' shows whether the filesystem is read-only on the host or only inside the container.