Xymon Mailing List Archive search

Detecting read-only file system in Linux

list Sebastian Auriol
Wed, 11 Mar 2015 12:57:14 -0000
Message-Id: <!&!AAAAAAAAAAAuAAAAAAAAAL60wriLM9cRsTVojW0AAAABAFEdQVQs6tMRsLEAoMxarIMAAAABk2cAABAAAADR/Bdu5OdnS58QAuMyWJrSAQAAAAA=@syntec.co.uk>

From: Xymon [mailto:xymon-bounces at xymon.com] On Behalf Of Thomas Eckert
Sent: 11 March 2015 07:42
Subject: Re: [Xymon] Detecting read-only file system in Linux
On 11 Mar 2015, at 00:58, Jeremy Laidman <user-71895fb2e44c@xymon.invalid> wrote:
On 11 March 2015 at 00:44, Thomas Eckert <user-2a86d6cd6326@xymon.invalid>
wrote:
Just for future reference as you already found your solution:


From looking at the util-linux package I understand that _if_ the
/proc-filesystem is mounted the information is used from there.

I don't think this is the case.  Running "strace" on the "mount" command
shows that it first looks at /etc/mtab, and if that exists, it doesn't look
at /proc/mounts.  Only if /etc/mtab doesn't exist, does mount look at
/proc/mounts.
Strange, I did also check with strace and did not see `/etc/mtab` used.
This is on Debian 7.x, Debian kernel 3.2.0-4-amd64 and util-linux 2.20.1-5.3
root at bb:~# strace -e trace=open mount 2>&1 | egrep 'mtab|proc'
open("/proc/filesystems", O_RDONLY)     = 3
open("/proc/self/mountinfo", O_RDONLY)  = 3
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
So in a situation where the filesystem containing /etc is having
problems and goes read-only, /etc/mtab won't get updated because it's now
read-only.
Agreed.
So re-using the `mount`-info for the r/o-check is at least highly
dependent on the individual environment and versions.
Cheers
Thomas

Thanks Jeremy, Thomas and Ben for your input.  I have just run your command
Thomas on a couple of our servers:
 
strace -e trace=open mount 2>&1 | egrep 'mtab|proc'
 
The old xymon server looks at /etc/mtab:
 
open("/etc/mtab", O_RDONLY|O_LARGEFILE) = 3
none on /proc type proc (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

But the newer server running xymon-client that had the disk that went
read-only:
 
open("/proc/mounts", O_RDONLY)          = 3
open("/etc/mtab", O_RDONLY)             = 3
proc on /proc type proc (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

Both servers are runing a 2.6.x kernel, but the new server has a kernel
released last month.  So, it does indeed appear to be highly dependent on
the version.  However, it looks like it will work on probably just about all
of servers except for our xymon server, so that's pretty good.

Kind regards, 

SebA