0

By default udisks2 mounts removable drives under /run/media/$USER/[UUID]. The UUID contains hyphens.

I wanted to use this mount point in a systemd service. But systemd uses hyphens instead of forward slashs.

man systemd.mount tells me:

Mount units must be named after the mount point directories they control. Example: the mount point /home/lennart must be configured in a unit file home-lennart.mount.

Can /run/media/daniel/76ya27o9-abce-81fv-8j2hj-casjkdjhhlasfd/ be used in a systemd service because of the hyphens? If yes, how?

1 Answers1

0

Well the hyphen will be escaped when the unit is being created:

[tom@localhost ~]$ udisksctl mount -b /dev/sdb1 
Mounted /dev/sdb1 at /run/media/tom/A942-EE49.

[tom@localhost ~]$ systemctl --type mount
UNIT                             LOAD   ACTIVE SUB     DESCRIPTION
...
run-media-tom-A942\x2dEE49.mount loaded active mounted /run/media/tom/A942-EE49
...

With some older version of systemd, you may need to escape the backslash of the escaped hyphen:

[Unit]
...
[Service]
...
[Install]
WantedBy=run-media-tom-A942\\x2dEE49.mount

However when I just tested it again with systemd 230, apparently you don't need to do that anymore. So:

[Unit]
...
[Service]
...
[Install]
WantedBy=run-media-tom-A942\x2dEE49.mount

should do.

FWIW, I think udisks2 prefers filesystem label over UUID if set.

P.S. The above case (WantedBy=) is just an example. It is used to make a service start (if enabled) with the mounting.

Tom Yan
  • 10,996