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?

0

1 Answer 1

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.

2
  • Perfect! Thanks a lot! \x2d was what I was searching for. I know that I could have changed also the udisks2 behavior, but then I would have had to change my other scripts as well ;) PS first I tried it and it was not working and but then after a couple of minutes I realized that I forgot the .mount at the end OMG.
    – Danielme
    Commented Jul 18, 2016 at 7:27
  • 1
    A valid question is why systemd did not simple use url-encode to escape / (%2F) and - (%2D) the same way. Don't tell me it's to save two bytes for every slash!
    – U. Windl
    Commented Apr 29, 2019 at 10:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .