{"id":100,"date":"2009-01-19T13:14:35","date_gmt":"2009-01-19T10:14:35","guid":{"rendered":"http:\/\/www.held.org.il\/blog\/?p=100"},"modified":"2009-01-19T13:14:35","modified_gmt":"2009-01-19T10:14:35","slug":"etcmtab-weirdness","status":"publish","type":"post","link":"http:\/\/www.held.org.il\/blog\/2009\/01\/etcmtab-weirdness\/","title":{"rendered":"\/etc\/mtab weirdness"},"content":{"rendered":"<p>There are many ways to fetch the list of currently-mounted-devices: read the files <em>\/etc\/mtab<\/em>, <em>\/proc\/mounts<\/em>, or exec <em>\/bin\/mount<\/em>, <em>\/bin\/df<\/em>.<\/p>\n<p>I've been arguing with a colleague (Yaniv), that relying on <em>\/etc\/mtab<\/em> is no much worse than relying on <em>\/proc\/mounts<\/em>. But after we inspected it on Linux &amp; Solaris (<em>\/etc\/mnttab<\/em>), I figured out that I was pretty wrong, and learned some new surprising facts:<\/p>\n<p><strong>On Linux:<\/strong><\/p>\n<ul>\n<li><em>\/proc\/mounts<\/em> is a read-only, kernel-generated file.<\/li>\n<li><em>\/etc\/mtab<\/em> (Linux) is a <strong>regular file<\/strong>. It's kept up-to-date because the <em>mount\/umount<\/em> commands modify it. It can be modified by a root user, moved and even deleted!<\/li>\n<li><em>df<\/em> command is using <em>\/etc\/mtab<\/em>, thus after rm'ing <em>\/etc\/mtab<\/em>, <em>df<\/em> would stop functioning.<\/li>\n<li><em>mount<\/em> command doesn't care about <em>\/etc\/mtab, <\/em>probably uses <em>\/proc\/mounts<\/em> or some internal kernel structure.<\/li>\n<\/ul>\n<p><strong>On Solaris (prepare for some weird stuff now):<\/strong><\/p>\n<ul>\n<li>Solaris has got <em>\/etc\/mnttab<\/em>, but no <em>\/proc\/mounts<\/em> equivalent.<\/li>\n<li><em>\/etc\/mnttab<\/em> is a <strong>mounted filesystem<\/strong>, of the <em>mntfs<\/em> type. So it's somewhat similar to <em>\/proc\/mounts<\/em> on Linux. It cannot be modified.<\/li>\n<li><em>\/etc\/mnttab<\/em> is actually <strong>a directory!<\/strong> (a mount point has to be a directory..)<em><\/em><\/li>\n<li>\/etc\/mnttab<strong> can<\/strong> be unmounted, renamed, rmdir'd (when unmounted) and mounted anywhere else.<\/li>\n<li>both <em>df<\/em> and <em>mount<\/em> rely on <em>\/etc\/mnttab<\/em>, thus not functioning when it's absent<\/li>\n<\/ul>\n<p><strong>On HP-UX:<\/strong><\/p>\n<ul>\n<li><em>\/etc\/mnttab<\/em>, which is a regular file, is similar to <em>\/etc\/mtab<\/em> on Linux.<\/li>\n<\/ul>\n<hr \/>\n<p>And on another, non-related subject: looks like Debian Lenny has got <a href=\"http:\/\/bts.turmzimmer.net\/details.php?bydist=lenny\">only 80 bugs<\/a> to go (as of 19\/01\/09)! Go Lenny!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are many ways to fetch the list of currently-mounted-devices: read the files \/etc\/mtab, \/proc\/mounts, or exec \/bin\/mount, \/bin\/df. I&#8217;ve been arguing with a colleague (Yaniv), that relying on \/etc\/mtab is no much worse than relying on \/proc\/mounts. But after we inspected it on Linux &amp; Solaris (\/etc\/mnttab), I figured out that I was pretty [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[75,1],"tags":[203,121],"_links":{"self":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/posts\/100"}],"collection":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/comments?post=100"}],"version-history":[{"count":0,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/posts\/100\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/media?parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/categories?post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.held.org.il\/blog\/wp-json\/wp\/v2\/tags?post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}