Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I check a bunch of systems to find any filesystem that are mounted read-only? Possibly via a script?

share|improve this question
2  
What systems? What issue? –  Ignacio Vazquez-Abrams Oct 12 '11 at 7:09
    
Your Question is not clear. Please rephrase it. –  SHW Oct 12 '11 at 7:13
    
They are RHEL4 and RHEL5 systems. The filesystem (eg /var, /tmp , /) are mounted as read only. I want to find/list which sytems have such read only issue. –  user11496 Oct 12 '11 at 7:38
add comment

5 Answers 5

Just look for the ro mount option.

share|improve this answer
2  
That miscatches any line with "ro" in it, including anything with the "errors=remount-ro" option. –  Teddy Oct 12 '11 at 8:16
    
So then use a more sophisticated regex. –  Ignacio Vazquez-Abrams Oct 12 '11 at 8:19
add comment
awk '$4~/(^|,)ro($|,)/' /proc/mounts
share|improve this answer
    
I understand the awk, but not the 'nosuid' part. Can you please explain a bit more? –  user11496 Oct 12 '11 at 9:30
    
@user11496: I meant "ro" - I mis-pasted my test code. I fixed my answer. –  Teddy Oct 12 '11 at 11:45
add comment

I've used the following in the past

grep ' ro ' /proc/mounts

In some instances you may want to skip any remote mounts which may be RO by design

grep ' ro ' /proc/mounts | grep -v ':'

You also may want to skip things that are mounted via automount

grep ' ro ' /proc/mounts | egrep -v 'automount|autofs'
share|improve this answer
add comment

If you intent is to find filesystems with problems (i.e. the mounting status has been changed to READ-ONLY due to a filesystem error), then I'd do the following (assumming ext* filesystems):

 tune2fs -e panic [raw-disk-partition-name]

EX:

 tune2fs -e panic /dev/sda1

What this does is panic the system, thus rebooting the server, possibly invoking a fsck on the problem filesystem to fix it. Thus a serious filesystem problem is handled by having the system fix it automatically, instead of dumping it into Read-ONLY mode which I have not found very helpful. Besides I'd rather panic a problem filesystem, fixing it than attempting to run with it damaged which as time goes on might cause more damage.

share|improve this answer
add comment

An approach that works even for remote file systems (which can be mounted rw even if they're exported ro, resulting in a read only file system) is to simply create a test file on each file system and test the return code of that command.

But if this is something that happens regularly you need to look into the cause rather than trying to keep up fixing the symptoms.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.