Sudo Error: Read-only File System

Published by Torry Crass on

So, a new fun problem.  You log into a computer, attempt to sudo into a priveleged account and wind up with the following:

[user@server ~]$ sudo su -
sudo: Can't open /var/run/sudo/user/0: Read-only file system
[user@server ~]$

Naturally, this doesn't look good.  The first thing you should do is run df -i and df -h to make sure you're not out of inodes or space.  While the error doesn't indicate that to be the problem, it can't hurt to be sure.  Assuming these come back fine, you need to log into root by doing a straight su – root command.

Once logged into root, give creation of a test file on the /var partition a whirl by something similiar to the command below.

[root@server var]# touch test
touch: cannot touch `test': Read-only file system

Well, this is no good.  But there is light at the end of the tunnel.  This problem is not uncommon with VMWare virtual machines.  While it doesn't happen very often, it can and does happen as this error demonstrates.  You should be able to resolve the problem by either a reboot or by issuing the following command:

WARNING: This information is provided with the assumption that you have a general understanding of Linux, file systems, troubleshooting and utilities related to this.  If you do not, you SHOULD NOT perform this task, just reboot.  Following the task below could cause system instability, crashing and data loss.  Use at your own risk!

IMPORTANT NOTE: This makes the assumption that you have separate / and /var partitions, if you do not, then you have to remount the / partition.  Validate this information by using filesystem tools like fdisk
IMPORTANT NOTE: You MUST replace /dev/hda1 with your valid disk corresponding to the /var partition.

[root@server /]# mount -o remount,rw /var

If you receive the following error:

block device /dev/sda3 is write-protected, mounting read-only

Your efforts to do this without a reboot are moot.  You will need to reboot the server and will most likely be prompted to fsck the partition due to file system errors which could be why the partition went into read-only in the first place.  Please seek additional documentation on the fsck process if you're not familiar with it already.

1 Comment

sixthfore · August 24, 2012 at 1:46 am

Thanks so much for writing this article! Been on a huge chase for this thing I'm working on and this one, super-clear and concise article is such a treat!

Leave a Reply