8

I'm curious about the file or symlink /etc/mtab. I believe this is a legacy mechanism. On every modern linux I've used this is a symbolic link to /proc/mounts and if mtab were to be a regular file on a "normal" file system /etc there would be challenges in making software work with mount namespaces.

For a long time I'd presumed that one of two things were true. Either:

  • We're waiting for software referencing /etc/mtab to age out or be updated
  • Other non-linux OS still use the same file name and the link is there for cross platform compliance

However both of these seem shaky ideas. I can't find good reference to any modern OS keeping the same file name outside Linux. And it seems to have lived for much too long to be simply a backward compatibility issue; far more significant changes seem to have come and gone in that same time.

So I'm left wondering if /etc/mtab is really just there for historic reasons. Is it in any way officially deprecated? Is there any solid modern reason [as of 2023] to keep it?

I don't want to delete it from my system, but as a software developer I'd like to understand its usefulness and whether to avoid it.

  • Inevitably someone has voted this is "opinion based" you'll note I'm looking for an official position not just your personal opinion. – Philip Couling Apr 16 '23 at 09:47
  • As a software developer, what would you use it for? What's the issue it poses to you? – Kusalananda Apr 16 '23 at 09:48
  • @Kusalananda you might interpret this whole question as exactly that. I don't know. I'm curious what would you still use it for and would those uses now be depreciated. – Philip Couling Apr 16 '23 at 09:50
  • 2
    As far as other Unix-style systems are concerned, see this answer — basically, as you suggest, /etc/mtab isn’t relevant there. In any case the Linux /etc/mtab isn’t even compatible with old Unix-style mtab. – Stephen Kitt Apr 16 '23 at 10:40
  • 1
    man mount classic /etc/mtab is completely disabled at compile time by default, man umount deprecated /etc/mtab, systemd NEWS Any reference to /etc/mtab has been dropped from systemd. The file has been obsolete since a while. However I get >200 results just grepping for etc/mtab in my usr/lib and usr/bin. So it'll be around for quite a while, I suppose. It's still the same file format and other than kernel taking over, not much else changed... – frostschutz Apr 16 '23 at 10:42
  • 1
    @Philip see https://man7.org/linux/man-pages/man8/mount.8.html#DESCRIPTION and https://man7.org/linux/man-pages/man8/umount.8.html#OPTIONS for mount and umount. – Stephen Kitt Apr 16 '23 at 11:29
  • @PhilipCouling I'm willing to say "c'mon, that's work you can do yourself!": That man page comes from upstream, and a bit of git log -S "The support for regular classic" later, we see that commit b6cc121043854e1048d020bc1d73d932df89eb4b documented the deprecation in 2018. (not saying it, instead instead showing off how you can find such info yourself) – Marcus Müller Apr 16 '23 at 11:32
  • @MarcusMüller it's not lazyness. I always ask those citing references to post something a little more tangible than a man command because they suffer many of the same problems as posting links to google searches namely they age out and different people get different results. – Philip Couling Apr 16 '23 at 11:56
  • 1
    2016 mailing list discussion kill mtab - lore.kernel.org btw, mount(8) supports /etc/mtab -> /proc/mounts symlink for 20 years... :-) – frostschutz Apr 16 '23 at 12:20

2 Answers2

8

Should the use of /etc/mtab now be considered deprecated?

Depends on who you ask. If you ask the authors of mount on Linux, yes; since 2018 it says

… is completely disabled in compile time by default, because on current Linux systems it is better …

I think that's pretty strong a statement. Prior to that, /etc/mtab was "also supported", but it was considered better to not use it:

This real mtab file is still supported, but on current Linux systems it is better to make it a symlink to…

That sentence was there since 2014. Before that, it was only recommended:

The mtab file is still supported, but it's recommended to use a symlink to …

In other words, yeah. This has been deprecated for nearly a decade. You shouldn't rely on it. Ignore.

The source of truth is /proc/mounts, if anything. (Listing mounts correctly, uniquely and unambigously gets a logically non-trivial problem considering Linux mount namespaces exist)

  • 2
    Showing that timeline is really helpful in understanding it's current status and understanding why it is still around despite its apparent age. 2019 is more recent than I'd imagined when I wrote the question. Thanks! – Philip Couling Apr 16 '23 at 12:50
  • @PhilipCouling absolutely had the same feeling! – Marcus Müller Apr 16 '23 at 12:50
  • Yeah it should be a symlink, because the real mtab is better located on /run. I've had periodic issues with it being /proc/mounts. Sometimes /proc/mounts really is wrong. (Don't think you have this issue? You probably don't. systemd has some unfixed multipath bugs that only show up in edge cases.) The reason /proc/mounts can be wrong is it has the device path from when it was mounted, which isn't the on-disk device path when it was initially mounted from initrd. – Joshua Apr 16 '23 at 20:23
  • 1
    @Joshua Interesting point about devices changing name and invalidating /proc/mounts. On balance /proc/mounts seems safer for much modern software because it safely tracks through namespaces and chroot. IE if it's not generated by the kernel there's a high risk it's wrong. But then I guess that creates a problem because the kernel is largely unaware of which device file its mounted. It understands device numbers instead – Philip Couling Apr 16 '23 at 22:15
2

I was going to add this as a comment but a better utility than /etc/mtab, which is deprecated, and even /proc/mounts, which is supported and useful, is

findmnt

It is not always there by default depending on the distro but is almost always in the repos. It gives the same information as /etc/mtab and /proc/mounts and has switches to parse the data and print out only what is needed or wanted or to just render it more legible. These can be found via its man page.

Nasir Riley
  • 11,422