How to Fix โ€œRead-only file systemโ€ in Linux: A Complete Guide

"Stability is the goal of IT operations, but anomalies are the daily reality."
Photo by Ingmar H / Unsplash

๐Ÿš€

If you encounter an error message like:

Read-only file system

when trying to execute disk write operations (e.g., tar, cp, mv, rm, chmod, chown, wget), it means your Linux filesystem is mounted as read-only, preventing any write operations.

๐Ÿ“Œ In this guide, youโ€™ll learn:
โœ… Why your filesystem is stuck in read-only mode
โœ… How to diagnose whether the issue is caused by disk corruption, filesystem errors, or misconfiguration
โœ… Step-by-step solutions to restore read-write (RW) mode
โœ… Preventive measures to avoid this issue in the future


๐Ÿ›‘ 1. Why is the Filesystem Read-only?

Your Linux filesystem may become read-only due to one of the following reasons:

๐Ÿ”น Filesystem corruption โ€“ Sudden power loss, improper shutdown, or unclean filesystem state
๐Ÿ”น Disk failure or bad sectors โ€“ The disk is failing, triggering the OS to mount it as read-only
๐Ÿ”น Misconfigured /etc/fstab file โ€“ Incorrect mount options, partition type mismatch (e.g., using ntfs instead of ext4)

Before fixing the issue, letโ€™s first diagnose the root cause.


๐Ÿ” 2. Diagnosing the Read-only Filesystem Issue

To identify the cause of the problem, follow these diagnostic steps.

๐Ÿ”น Step 1: Check System Logs for Clues

Run the following command to check logs:

dmesg | tail -50

๐Ÿ“Œ If you see messages like:

EXT4-fs error (device sda1): ext4_journal_check_start:56: Detected aborted journal

โžก๏ธ The issue is likely filesystem corruption.

๐Ÿ“Œ If you see disk I/O errors like:

blk_update_request: I/O error, dev sda, sector 123456

โžก๏ธ The problem is likely a failing hard drive.


๐Ÿ”น Step 2: Check the Mount Status

Verify how your filesystem is currently mounted:

mount | grep ' ro,'

๐Ÿ“Œ If you see:

/dev/sda1 on / type ext4 (ro,errors=remount-ro)

โžก๏ธ The system automatically mounted the filesystem as read-only due to errors.


๐Ÿ”น Step 3: Verify Disk Health

Check the disk for bad sectors:

smartctl -H /dev/sda

๐Ÿ“Œ If the result is "FAILED" or "PRE-FAIL", the disk may be failing.

Run a deeper analysis:

smartctl -a /dev/sda

If Reallocated Sectors Count or Pending Sectors is high, itโ€™s a sign of a failing disk.


๐Ÿ› ๏ธ 3. Fixing the Read-only Filesystem Issue

Once you've identified the cause, follow the appropriate solution below.


๐Ÿ”น Case 1: Remount the Filesystem in Read-Write Mode

If the system was accidentally mounted as read-only, remount it as read-write:

mount -o remount,rw /

โœ… Test by creating a new file:

touch /testfile

๐Ÿ“Œ If this works, the issue was temporary, and no further action is needed.


๐Ÿ”น Case 2: Fix Filesystem Errors with fsck

If your filesystem is corrupted, follow these steps:

1๏ธโƒฃ Boot into Recovery Mode or a Live CD If / is mounted as read-only, unmount the partition before repairing:

umount /dev/sda1

2๏ธโƒฃ Run fsck to Check and Repair the Filesystem

fsck -y /dev/sda1

๐Ÿ“Œ The -y option automatically fixes errors.

3๏ธโƒฃ Reboot the system

reboot

โœ… If errors were fixed, the filesystem should now mount as read-write.


๐Ÿ”น Case 3: Fix /etc/fstab Misconfiguration

If the issue is caused by an incorrect /etc/fstab entry, follow these steps:

1๏ธโƒฃ Check /etc/fstab

cat /etc/fstab

๐Ÿ“Œ Example Incorrect Entry:

UUID=abc123 / ext4 defaults,ro 0 1

โŒ The "ro" option forces read-only mode!

2๏ธโƒฃ Fix the Configuration Edit /etc/fstab:

nano /etc/fstab

Change:

UUID=abc123 / ext4 defaults,rw 0 1

โœ… Save the file and reboot:

reboot

๐Ÿ”น Case 4: Disk Failure โ€“ Backup & Replace the Drive

If smartctl reports a failing disk, it's time to back up data and replace the drive.

1๏ธโƒฃ Copy Data to a Backup Drive Use rsync to back up important files:

rsync -av /home/ /mnt/backup/

2๏ธโƒฃ Clone the Disk (If Still Readable)

dd if=/dev/sda of=/dev/sdb bs=64K conv=noerror,sync

3๏ธโƒฃ Replace the Hard Drive Once backed up, install a new disk, reinstall Linux, and restore your data.


๐Ÿ›ก๏ธ 4. Preventing Future Read-only Filesystem Issues

Follow these best practices to avoid this problem in the future:

โœ… Use a UPS (Uninterruptible Power Supply) to prevent power-related filesystem corruption.
โœ… Run regular disk health checks:

smartctl -a /dev/sda

โœ… Schedule periodic filesystem checks:

fsck -n /dev/sda1

โœ… Modify /etc/fstab safely โ€“ Always back it up before making changes:

cp /etc/fstab /etc/fstab.bak

๐Ÿ“Š 5. Summary

Issue Solution
Filesystem is in read-only mode Remount it using mount -o remount,rw /
Filesystem corruption detected Run fsck -y /dev/sda1 to repair it
/etc/fstab is misconfigured Fix incorrect options (e.g., remove ro)
Disk has bad sectors Use smartctl to check health; replace if necessary
Prevent future issues Use UPS, run fsck regularly, and monitor disk health

๐Ÿ’ฌ Join the Discussion!

Have you ever encountered the "Read-only file system" error in Linux?
What steps did you take to resolve it?

๐Ÿ’ฌ Share your experience in the comments below! ๐Ÿš€

๐Ÿ‘‰ If youโ€™re troubleshooting Linux boot issues, check out: How to Fix GRUB Boot Failure in Linux


Read more