AutoFS has been around for a long time.
Now, there's this new thing called systemd,
and systemd has auto mount units.
And these auto mount units can be used with mount units
to mount a file system only when the mount directory is accessed.
And that's exactly what AutoFS is doing.
So why are we still using AutoFS?
Well, for one important reason, systemd auto mount
does not offer wildcard mounts.
To configure a systemd auto mount,
you create mydir.auto mount, where mydir is the mount point,
and you create it for the matching mydir.mount unit.
And while using auto mount, you should enable the auto mount
and not the mount unit, because if you enable the mount unit,
then it will always be there.
If you want to see what that looks like,
you can check the nfsdata.mount and the nfsdata.auto mount
in the course git repository at github.com slash
sandervanvugt slash rhcsa10 for an example.
Let me show you.
So do we already have the course git repository?
I don't see it, so let me use a git clone,
https://github.com slash sandervanvugt slash rhcsa10.
Next, I get in the rhcsa10 directory,
and there we have nfsdata.mount and nfsdata.auto mount.
Well, assuming that this is what I want to use,
ooh, nfsdata.mount and nfsdata.auto mount, hang on,
because we just created nfsdata in AutoFS.
So I do need to make sure that it is removed
from etc.auto.master.
There we go, deleting it.
And next, let me also use mount and manually
unmount this nfsdata.
No, that doesn't seem to be necessary.
So I do need systemctl restart autofs
to make sure that AutoFS reads its new configuration.
And now I can copy nfsd star to etc systemd system,
which is where your own unit should be ending up,
and systemctl daemon reload, because I just
wrote files to a directory.
And then we check out these unit files.
So we have nfsdata.mount.
And what do we see in nfsdata.mount?
Well, we see a WOT, and the WOT is 127.0.0.1.
Now, let's do that for real.
Let's use the share that we just created, nfsserver colon
slash nfsdata.
And that is going to be mounted on nfsdata,
and the type is nfsdata.
And the type is nfs.
So that is looking good, but I'm not going to activate this.
I'm going to activate the nfsdata.automount.
So automount is aware, so the where is nfsdata.
We even have a timeout idle second
to make sure that after some inactivity,
the mount will disappear as well.
Let's make that 30 seconds.
10 seconds is a little bit tight.
Here we have the install section,
and we don't have anything else.
They match on a first-name basis.
So nfsdata.automount automatically
knows that it is meant to be used for nfsdata.mount.
So systemctl enable minus minus now nfsdata.automount.
And then I'm using systemctl status on nfsdata.mount.
And you can see it's inactive, but you can also
see it as this triggered by option.
It's triggered by nfsdata.automount.
So if I get into nfsdata and I do my systemctl status again,
we can see that suddenly it is mounted.
And that is how you use automount in systemd.
I'd say for the exam, if this is a task on the exam,
read your task carefully and decide
if you are going to do it with systemd or with AutoFS.