The “Read-only file system …” is an error that is related to the file system. This error may occur in different situations for different reasons. This error simply expresses that the target file system is mounted as read-only mode and it can not be written or changed.
Read-only File System Error Cases
There may be different “read-only file system” error cases. Generally, they are not directly causing this error. The main reason is the file system is mounted as read-only for different reasons. Below we list some cases of this error.
While trying to restart apache2 web server you may get this error like below.
$ sudo service apache2 start
[sudo] password for username:
sudo: unable to open /var/lib/sudo/user: Read-only file system
* Starting web server apache2
List Mounted File Systems
First, we will list already mounted file systems. The mount command can be used to listed mounted file systems. The output may a bit long but just find the lines related to the root path and home path.
mount
Re-Mount File System
The first step to solving a read-only file system error is remounted file system. Because the file system may be mounted as read-only for different reasons which occur once in a time. So remounting file system will mount it in a normal state. Specified file systems located in the /etc/fstab configuration file can be remounted with the following command. This operation requires root privileges as expected.
sudo mount -o remount /
Reboot System
Another way to solve read-only file system error is rebooting the system. Rebooting the system make a fresh start where prevous error are cleared which may be related libraries, configuration, temporary changes etc.
sudo reboot
Check File System For Errors
Rebooting the system generally checks the file system for errors and if it is errors they are fixed. But in some cases, this may not work. We can explicitly check errors and fix them automatically by using the fsck command.
sudo fsck.ext4 -f /dev/sda2
Re-Mount File System In Read-Write
The file system is configured to be mounted as read-only by default. But these file systems can be also mounted as read and write. The rw option can be used to mount read and write.
sudo mount -oremount,rw /