2

I want to create systemd mount-unit equivalent for next fstab line

/dev/sdc1 /жышы ext4 defaults 1 2

Something as
жышы.mount

[Unit]
Description= /dev/sdc1 to /жышы

[Mount]
What=/dev/sdc1
Where=/жышы
Type=ext4

[Install]
WantedBy=multi-user.target

Yes, I tried to use systemd-escape for unit file name and for Where, but without success. My better approach was:
xd0xb6xd1x8bxd1x88xd1x8b.mount

[Unit]
Description= /dev/sdc1 to /жышы

[Mount]
What=/dev/sdc1
Where='/жышы'
Type=ext4

[Install]
WantedBy=multi-user.target

This variant almost working (no error for unit file name), but mounts /dev/sdc1 to auto-created folder /xd0xb6xd1x8bxd1x88xd1x8b instead of /жышы.

Please help to fix this mess.

1 Answers1

3

From man systemd.mount:

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. For details about the escaping logic used to convert a file system path to a unit name, see systemd.unit(5).

OK, so from man systemd.unit:

The escaping algorithm operates as follows: given a string, any "/" character is replaced by "-", and all other characters which are not ASCII alphanumerics, ":", "_" or "." are replaced by C-style "\x2d" escapes. In addition, "." is replaced with such a C-style escape when it would appear as the first character in the escaped string.

When the input qualifies as absolute file system path, this algorithm is extended slightly: the path to the root directory "/" is encoded as single dash "-". In addition, any leading, trailing or duplicate "/" characters are removed from the string before transformation. Example: /foo//bar/baz/ becomes "foo-bar-baz".

This escaping is fully reversible, as long as it is known whether the escaped string was a path (the unescaping results are different for paths and non-path strings). The systemd-escape(1) command may be used to apply and reverse escaping on arbitrary strings. Use systemd-escape --path to escape path strings, and systemd-escape without --path otherwise.

So, we run

systemd-escape --path /жышы

and get

\xd0\xb6\xd1\x8b\xd1\x88\xd1\x8b

So, \xd0\xb6\xd1\x8b\xd1\x88\xd1\x8b.mount is the right file name. The backslashes are important!

Edgar Magallon
  • 4,711
  • 2
  • 12
  • 27
Marcus Müller
  • 21,602
  • 2
  • 39
  • 54
  • Well `\xd0\xb6\xd1\x8b\xd1\x88\xd1\x8b.mount` on my `ext4` show as `xd0xb6xd1x8bxd1x88xd1x8b.mount` file and non working. But creating file `\\xd0\\xb6\\xd1\\x8b\\xd1\\x88\\xd1\\x8b.mount` that show as `\xd0\xb6\xd1\x8b\xd1\x88\xd1\x8b.mount` does the trick. – Alexander Dyadyun Apr 09 '23 at 12:56
  • What "shows" IS what you created. So, I don't know *how* you attempted to create things (something broke the backslashes!), but that file name with the single backslashes is the right one. – Marcus Müller Apr 09 '23 at 12:57
  • It was `touch \xd0\xb6\xd1\x8b\xd1\x88\xd1\x8b.mount`. Yes I forgоt about esc-sequences in filenames. My bad. – Alexander Dyadyun Apr 09 '23 at 13:05
  • Nothing to be sorry about! :) Ah, I'd try `touch "$(systemd-escape --path /жышы).mount"` – Marcus Müller Apr 09 '23 at 13:59