ThisCalculator

Everyday

Fix fsck and Read-Only File System Errors on Linux

Updated · Standard formula, shown below

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) – use lsblk or df -h to find it
  • If the root filesystem is affected, you’ll need a live USB or recovery environment to unmount it safely

Step-by-Step

  1. Identify the read-only mount. Run mount | grep ro or findmnt -o TARGET,SOURCE,FSTYPE,OPTIONS | grep ro to see which filesystems are mounted read-only. Note the device path (like /dev/sda1) and the mount point (like / or /home).
  2. Unmount the filesystem. For non-root partitions, unmount it: sudo umount /dev/sda1 (or sudo umount /mount/point). If you get a “target is busy� error, use sudo lsof +f -- /mount/point to find processes using it, close them, then unmount again.
  3. 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.
  4. Run fsck on the unmounted filesystem. Use sudo fsck -f /dev/sda1. The -f forces a check even if the filesystem appears clean. Let it run; it will ask before fixing each issue – press y to accept fixes, or use -y to auto-answer yes (but be cautious: -y can discard some recoverable data in rare cases).
  5. 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.
  6. 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.
  7. 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/point or sudo mount -o remount,rw / for root.
  8. 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 -y blindly. 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 | tail for 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 lsof or sudo fuser -m /mount/point to 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 with dumpe2fs -h /dev/sda1).
  • Filesystem still read-only after fsck. Check for hardware errors with dmesg and smartctl. 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/fstab for options like ro or errors=remount-ro. Remove ro if present, and consider changing errors=remount-ro to errors=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.