Attempting to modify file attributes or execute administrative permissions in Linux using chmod +x script.sh or chmod 755 /var/www only to be stopped by the error: ‘chmod: changing permissions of \’file\’: Read-only file system’ brings system administration to a halt. In Linux filesystem architecture, when an underlying storage device encounters severe I/O errors, storage controller timeouts, bad disk sectors, or filesystem metadata corruption, the Linux kernel automatically remounts the affected partition as read-only (ro) to prevent catastrophic data destruction.
Why Does Linux Remount Filesystems as Read-Only?
The read-only filesystem lock is an emergency self-preservation mechanism triggered by the kernel:
- Filesystem Corruption Detected: The filesystem driver (ext4, XFS, Btrfs) detecting invalid inode pointers or broken block allocations, executing its configured
errors=remount-ropolicy. - Hardware Storage Controller Timeouts: Dropped SATA, NVMe, or USB bus connections causing the kernel to lose write acknowledgment.
- Unclean Shutdowns or Power Outages: Abrupt power interruptions leaving filesystem journal transactions incomplete.
- Failing Physical Drive or Bad Sectors: SMART disk degradation forcing read-only protection.
- Explicit Read-Only Mount Flags in /etc/fstab: Storage mounts configured with
roinstead ofrw.
Step 1: Inspect Mounted Filesystem Status with mount
Identify which partition has been placed into read-only mode.
- Open your terminal and run:
mount | grep -w 'ro' - Inspect the output to pinpoint the mount point (e.g.
/dev/sda1 on / type ext4 (ro,relatime)). - Check the kernel ring buffer to view the exact error that triggered the lock:
sudo dmesg -T | grep -E -i 'error|read-only|ext4|i/o' | tail -n 20
Step 2: Remount the Filesystem as Read-Write (rw)
If the error was caused by a transient bus timeout or configuration error, remounting restores immediate write access.
- Execute the remount command with root privileges:
(Replacesudo mount -o remount,rw //with your specific mount point, e.g./dataor/mnt/storage). - Test creating or modifying a file:
touch /tmp/test_write && rm /tmp/test_write - If the remount fails with ‘Cannot remount read-write: Filesystem has errors’, proceed to filesystem check repairs.
Step 3: Check and Repair Filesystem Errors with fsck
Repairing corrupted filesystem journal structures allows the kernel to mount partitions in read-write mode safely.
- Important: Never run
fsckon an actively mounted read-write filesystem. Ensure the target is unmounted or read-only. - If repairing a secondary drive:
sudo umount /dev/sdb1 sudo fsck -yf /dev/sdb1 - If repairing the primary root partition (
/), force a filesystem check on the next boot:sudo touch /forcefsck sudo reboot - Alternatively, boot from an Ubuntu Live USB, open terminal, and run:
sudo fsck -yf /dev/sdX1
Step 4: Inspect /etc/fstab for Incorrect Mount Options
Ensure permanent mount configuration entries do not specify read-only flags.
- Open
/etc/fstabin a text editor:sudo nano /etc/fstab - Review the mount options for your drives. Ensure options specify
defaultsorrwrather thanro. - Save changes if modifications were made.
Step 5: Check Physical Drive SMART Health
Verify whether hardware drive degradation is triggering safety locks.
- Install smartmontools:
sudo apt install smartmontools -y - Run a drive health check:
sudo smartctl -H /dev/sda - If the output reports FAILED or high reallocated sector counts, back up all critical files immediately and replace the physical drive.
Inspecting kernel messages with dmesg, remounting partitions via mount -o remount,rw, running fsck disk repairs, and checking SMART health resolves ‘chmod: Read-only file system’ in Linux.