Fix fsck and Read-Only File System Errors on Linux
When Linux mounts a filesystem as read-only, it usually means the system detected corruption or an unclean shutdown and is protecting your data. This guide walks you through using fsck to check and repair the filesystem, then remounting it read-write. You’ll need root or sudo access and a basic comfort with the terminal.
What You’ll Need
- Root or sudo access on the affected Linux machine
- Knowledge of the device name for the affected partition (e.g.,
/dev/sda1) – uselsblkordf -hto find it - If the root filesystem is affected, you’ll need a live USB or recovery environment to unmount it safely
Step-by-Step
- Identify the read-only mount. Run
mount | grep roorfindmnt -o TARGET,SOURCE,FSTYPE,OPTIONS | grep roto see which filesystems are mounted read-only. Note the device path (like/dev/sda1) and the mount point (like/or/home). - Unmount the filesystem. For non-root partitions, unmount it:
sudo umount /dev/sda1(orsudo umount /mount/point). If you get a “target is busy� error, usesudo lsof +f -- /mount/pointto find processes using it, close them, then unmount again. - For the root filesystem, boot from a live USB. If the read-only filesystem is
/, you cannot unmount it while running. Boot from a Linux live USB, open a terminal, and mount your root partition somewhere temporary (e.g.,sudo mount /dev/sda1 /mnt). Then unmount it:sudo umount /mnt. - Run fsck on the unmounted filesystem. Use
sudo fsck -f /dev/sda1. The-fforces a check even if the filesystem appears clean. Let it run; it will ask before fixing each issue – pressyto accept fixes, or use-yto auto-answer yes (but be cautious:-ycan discard some recoverable data in rare cases). - Check the exit status. After fsck finishes, it prints an exit code. 0 means no errors, 1 means errors fixed, 2 means system should be rebooted, 4 means errors left unfixed, and 8 means operational error. If you see 4, run fsck again; if it persists, the disk may be failing.
- Remount the filesystem read-write. After a successful fsck, mount it back:
sudo mount /dev/sda1 /mount/point. For the root filesystem from a live USB, you can reboot normally. - If remounting fails or the filesystem is still read-only, try a manual remount. Sometimes the kernel keeps the read-only flag. Run
sudo mount -o remount,rw /mount/pointorsudo mount -o remount,rw /for root. - Check for hardware issues. If fsck repeatedly finds errors, check disk health with
sudo smartctl -a /dev/sda(if smartmontools is installed). Look for reallocated sectors or pending errors.
Common Mistakes
- Running fsck on a mounted filesystem. This can cause severe corruption. Always unmount first. For root, use a live environment.
- Using the wrong device name. Double-check with
lsblk. Using the wrong partition can damage another filesystem. - Ignoring the exit code. If fsck exits with 4, the filesystem is still broken. Re-run or seek further help.
- Using
-yblindly. While convenient, it can delete orphaned files without asking. Prefer interactive mode unless you know what you’re doing. - Forgetting to remount after fixing. The filesystem stays unmounted until you mount it again.
Tips
- Always back up important data before running fsck, especially if the disk shows signs of failure.
- If you suspect a recent unclean shutdown (power loss), run fsck as soon as possible to prevent further issues.
- For ext4 filesystems, you can also use
e2fsck -f /dev/sda1– it’s the same tool. - If the filesystem is mounted read-only due to a kernel error, check
dmesg | tailfor messages like “I/O error� or “remounting filesystem read-only�. - Consider scheduling periodic filesystem checks with
tune2fs -c(for ext4) to catch issues early.
Troubleshooting
- fsck says “Device or resource busy�. The filesystem is still mounted. Unmount it first. If unmount fails, use
sudo lsoforsudo fuser -m /mount/pointto find and stop processes. - fsck reports “Superblock invalid�. The primary superblock is corrupted. Use a backup superblock:
sudo fsck -b 32768 /dev/sda1(for ext4; the backup location is usually 32768, but check withdumpe2fs -h /dev/sda1). - Filesystem still read-only after fsck. Check for hardware errors with
dmesgandsmartctl. If the disk is failing, copy data off immediately. - fsck hangs or takes forever. On large filesystems, it can take hours. Be patient. If it truly hangs (no progress for 30+ minutes), it may be a hardware issue – consider a different disk.
- You get “Permission deniedâ€� when running fsck. Ensure you’re using sudo. Also, the filesystem must be unmounted; you cannot fsck a read-only mounted filesystem directly.
- After fixing, the system still boots to read-only. Check
/etc/fstabfor options likeroorerrors=remount-ro. Removeroif present, and consider changingerrors=remount-rotoerrors=continue(but be aware of the risks).
Frequently Asked Questions
Can I run fsck on a mounted filesystem?
No. Running fsck on a mounted filesystem can cause data corruption. Always unmount first. For root, use a live environment.
What does “read-only file system� mean?
It means the kernel has mounted the filesystem with the read-only flag, usually because it detected corruption or I/O errors. This prevents further damage but also prevents writes.
Will fsck delete my files?
fsck repairs filesystem metadata, not user data. In rare cases, it may place orphaned files in lost+found. It can delete files only if they are beyond repair, which is uncommon.
How long does fsck take?
It depends on the filesystem size and speed. A small partition may take seconds; a multi-terabyte drive can take hours. You can use fsck -C to show progress.
What is the difference between fsck and e2fsck?
fsck is a frontend that calls the appropriate filesystem-specific checker. For ext2/ext3/ext4, it calls e2fsck. Using e2fsck directly works only for those filesystems.
Can I prevent read-only errors in the future?
Regularly check disk health, shut down cleanly, and consider using a UPS to avoid power loss. Also, check /etc/fstab for proper mount options.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.