How to Fix โRead-only file systemโ in Linux: A Complete Guide
๐
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