Why Does the Linux Filesystem Go into Read-Only Mode and How to Resolve It in Various Versions (Ubuntu, RHEL)?

ANGADSINGH OBBIANGADSINGH OBBI
4 min read

Introduction

Linux filesystems can switch to read-only mode due to various reasons, impacting the system's ability to write data and potentially causing service disruptions. Understanding the underlying causes and knowing how to address them in different Linux distributions like Ubuntu and Red Hat Enterprise Linux (RHEL) is essential for maintaining system integrity and performance.

Common Causes for Read-Only Filesystem Mode:

  1. Filesystem Corruption:

    • Errors or inconsistencies in the filesystem can occur due to improper shutdowns, software bugs, or physical damage to the storage medium.

    • The system may mount the filesystem as read-only to prevent further corruption.

  2. Hardware Issues:

    • Bad sectors, failing disks, or malfunctioning storage controllers can trigger read-only mode.

    • Disk failures can cause I/O errors, prompting the system to protect the filesystem by making it read-only.

  3. Power Failures:

    • Unexpected power loss can leave the filesystem in an inconsistent state.

    • On reboot, the filesystem might be mounted as read-only to allow for a manual check and repair.

  4. Mounting Errors:

    • Incorrect mounting options or issues during the mounting process can lead to a read-only filesystem.

    • For example, using the -o remount,ro option explicitly mounts the filesystem as read-only.

  5. Kernel Bugs:

    • Although rare, bugs in the Linux kernel can cause the filesystem to become read-only.

    • This can happen due to issues in the filesystem drivers or related kernel subsystems.

Resolving Read-Only Filesystem Issues

For Ubuntu
  1. Check and Repair the Filesystem (Usingfsck):

    • Boot into a live session or recovery mode:

      • Reboot the system and select "Advanced options for Ubuntu" from the GRUB menu.

      • Choose "Recovery mode" and then "Drop to root shell prompt".

    • Identify the affected partition (e.g., /dev/sda1):sudo fdisk -l

        sudo fdisk -l
      
    • Unmount the partition if it is mounted:

        sudo umount /dev/sda1
      
    • Run fsck on the partition:

        sudo fsck -y /dev/sda1
      
      • The -y option automatically answers "yes" to prompts.
    • Reboot the system:

        reboot
      
  2. Remount the Filesystem:

    • Identify the affected mount point (e.g., /mnt/data):

        df -h
      
    • Remount the filesystem:

        mount -o remount,rw /mnt/data
      
For RHEL
  1. Check and Repair the Filesystem (Usingxfs_repair for XFS):

    • Boot into rescue mode or use a live CD/ISO:

      • Insert the RHEL installation media and boot from it.

      • Select "Troubleshooting" and then "Rescue a Red Hat Enterprise Linux system".

    • Identify the affected partition (e.g., /dev/sda1):

        fdisk -l
      
    • For XFS filesystems, run xfs_repair:

        sudo xfs_repair /dev/sda1
      
    • For other filesystems, use fsck:

        sudo fsck -y /dev/sda1
      
    • Reboot the system:

        sudo reboot
      
  2. Remount the Filesystem:

    • Identify the affected mount point (e.g., /mnt/data):

        df -h
      
    • Remount the filesystem:

        sudo mount -o remount,rw /mnt/data
      

Preventative Measures

  1. Regular Backups:

    • Ensure regular backups of important data to mitigate the impact of filesystem issues.

    • Use tools like rsync, tar, or backup solutions such as Bacula or Amanda.

  2. Filesystem Monitoring:

    • Use monitoring tools like iostat, iotop, or nagios to track filesystem health and performance.

    • Set up alerts for I/O errors or abnormal disk activity.

  3. Stable Power Supply:

    • Use an uninterruptible power supply (UPS) to protect against power failures.

    • Ensure proper shutdown procedures are followed during power outages.

  4. Regular Maintenance:

    • Periodically check and repair filesystems using fsck or xfs_repair.

    • Schedule maintenance windows to perform these checks without impacting system availability.

  5. Update Kernel and Drivers:

    • Keep the Linux kernel and storage drivers up to date to benefit from bug fixes and performance improvements.

    • Regularly check for updates and apply them as part of system maintenance.

Conclusion

Understanding why a Linux filesystem goes into read-only mode and knowing how to resolve it can significantly reduce downtime and data loss. By following the detailed steps outlined for Ubuntu and RHEL, system administrators can effectively troubleshoot and fix read-only filesystem issues. Regular maintenance and monitoring are crucial in preventing these problems and ensuring the system runs smoothly.

0
Subscribe to my newsletter

Read articles from ANGADSINGH OBBI directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

ANGADSINGH OBBI
ANGADSINGH OBBI