How to Check and Troubleshoot Read-Only File Systems in Linux
How to Check and Troubleshoot Read-Only File Systems in Linux
How to Check for a Read-Only File System in Linux
Hi,
A Linux filesystem can sometimes become mounted in read-only (ro) mode due to disk errors, filesystem corruption, storage issues, or administrative configuration changes. When a filesystem is mounted as read-only, users cannot create, modify, or delete files within that mount point.
Common Symptoms of a Read-Only File System
You may notice the following behaviors:
Unable to create new files using the
touchcommand.Unable to edit existing files.
File deletion operations fail.
Applications report "Read-only file system" errors.
Log files stop updating.
Example Error
touch testfile
touch: cannot touch 'testfile': Read-only file system
Method 1: Check Mounted File Systems Using the mount Command
The simplest way to identify a read-only filesystem is to inspect the mount options.
mount
Example Output
/dev/sda1 on /data type ext4 (ro,relatime)
If the mount options contain ro, the filesystem is mounted as read-only.
You can filter the output as follows:
mount | grep "(ro,"
This displays only filesystems currently mounted in read-only mode.
Method 2: Check Using the findmnt Command
findmnt -o TARGET,SOURCE,FSTYPE,OPTIONS
Example:
findmnt | grep " ro,"
This provides a cleaner view of mount options and filesystem status.
Method 3: Test File Creation
Attempt to create a temporary file in the target filesystem.
cd /mountpoint
touch testfile
If the filesystem is read-only, Linux returns:
touch: cannot touch 'testfile': Read-only file system
Automated Check Using a Shell Script
The following script attempts to create a temporary file on each mounted filesystem and reports whether the operation succeeds.
#!/bin/ksh
df -P | awk 'NR>1 {print $6}' > /tmp/mountpoints.lst
for mp in $(cat /tmp/mountpoints.lst)
do
echo "Checking: $mp"
touch "$mp/test_rw_$$" 2>/dev/null
if [ $? -eq 0 ]
then
echo "Writable"
rm -f "$mp/test_rw_$$"
else
echo "Read-Only or Permission Denied"
fi
echo "--------------------------------"
done
Sample Output
Checking: /
Writable
--------------------------------
Checking: /data
Read-Only or Permission Denied
--------------------------------
Method 4: Check Kernel Messages
Linux often logs filesystem-related issues in system logs.
dmesg | grep -i "read-only"
or
dmesg | grep -i ext4
Example output:
EXT4-fs error detected
Remounting filesystem read-only
This indicates that Linux automatically remounted the filesystem in read-only mode after detecting corruption or I/O errors.
Common Causes of Read-Only Filesystems
Filesystem corruption
Disk I/O errors
Storage device failures
Unexpected server shutdowns
Incorrect mount configuration in
/etc/fstabSAN or network storage issues
Remount a Filesystem as Read-Write
If the issue has been resolved and the filesystem supports it, remount it as read-write:
mount -o remount,rw /mountpoint
Example:
mount -o remount,rw /data
Note: If the filesystem was remounted as read-only because of corruption, run the appropriate filesystem repair utility (such as fsck) before switching it back to read-write mode.
Conclusion
Read-only filesystems are often a warning sign of underlying storage or filesystem issues. Commands such as mount, findmnt, and touch can quickly help identify affected mount points. For enterprise environments, automated scripts can be used to regularly verify filesystem accessibility and detect problems before they impact applications.