Solutions to the "Read-only File System" Error in Linux System File Operations

24-01-2024 02:21:13

When performing routine maintenance on Linux cloud servers, improper shutdowns can lead to file system errors on the disk, preventing file operations and resulting in a "Read-only file system" error, as shown in the image below. In such cases, there's no need to panic. By following the steps outlined in this article, you can remove the read-only state and restore the system to normal operation.

Note: This fix may lead to the loss of some files and data. It is advised to back up important files before proceeding. The specific repair steps are as follows:

1.Check Mounted Partitions

Use the mount command to view currently mounted partitions.

[root@localhost ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,relatime)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=388136k,mode=700)
/dev/vdb1 on /home type ext4 (ro,relatime,data=ordered)

If a partition is marked with "ro," it indicates that the partition is in a read-only state. It's also advisable to check the /etc/fstab file to confirm the partition configuration.

2.Unmount Read-only Partition

Use the umount command to unmount the partition in read-only state.

[root@localhost ~]#umount /dev/vdb1

If you encounter a "device is busy" message, identify the process causing the busy state. For example, execute commands like /etc/init.d/httpd stop to stop certain running services. The command fuser -m /home will display the PID using this module, and fuser -mk /home will directly terminate that PID.

3.Repair Disk Files

Use the fsck command to repair the abnormal disk partition.

[root@localhost ~]#fsck -fvy /home 

4.Remount the Partition

After successful repair, use the remount or mount -a command to remount the partition.

[root@localhost ~]# mount -o rw,remount /home

5.Restart Services

Finally, restart the services that were stopped earlier with /etc/init.d/httpd start, or execute the reboot command to restart the server, allowing the system to automatically start running services.