Solution for a Linux system becoming read-only and showing the "Read-only file system" prompt.

Published: 2019-09-20

Problem description: linux system becomes read-only, and the prompt Read-only file system appears, as shown in the figure: 

image.png

Cause: The system did not shut down normally, causing a file system error on the virtual disk.

Note: This repair may cause individual files and data loss. Before repairing, it is recommended to back up files first.


Solution: Use fsck to manually repair disk files. The specific operations are as follows:

 

1. Use mount to check the disk mount status 

mount:   Used to check which module is mounted read-only; generally displayed as:


[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)

[root@localhost ~]#


Check the partitions mounted with ro. If ro is found, it indicates that this disk is in read-only state (it is best to also check /etc/fstab to see whether the configuration file has already been set to read-only mount permission)


2. Unmount the read-only partition

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

If the prompt “device is busy” appears, find out which process is making it busy

For example, you can run commands such as /etc/init.d/httpd stop to stop some running services

fuser -m /home will display the pid using this module

fuser -mk /home will directly kill that pid

image.png


3. Use fsck to repair disk files

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

Repair the abnormal disk partition

image.png

Then mount it again.


4. Directly remount or use mount -a, the command is

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

Finally, start the services that were stopped initially with /etc/init.d/httpd start. You can also run reboot to restart the server and let the system automatically start the services that run.

image.png