3

I have a systemd service mounting a partition of a UFS LU to /mnt

## bt_mount.service ##
[Unit]
Description=Mount bt_firmware_a/b to /mnt

[Service]
Type=oneshot
PassEnvironment="SLOT"  ## "_a" or "_b", depends on the boot slot
ExecStart=/bin/mount -o noexec,nodev,ro /dev/disk/by-partlabel/bt_firmware${SLOT} /mnt

[Install]
WantedBy=local-fs.target

BUT

It fails sometimes saying that "special device /dev/disk/by-partlabel/bt_firmware_a does not exist"

systemd-analyze shows that bt_mount.service gets to run before the symbol-link is created, that is the cause.

I search on google and get to know that systemd-udevd.service plays an important role to create thoes symlink, and it will creates them when udevadm --trigger.

systemd-udevd.service
systemd-udevd-trigger.service

I had tried to add dependency for the service using statement below, but still the same.

After=systemd-udevd-trigger.service systemd-udevd.service

So, it there any way to let some service launch after the specific symlink is created?

xiao
  • 63
  • 1
  • 5

1 Answers1

0

I'm late to the party. However as still no answer and showing up top on search engines worth proposing a solution.

Fought some time with a similar issue with a oneshot service that must run before some partitions are mounted but after the partlabel symlinks are created.

Systemd creates a systemd-fsck@dev-disk-by\x2dpartlabel-XXX.service for every partlabel (here XXX) and similarly for other disk labels or partuuids.

As you have a dependency on your boot slot i don't think it is possible to wait only on your active boot slot's symlink, so add both partition labels to your Wants/Requires and After like in:

Wants=systemd-fsck@dev-disk-by\x2dpartlabel-bt_firmware_a.service systemd-fsck@dev-disk-by\x2dpartlabel-bt_firmware_b.service
After=systemd-fsck@dev-disk-by\x2dpartlabel-bt_firmware_a.service systemd-fsck@dev-disk-by\x2dpartlabel-bt_firmware_b.service

Feel free to use Requires instead of Wants depending on your use case.

Hope that will help someone even if the OP probably found a way on his own in the meantime.

Martin
  • 451
  • 6
  • 10