On-demand mounts are useful when a filesystem is slow, optional, or remote and you do not want boot to block on it. A systemd automount unit keeps the path available immediately, then mounts the backing storage only when a process actually touches the directory.
In systemd, the *.automount unit watches a directory and triggers the matching *.mount unit on first access. Both files must use the same escaped path-based name, so a mount point such as /srv/archive becomes srv-archive.mount and srv-archive.automount. The example below uses a bind mount because it is easy to validate safely, but the same structure applies to local disks, network filesystems, and other mount types by changing What=, Type=, and Options= in the mount unit.
Automount units are privileged and belong in the system manager, so use sudo/root and place them under /etc/systemd/system. Keep network ordering or remote-mount requirements on the matching *.mount unit, not on the *.automount unit itself; the upstream systemd.automount documentation warns that directives such as After=network-online.target on the automount unit can create ordering cycles. If you do not want idle unmounting, omit TimeoutIdleSec= or set it to 0 because the default is disabled.
Steps to create a systemd automount unit:
- Convert the target mount path to the escaped unit name that both files must use.
$ systemd-escape --path /srv/archive srv-archive
The escaped name becomes srv-archive.mount for the mount unit and srv-archive.automount for the automount unit.
- Create the source and target directories for the sample bind mount.
$ sudo mkdir -p /srv/source-archive /srv/archive $ sudo touch /srv/source-archive/report-2026.txt
The sample source file makes the first automount trigger easy to verify. Replace these paths with the real source and mount point you want to manage.
- Create the matching mount unit file.
[Unit] Description=Bind mount for /srv/archive [Mount] What=/srv/source-archive Where=/srv/archive Type=none Options=bind
This bind-mount example keeps the article focused on the unit relationship. For NFS, CIFS, or a block device, change What=, Type=, and Options= for the real backend and keep any remote-mount dependencies on this *.mount unit.
- Create the matching automount unit file.
[Unit] Description=Automount for /srv/archive [Automount] Where=/srv/archive TimeoutIdleSec=5min [Install] WantedBy=multi-user.target
Where= must match the path in the mount unit and the escaped filename. The TimeoutIdleSec=5min line unmounts the filesystem after five idle minutes; remove it or set it to 0 to keep the mount active until shutdown or manual unmount.
- Verify that both unit files parse cleanly before reloading the manager.
$ sudo systemd-analyze verify /etc/systemd/system/srv-archive.mount /etc/systemd/system/srv-archive.automount
No output means systemd accepted the syntax and unit relationship.
- Reload systemd and enable the automount unit at boot.
$ sudo systemctl daemon-reload $ sudo systemctl enable --now srv-archive.automount Created symlink /etc/systemd/system/multi-user.target.wants/srv-archive.automount → /etc/systemd/system/srv-archive.automount.
The automount unit is the object you enable. The matching *.mount unit usually remains static and is pulled in automatically on first access.
- Confirm that the automount unit is active and waiting for access.
$ systemctl status --no-pager --full srv-archive.automount | head -n 5 ● srv-archive.automount - Automount for /srv/archive Loaded: loaded (/etc/systemd/system/srv-archive.automount; enabled; preset: enabled) Active: active (waiting) since Mon 2026-04-13 08:24:20 UTC; 69ms ago Triggers: ● srv-archive.mount Where: /srv/archiveThe active (waiting) state is the success condition before the first access. It means the path is armed and ready to trigger the mount unit.
- Access the mount point to trigger the mount and confirm that the backing content appears.
$ ls /srv/archive report-2026.txt $ systemctl status --no-pager --full srv-archive.mount | head -n 5 ● srv-archive.mount - Bind mount for /srv/archive Loaded: loaded (/etc/systemd/system/srv-archive.mount; static) Active: active (mounted) since Mon 2026-04-13 08:24:20 UTC; 71ms ago TriggeredBy: ● srv-archive.automount Where: /srv/archiveThe first access may pause briefly while the mount is established. If the directory stays empty or the mount unit fails, inspect journalctl -u srv-archive.mount -u srv-archive.automount for the real error.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
