Linux Tips guides, explanations and reader checklists on whilenetworking.com

Resolving ‘Read-Only Filesystem’ Errors After Unexpected Power Loss with Remount Commands

An unexpected power loss is one of the most common triggers for filesystem corruption in Linux environments. When an operating system shuts down abruptly,…

An unexpected power loss is one of the most common triggers for filesystem corruption in Linux environments. When an operating system shuts down abruptly, pending write operations may not complete, causing the kernel to mount affected partitions as read-only upon reboot to prevent further data corruption. For IT students and junior engineers, encountering a boot loop or a root shell prompt because of a Read-only file system error can be intimidating. However, understanding the mechanics behind this behavior and mastering the correct remount procedures is a fundamental troubleshooting skill. This guide provides a practical, step-by-step approach to diagnosing and resolving these errors safely, distinguishing between scenarios where the filesystem can be repaired live versus those requiring a full recovery environment.

Understanding the Root Cause: Why the System Mounts Read-Only

When Linux detects inconsistencies in its filesystem metadata—such as dirty bit flags set by incomplete writes or journal entries that don’t match the current state—it automatically remounts the partition as read-only. This is a protective mechanism designed to ensure data integrity. Attempting to write to a read-only filesystem will fail with Read-only file system errors, which can halt services, prevent updates, and stop application containers from starting.

It is crucial to understand that simply rebooting the machine often does not fix the issue if the underlying filesystem corruption persists. The system remains in a defensive state until the inconsistencies are resolved or the filesystem is explicitly remounted with write permissions after a successful check. Common triggers include sudden power cuts, kernel panics, or hardware failures like failing hard drives.

Immediate Recovery: Accessing the Emergency Shell

If your system fails to boot normally and drops you into an emergency shell (often indicated by a prompt like (init) #), you must manually remount the root filesystem to regain control. This is the most critical step in the recovery process.

  1. Identify the Filesystem Type: Determine if you are using ext4, xfs, or another type, as the commands and flags differ slightly. You can usually infer this from the error message or by checking /proc/filesystems.
  2. Remount Root with Read-Write Permissions: Execute the following command to remount the root partition:

    bash
    mount -o rw,remount /

    • mount: The utility used to attach filesystems.
    • -o rw,remount: Options specifying read-write (rw) access and that the filesystem is already mounted (remount).
    • /: The root directory path.

    Expected Output: If successful, you will receive no output, or a message confirming the remount. If the command fails, it usually indicates severe corruption requiring a full filesystem check.

Performing a Filesystem Check (fsck) on ext4 Systems

Once the root filesystem is writable, the next step is to repair any detected inconsistencies. For ext2, ext3, and ext4 filesystems, the standard tool is e2fsck. It is vital to run this check when the filesystem is not mounted as read-write or while in single-user mode; however, since we just remounted root, we can proceed cautiously.

Run the following command to scan and repair errors:

e2fsck -y /dev/sda1
  • -y: Automatically answer “yes” to all prompts regarding inode usage and block allocation. This is essential in an emergency shell where you cannot interactively confirm fixes.
  • /dev/sda1: Replace this with your actual root device identifier (e.g., /dev/nvme0n1p2). You can find the correct device using lsblk or fdisk -l.

Illustrative Output:

e2fsck 1.47.0 (5-Feb-2023)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
...
3943 blocks in filesystem, 456 free (2% fragmentation).
Filesystem was modified.

Note: Do not run fsck on a mounted root partition unless you have remounted it as read-write first, though some versions of e2fsck handle this gracefully. If the check reports “clean,” no repair is needed, but the read-only flag may still require a reboot to clear.

Handling XFS Filesystems and Special Cases

If your system uses the XFS filesystem (common in modern enterprise distributions like RHEL 8/9 or CentOS Stream), the procedure differs slightly. XFS does not support online defragmentation or certain types of repair while mounted, and its recovery tools are more restrictive.

To remount an XFS root partition:

mount -o remount,rw /dev/mapper/root

Note: The device path may vary depending on your LVM setup.

If inconsistencies exist, you generally must boot into a rescue mode or live USB environment to run xfs_repair. Running xfs_repair on a mounted filesystem is dangerous and can lead to data loss. In an emergency shell, if xfs_repair is unavailable, the safest immediate action is often to reboot, which may allow XFS to complete its internal journaling process cleanly.

Verifying the Fix and Restoring Services

After running the repair commands, you must verify that the filesystem is no longer read-only and that your system can boot normally.

  1. Check Mount Options: Run mount | grep / to ensure the root directory is mounted with rw (read-write) rather than ro.
  2. Reboot the System: Execute reboot or press Ctrl+Alt+Del. A reboot clears the emergency state and allows the init system to start normally.

Verification Steps Post-Reboot:
* Check system logs: journalctl -b -1 | grep -i error (previous boot) vs journalctl -p 3 --since "5 minutes ago" (current boot).
* Ensure services are running: systemctl list-units --state=failed.
* Test disk health: Run smartctl -a /dev/sda to check for hardware errors that might have caused the power loss or corruption.

Common Mistakes and Safety Precautions

When troubleshooting read-only filesystems, several pitfalls can turn a simple recovery into a data loss disaster.

  • Running fsck on a Live Root: Never run fsck on a root partition while the system is running normal services without remounting it first. While modern kernels are careful, forcing repairs on active filesystems is risky.
  • Ignoring Hardware Errors: A read-only mount might be a symptom of a failing drive rather than software corruption. Always check SMART data before assuming a software fix will work permanently.
  • Assuming “Clean” Means Safe: If e2fsck reports the filesystem is clean but it remains read-only, there may be a configuration issue in /etc/fstab or a hardware controller enforcing read-only mode. Check dmesg for I/O errors.
  • Deleting Logs Prematurely: After repair, do not immediately delete log files to “clean up.” Review them first to understand why the power loss occurred (e.g., did the UPS fail?).

Student Practice Task: Simulating a Power Failure

To solidify these skills, IT students should practice in a safe lab environment using virtual machines.

Task:
1. Start a fresh Ubuntu or Debian VM.
2. Unmount a test partition (e.g., /home): sudo umount /home.
3. Remount it as read-only: sudo mount -o remount,ro /home.
4. Attempt to write a file: echo "test" > /home/test.txt. Verify the error.
5. Remount as read-write: sudo mount -o remount,rw /home.
6. Write the file again and verify success.
7. Simulate corruption by creating an inode issue (advanced) or simply rebooting with fsck enabled in GRUB to see the recovery menu.

This hands-on approach builds muscle memory for emergency procedures without risking production data. By mastering these commands, engineers can minimize downtime and protect critical infrastructure against the inevitable hardware hiccups of daily operation.

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.