mount -p

Latest response

On BSD/Solaris etc, mount -p prints a list of current mounts in fstab format. Very useful. This doesn't appear to work on Linux distributions (and HPUX).

Does anyone know a way to do this, or why it hasn't been upgraded to support it all these years? If not, I'll just have to write an equivalent but to save reinventing the wheel...

Thanks, Frank.

Responses

In all my years of administering Solaris, I don't recall ever using mount -p for anything. Out of curiosity, what's your use-case (that is, "what have I been missing all these years")?

I have to agree. I read this original post and couldn't come up with a use case where I wouldn't just cat /etc/fstab

Is it just so you can list mounts that have been manually configured and then use the output to add entries to fstab? Even that use case is something i'd do rarely.

Calling 'mount' with no arguments is pretty close, wouldn't take much to massage it into fstab format (although fstab will probably go away in the not too distant future!).

Interested in the response.

It's exactly so you can take the current manually created mounts and generate a fresh fstab to match. It may not figure much in Linux these days, where I see it being run as a guest OS under a hypervisor. But with a bigger system that's left up for years on end, with multiple drives and NFS connections, it's really handy. Unfortunately you have to filter it for ZFS legacy stuff now, of course.

However, in this instance I want to use it on a RHEL box to produce "consistent" output for processing by a script. fstab lines are easy to parse.

Interesting. I can honestly say I have never seen this requirement, but it may be down to difference in work practice/process.

With customer/clients i've worked for, if manually creating mounts, the agreed process is always

1. Create mount point
2. Create fstab entry
3. Mount from fstab entry by specifying _only_ mount point, not source, to ensure fstab entry works correctly  

Haven't had a customer for a while that doesn't manage this through version controlled config management though, so hand configuring mounts isn't something I really see anymore.

Yeah, as I mentioned - Linux seems to be run as small VMs under a hypervisor using tools to keep folks away from the command line as much as possible. It's a matter of style and Unix vs Linux philosophy.

That said, my actual problem with RHEL right now is getting parsable portable output from mount. Everyone seem to reckon "I don't want to do that", but has no one got the answer on the off-chance that I do?

I believe the Unix/Linux philosophy are very much the same, it's just management of servers is evolving over time.

That philosophical discussion aside, what about grabbing the output from mtab?

cat /etc/mtab

or go to the source:

cat /proc/mounts

Alternatively, you can use findmnt that lets you format the output on command line. findmnt is in the util-linux package:

https://access.redhat.com/downloads/content/rhel---7/x86_64/2456/util-linux/2.23.2-43.el7_4.2/x86_64/fd431d51/package

Thanks! I didn't actually know about /etc/mtab - last time I saw that was on Unix V7, so it never even occurred to me to look. I guess that explains why non-Linux systems have mount -p, to recreate it. It all makes sense now.

Odd that Linux should reach back so far for something like this, but I remember thinking it was a handy system at the time.

If you're using RHEL7, /etc/mtab is mostly a "compatibility" service. If your goal is to develop (portable) Linux habits, you're likely better off parsing /proc/mounts.

As to Pixel's prior comment about things changing over time, even Solaris is markedly different, these days. Much of what you used to be able to manage via SysV-ish text files are slowly being supplanted by config-registries. Solaris 10 was the initial foray into that with SMF. As SMF has extended its tentacles (and other configuration methods have been more-widely adopted), Solaris 11 became even more indirect in configuring things (having to use tools to make mods rather than editing no-longer extant legacy files). The last time I looked at Solaris 11, my impression was "looks like the plans for the next version of Solaris is to be a bunch of GUI/TUI tools for management." Solaris 11 really left the feeling that how they were changing management methods really wanted a GUI/TUI since hand-modding files was becoming kin of a non-starter and the indirect methods that were in Solaris 11 were a bit lacking.

As someone who spent the better part of a decade needing to be multi-OS (IRIX, UNICOS, Solaris, HP/UX, AIX) on a week-by-week basis, you got used to dealing with the deltas - large and small - between them. For example, HP/UX used to really piss me of having to use lanman to get the same types of outputs that every other operating system used to give me with ifconfig -a (and now that's gone in RHEL, too!)

Thanks for the tip. /dev/mounts is also a Linux thing AFAIK but it's good to know what's expected to stick around.

I know exactly what you mean about Solaris 11 - and I'm not a fan. FWIW I jumped ship to xBSD nearly 20 years ago, rather than Linux, giving Penguinistas two decades of peace without me. All this is about to change ;-)

And what is it with ifconfig? It's been there since the late 1980's - what was so wrong with it?

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.