brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: a systemd .mount unit must be named after its mount path

Systemd
~/tips/tip-systemd-mount-unit-name

systemd-escape -p --suffix=mount /mnt/backup

Name mount unit files correctly so systemd accepts them, using systemd-escape.

Writing a .mount unit instead of an fstab line gives you dependencies and timers on a mount. systemd is strict about the file name of such a unit, though.

The unit name has to be the mount path, with slashes turned into dashes. Let systemd work it out:

systemd-escape -p --suffix=mount /mnt/backup
systemd-escape -p --suffix=mount '/mnt/my disk'

That prints mnt-backup.mount and mnt-my\x20disk.mount. Then write the file under that name:

# /etc/systemd/system/mnt-backup.mount
[Mount]
What=/dev/disk/by-uuid/0a1b2c3d-example
Where=/mnt/backup
Type=ext4

[Install]
WantedBy=multi-user.target

Take a tmpfs mount for /mnt/scratch. As mnt-scratch.mount it mounts fine; the same file as scratch.mount fails with Where= setting doesn't match unit name. Refusing.

Services can then wait for it with RequiresMountsFor=/mnt/backup, and you can pair it with an .automount unit of the same name.

I would not define the same path in both fstab and a unit file. systemd turns fstab lines into mount units at boot, and a file in /etc/systemd/system with the same name overrides the generated one, which gets confusing fast.

Further reading: systemd.mount man page, systemd-escape man page

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link