cancel
Showing results for 
Search instead for 
Did you mean: 
HerveQ
Flight Engineer Flight Engineer
Flight Engineer
  • 18.7K Views

Automounting using systemd

Do you know that systemd provides its own automount feature?
It is as simple as declaring your file system in /etc/fstab and adding the x-systemd.automount mount option:

[root@demo ~]# vi /etc/fstab
...
nfs.example.com:/exports/docs  /documents  nfs  x-systemd.automount  0  0
[root@demo ~]# mkdir /documents
[root@demo ~]# reboot # or systemctl daemon-reload && systemctl start documents.automount


That's it. No need to install the autofs package, updating the /etc/auto.master file, or starting an extra service.

You can also add the x-systemd.idle-timeout option for systemd to unmount the file system when idle, and any other mount options the file system requires:

nfs.example.com:/exports/docs /documents nfs x-systemd.automount,x-systemd.idle-timeout=2min,rw,sync 0 0

See systemd.automount(5) and systemd.mount(5) man pages.

Labels (2)
4 Replies
Razique
Flight Engineer Flight Engineer
Flight Engineer
  • 18.7K Views

This is pretty cool. I did not know about that. What are the benefits of using systemd automount feature?

0 Kudos
m2
Cadet
Cadet
  • 17.7K Views

Does anyone know if the use of this setting conflicts with the normal legacy automounter?  Is it like chrony and ntp where you need to choose one or the other but not both?  I have not seen this in practice, only the old school methods. 

0 Kudos
Tracy_Baker
Starfighter Starfighter
Starfighter
  • 17.7K Views

That's pretty nifty.

This would beat the heck out of teaching autofs to students. The concepts of master map, indirect map, and direct map files is a big issue with new-to-autofs students.

(As it is a section in RH134, autofs will still be taught to my students)

I wonder what kind of automount it is: is it equivalent to a direct mount (the mount point must exist and the mounted directories exist upon entering the mount point) or an indirect mount (the mount point is created on demand and the mounted directories are only mounted when accessed)?

Gotta play around with this :)

Program Lead at Arizona's first Red Hat Academy, est. 2005
Estrella Mountain Community College
Tiz_ITDM
Cadet
Cadet
  • 15.6K Views

This is awesome and elegant, thank you. I don't know why it is not in RHCSA course material.

One thing I've noticed is that you can't "man -K x-systemd.automount" because of several formatting tags in the man page where it is located: systemd.mount(5)

Basically this sucks.

Found only in vdo(1M)

root@tizrh man5]# man -wK x-systemd
/usr/share/man/man8/vdo.8.gz

[root@tizrh man5]# zgrep x-systemd /usr/share/man/man8/vdo.8.gz
\fBx-systemd.requires=vdo.service\fP
/dev/mapper/vdo0 /vdo xfs defaults,x-systemd.requires=vdo.service 0 0

But present in systemd.mount(5)

[root@tizrh man5]# zgrep systemd /usr/share/man/man5/systemd.mount.5.gz |grep x | grep automount
"x\-systemd\&.automount"
\fBx\-systemd\&.automount\fR
\fBx\-systemd\&.automount\fR

I know there some fancy escape for the grep to use (and for man -K?), but I would expect to get results also for systemd.mount.

0 Kudos
Join the discussion
You must log in to join this conversation.