Read-only filesystem: how to recover

Topic: Servers linux

Summary

When a filesystem is mounted read-only due to errors or full disk: free space if full, run fsck to repair errors, then remount read-write. Use this when writes fail with 'read-only file system' or after an unclean shutdown.

Intent: Troubleshooting

Quick answer

  • If full: free space from another session or single-user (truncate logs, delete caches); then remount rw: mount -o remount,rw /.
  • If errors: boot single-user or from live ISO; umount the fs; fsck -f /dev/sdX; fix or accept fixes; mount and reboot.
  • Check dmesg for I/O or ext4 errors; add nofail in fstab for non-root so the system boots even if the disk is missing or failed.

Prerequisites

Steps

  1. Determine cause

    dmesg | tail -50 for 'ext4' or 'read-only'; df -h and du for full disk; if full, free space first then remount.

  2. Remount if disk was full

    Free space (see disk-full guide); then mount -o remount,rw / or the mount point; verify with touch /path/test.

  3. Run fsck if errors

    Boot single-user or live; umount the partition; fsck -f /dev/sdb1; answer prompts or -y; mount and reboot.

  4. Prevent recurrence

    Fix underlying disk or cable; ensure clean shutdown; use nofail in fstab for optional disks so boot does not hang.

Summary

You will recover a read-only filesystem by freeing space (if full) and remounting, or by running fsck (if errors) and then remounting. Use this when writes fail with read-only or after a crash.

Prerequisites

  • Root; console or single-user/live boot if root fs is ro.

Steps

Step 1: Determine cause

dmesg | tail -50
df -h

Step 2: Remount if disk was full

Free space; then:

sudo mount -o remount,rw /

Step 3: Run fsck if errors

From single-user or live: umount /dev/sdb1; fsck -f /dev/sdb1; then mount and reboot.

Step 4: Prevent recurrence

  • Fix disk hardware or cable; avoid hard power off; use nofail for non-critical mounts.

Verification

  • Mount shows rw; touch works; dmesg has no new read-only or I/O errors.

Troubleshooting

Cannot remount rw — Underlying error; run fsck; replace disk if hardware fault.

fsck asks many questions — Run with -y for automatic fix; backup first if data is critical.

Next steps

Continue to