A sudden power outage, an accidental pull of the power cord, or an unexpected server crash can leave your Linux system in a precarious state. One of the most common and alarming symptoms is the “Read-only Filesystem” error. This occurs when the kernel detects inconsistencies in the file system metadata—often due to unflushed dirty data—and automatically remounts partitions as read-only to prevent further corruption.
For IT students, junior engineers, and seasoned practitioners, understanding how to diagnose and fix this issue is a critical skill. Unlike Windows systems which might prompt you immediately upon booting, Linux requires manual intervention in the shell. This guide walks you through the recovery process using safe, standard shell commands, explaining exactly what each step does so you can adapt it to your specific environment.
Understanding the Root Cause and Immediate Safety
Before attempting any repairs, it is vital to understand why this happens. Modern file systems like ext4, xfs, or btrfs maintain a journal to track changes. When power fails, the journal may be incomplete, leaving the file system in an inconsistent state. The kernel’s default behavior is to remount the root and other partitions as read-only to protect existing data from being overwritten during a repair attempt.
Important Safety Note: Never force a write operation on a filesystem that is currently mounted read-only. Your goal is to repair the metadata, not to write new files yet. Always work in a safe environment, such as a virtual machine or a dedicated test server, before applying these steps to production infrastructure.
Step 1: Identify the Affected Filesystem
The first step is to determine which partition has been remounted read-only. You can do this by checking the mount options using the mount command. This lists all currently mounted filesystems and their properties.
sudo mount | grep -E 'on /|on /home'
Expected Output:
/dev/sda2 on / type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sdb1 on /home type xfs (ro,relatime,seclabel)
In this illustrative example, the root partition (/) is writable (rw), but the /home partition mounted from /dev/sdb1 is read-only (ro). Note that some systems may remount only the root partition. If you see ro next to your primary filesystem, proceed immediately to unmounting it.
Step 2: Unmount and Remount the Filesystem
The most straightforward recovery method for a single partition (like /home) is to unmount it and then mount it again in read-write mode. The kernel will attempt to run its built-in consistency checks automatically during this process.
First, ensure no processes are accessing the directory by running fuser or lsof:
sudo fuser -vm /home
# If output shows PIDs, kill them: sudo kill -9 <PID>
Next, unmount the partition:
sudo umount /home
Now, remount it explicitly with read-write permissions:
sudo mount -o remount,rw /home
Verification: Run mount again. The output should now show (rw,...) for the /home partition instead of (ro,...). If this works, your data is safe, and you can continue normal operations.
Step 3: Repairing the Root Filesystem
Repairing the root filesystem (/) requires unmounting it while the system is running, which is risky because critical processes are still using it. The safest approach is to reboot into a rescue mode or use a live USB environment. However, many modern distributions allow for emergency repair via fsck from within the current session if you can safely isolate the partition.
A safer alternative for root repair is to drop to an emergency shell:
sudo init 1
# Or on systemd systems:
sudo systemctl reboot --force
Once in single-user mode or a rescue shell, mount the root filesystem as read-write (it will be mounted read-only by default):
mount -o remount,rw /
Then, run the file system check. For ext4, use fsck:
sudo fsck -y /dev/sda2
Note: Replace /dev/sda2 with your actual root device.
The -y flag automatically answers “yes” to repair prompts, which is useful in automated scripts but should be used with caution on production systems. For XFS, the command is xfs_repair:
sudo xfs_repair /dev/sdb1
Illustrative Output:
e2fsck 1.47.0 (5-Feb-2023)
Pass 1: Checking inodes, blocks, and superblocks... done
Pass 2: Checking directory structure... done
Pass 3: Checking directory connectivity... done
Pass 4: Checking reference counts... done
Pass 5: Checking group summary information...
Filesystem /dev/sda2 is clean.
After the check completes, reboot the system normally to ensure the filesystem is mounted correctly in multi-user mode.
Step 4: Using Failsafe or Recovery Mode
If you cannot unmount the root filesystem or if fsck fails, your distribution likely offers a “Failsafe” or “Recovery Mode” boot option in the GRUB bootloader menu. This mode starts the system with minimal services and often mounts the root filesystem as read-write specifically for repair purposes.
- Reboot the machine.
- Hold
Shift(or pressEscon UEFI systems) to pause the GRUB menu. - Select “Advanced options” -> “[Kernel Version] (recovery mode)” or “(failsafe)”.
- Select “root shell” from the recovery menu.
- Run
fsck -y /dev/sdX(replace with your device). - Reboot.
This method is highly recommended for production servers where you cannot afford to unmount the root filesystem while running applications.
Step 5: Common Mistakes and Prevention Strategies
A frequent mistake is attempting to run fsck on a mounted read-only filesystem without first remounting it as read-write (in rescue mode). Running fsck on a live, mounted root partition can lead to data loss or kernel panics. Always ensure the filesystem is unmounted or in a single-user state before repairing.
Another common error is ignoring the underlying cause. If the power failure was due to an unstable power supply or overheating hardware, running repairs repeatedly will not solve the problem; the hardware must be addressed. Additionally, always ensure your system is configured to flush data properly. Check your mount options for noatime and nodiratime, which reduce write frequency, but never disable journaling (data=ordered should remain default).
Student Practice Task: Simulating a Crash
To solidify these skills, try this exercise in a Virtual Machine (e.g., Ubuntu 22.04 LTS):
1. Create a new directory and copy some files: mkdir -p /test_data && cp /etc/passwd /test_data/.
2. Simulate a crash by forcing a reboot immediately after writing data, or unplug the power if using a physical machine.
3. On boot, observe the “File system check” message in the logs (dmesg | grep -i fsck).
4. Attempt to write a new file to /test_data. You will likely get a “Read-only file system” error.
5. Follow the steps above to unmount and repair.
6. Verify you can now write to the directory.
Industry Application: Automated Monitoring
In professional environments, relying on manual intervention is insufficient. System administrators often configure monitoring tools like Nagios, Zabbix, or Prometheus to detect when a filesystem becomes read-only. When this event triggers an alert, it indicates a potential hardware failure or corruption that needs immediate attention. The remediation playbook usually involves rebooting into rescue mode and running fsck, followed by checking SMART data for disk health and inspecting UPS logs for power events.
By mastering these recovery techniques, you ensure business continuity and protect valuable data from catastrophic loss due to simple electrical glitches.
Educational-use notice: This tutorial is for learning and controlled lab use only. Test carefully, use backups, and obtain authorization before making changes. Do not run unfamiliar commands on production systems. We accept no responsibility for misuse, damage, data loss, or production issues.

