Component
systemd
Is your feature request related to a problem? Please describe
Mounting multiple UUIDs in the same directory on separate subdirectories.
System with 2 disks, whole installation on BTRFS RAID1 and two separate ESPs (/boot, Limine bootloader, UKI).
Both ESPs are synced via a mkinitcpio hook, so system can UEFI boot from any ESP in case a disk fails.
The ESPs have to be mounted at constant places - here /mnt/esp/${UUID} - for syncing via rsync from /boot (=updated ESP) to /mnt/esp/${UUID} (the ESP under /boot has never any changes).
Service mnt-esp-preferred.service detects the last updated ESP via file .last-update - that file is touched by the mkinitcpio hook - and then links (ln) the related device to /mnt/esp/preferred.
In /etc/fstab /boot is mounted from /mnt/esp/preferred and requires /mnt/esp/preferred.
Describe the solution you'd like
Using mount template units exactly like service template units.
Including being able to use template@*.mount.
Being able to use template@*.mount would be convienent for sleep/hibernate and resume services, plus systemctl in general.
systemd-escape --path already escapes at-symbols (@) in paths, so the @ of the template unit is unique and not part of the path.
For verifying that the instantiated unit name matches the What= setting the @ must just be ignored.
# systemd-escape --path 'AAAA-AAAA'
AAAA\x2dAAAA
## correct path escaping for /mnt/test/AAAA-AAAA is mnt-test-AAAA\x2dAAAA
# systemctl start 'mnt-test-@AAAA\x2dAAAA.mount' ;
mnt-test-@.mount
[Unit]
Description=UUID %I at /mnt/test/%I
ConditionPathExists=/dev/disk/by-uuid/%I
### Define JobTimeoutSec due to implict BindsTo= setting of device for What= setting, which leads to long 90s device timeout if the related disk failed or is not available
JobTimeoutSec=2s
[Mount]
What=/dev/disk/by-uuid/%I
Where=/mnt/test/%I
Type=vfat
Options=defaults,umask=0077,nofail
### TimeoutSec for mount command (if device is present)
TimeoutSec=1s
Describe alternatives you've considered
Right now for my explicit case a script copies the mount template file to a fitting mount unit name, then replaces all %I occurrences via sed.
So instead of using mnt-esp-@AAAA\x2dAAAA.mount the final unit is mnt-esp-AAAA\x2dAAAA.mount.
The script also takes care of the needed override files for mnt-esp-preferred.service.
Unfortunately the script cannot use mnt-esp-@*.mount but only mnt-esp-*.mount, which could lead to false-positives in other cases where there are further submounts under that target.
mnt-esp-.target
[Unit]
Description=Collection of mnt-esp-@*.mount units
### Mimic dependencies of "mount units referring to local file systems"
DefaultDependencies=no
After=local-fs-pre.target
Before=local-fs.target
[Install]
RequiredBy=local-fs.target
mnt-esp-@.mount
[Unit]
### Mount NOT(!) via /etc/fstab due to ConditionPathExists and long (90s!) default timeout for related device, plus (optional) hibernation services
Description=ESP UUID %I at /mnt/esp/%I
ConditionPathExists=/dev/disk/by-uuid/%I
### Define JobTimeoutSec due to implict BindsTo= setting of device for What= setting, which leads to long 90s device timeout if the related disk failed or is not available
JobTimeoutSec=2s
[Mount]
What=/dev/disk/by-uuid/%I
Where=/mnt/esp/%I
Type=vfat
Options=defaults,umask=0077,nofail
### TimeoutSec for mount command (if device is present)
TimeoutSec=1s
[Install]
### Enable target to always start mount unit at system start, and not only when requested
WantedBy=mnt-esp-.target
mnt-esp-preferred.service
[Unit]
Description=Select preferred ESP
DefaultDependencies=no
### Blocks of the following definitions will be added by shell script via override file
# Wants=mnt-esp-XXXX\xXXXX.mount
# After=mnt-esp-XXXX\xXXXX.mount
# ConditionPathExists=|/dev/disk/by-uuid/XXXX-XXXX
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/systemd/mnt-esp-preferred.sh
Environment=MOUNT_SERVICE='%n'
Environment=MOUNT_CHECKFILE='.last-update'
Environment=MOUNT_BASEPATH='/mnt/esp'
Environment=MOUNT_TARGETLINK='/mnt/esp/preferred'
### Following environment definitions will be added by shell script via override file
# Environment=MOUNT_UUIDS='...'
/etc/fstab
/mnt/esp/preferred /boot vfat defaults,umask=0077,x-systemd.requires=mnt-esp-preferred.service 0 2
The systemd version you checked that didn't have the feature you are asking for
261.3
Component
systemd
Is your feature request related to a problem? Please describe
Mounting multiple UUIDs in the same directory on separate subdirectories.
System with 2 disks, whole installation on BTRFS RAID1 and two separate ESPs (
/boot, Limine bootloader, UKI).Both ESPs are synced via a mkinitcpio hook, so system can UEFI boot from any ESP in case a disk fails.
The ESPs have to be mounted at constant places - here
/mnt/esp/${UUID}- for syncing viarsyncfrom/boot(=updated ESP) to/mnt/esp/${UUID}(the ESP under/boothas never any changes).Service
mnt-esp-preferred.servicedetects the last updated ESP via file.last-update- that file is touched by the mkinitcpio hook - and then links (ln) the related device to/mnt/esp/preferred.In
/etc/fstab/bootis mounted from/mnt/esp/preferredand requires/mnt/esp/preferred.Describe the solution you'd like
Using mount template units exactly like service template units.
Including being able to use
template@*.mount.Being able to use
template@*.mountwould be convienent for sleep/hibernate and resume services, plussystemctlin general.systemd-escape --pathalready escapes at-symbols (@) in paths, so the@of the template unit is unique and not part of the path.For verifying that the instantiated unit name matches the
What=setting the@must just be ignored.mnt-test-@.mount
Describe alternatives you've considered
Right now for my explicit case a script copies the mount template file to a fitting mount unit name, then replaces all
%Ioccurrences via sed.So instead of using
mnt-esp-@AAAA\x2dAAAA.mountthe final unit ismnt-esp-AAAA\x2dAAAA.mount.The script also takes care of the needed override files for
mnt-esp-preferred.service.Unfortunately the script cannot use
mnt-esp-@*.mountbut onlymnt-esp-*.mount, which could lead to false-positives in other cases where there are further submounts under that target.mnt-esp-.target
mnt-esp-@.mount
mnt-esp-preferred.service
/etc/fstab
The systemd version you checked that didn't have the feature you are asking for
261.3