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.
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.