The "auto" part in automount
does not refer to the boot process: automount
units define mount points that are mounted on-demand, i.e. only when they are accessed.
automount
units are optional; but, when they exist, corresponding mount
units must also exist. The former are meant to add functionalities to existing instances of the latter. From man systemd.mount
:
Optionally, a mount unit may be accompanied by an automount unit, to allow on-demand or parallelized mounting.
And, from man systemd.automount
:
For each automount unit file a matching mount unit file (see systemd.mount(5) for details) must exist which is activated when the automount path is accessed. Example: if an automount unit home-lennart.automount
is active and the user accesses /home/lennart
the mount unit home-lennart.mount
will be activated.
A typical use case for automount
units is mounting file systems (e.g. on remote or removable or encrypted media) that are not required during the boot process and may slow it down, or that may be unavailable at boot, but that you still like having managed by systemd.
A simple, illustrative-only example. Given the mnt-foo.mount
unit
[Unit]
Description=foo mount
[Mount]
Where=/mnt/foo
What=/home/user/foo
Type=ext4
(for simplicity, foo
is just a regular file formatted as ext4), and the mnt-foo.automount
unit
[Unit]
Description=foo automount
[Automount]
Where=/mnt/foo
[Install]
WantedBy=multi-user.target
after the latter is activated (or enable
d, and the system rebooted)
# systemctl start mnt-foo.automount
you will be able to check that /home/user/foo
is not mounted anywhere yet—mount
gives
$ mount | grep foo
systemd-1 on /mnt/foo type autofs (...)
and indeed /home/user/foo
is only mounted on /mnt/foo
as soon as you access the mount point:
$ ls /mnt/foo
$ mount | grep foo
systemd-1 on /mnt/foo type autofs (...)
/home/user/foo on /mnt/foo type ext4 (rw,relatime)
Does this mean that when
– ummw Mar 05 '20 at 08:00enable
ing a drive, it must be mounted for the system to boot correctly? Or does this depend on the target or unit config?automount
units, enabledmount
units are only mounted at boot if they are needed (e.g.WantedBy
) in order to reach the default target (in systemd parlance); if so, and if their resource is not available, 1.1) the system won't boot if they hold a needed part of the tree (e.g./
); 1.2) otherwise, their mount operation will fail, possibly slowing down the boot process. (cont.) – fra-san Mar 05 '20 at 22:30automount
unit only needs to be available when accessed; it doesn't need to be available at boot. If anautomount
unit is not started, its file system is not mounted when the corresponding mount point is accessed. 3) Having both an enabled and activatedmount
unit and a corresponding enabled and activatedautomount
unit at boot makes only sense in corner cases that are beyond the scope of this answer, I guess (e.g. mounting a file system at boot and unmounting it when not used by means of theTimeoutIdleSec
option). – fra-san Mar 05 '20 at 22:31