[systemd-devel] systemd.mount - How to disable the auto-creation of the directory (directories)
kAja Ziegler
ziegleka at gmail.com
Thu Oct 20 07:18:36 UTC 2022
Hello,
Is there any way to turn off the automatic directory (directories) creation
during mount unit start/run? To make the [auto-generated] mount unit behave
the same as the mount command - to end with an error?
- from the systemd.mount man page:
What=
Takes an absolute path of a device node, file or other resource to mount.
See mount(8) for details. If this refers to a device node, a dependency on
the respective device unit is automatically created. (See systemd.device(5)
for more information.)
This option is mandatory.
Where=
Takes an absolute path of a directory of the mount point. If the mount
point does not exist at the time of mounting, it is created. This string
must be reflected in the unit filename. (See above.) This option is
mandatory.
- example:
- fstab:
/mnt/x /mnt/y none bind 0 0
- commands:
# systemctl daemon-reload
# systemctl --version
systemd 250 (v250.8-1.fc36)
# ls -1 /mnt
# mount /mnt/y
mount: /mnt/y: mount point does not exist.
dmesg(1) may have more information after failed mount system call.
# ls -1 /mnt
# systemctl cat mnt-y.mount
# /run/systemd/generator/mnt-y.mount
# Automatically generated by systemd-fstab-generator
[Unit]
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
SourcePath=/etc/fstab
Before=local-fs.target
[Mount]
What=/mnt/x
Where=/mnt/y
Type=none
Options=bind
# systemctl start mnt-y.mount
# systemctl status mnt-y.mount
● mnt-y.mount - /mnt/y
Loaded: loaded (/etc/fstab; generated)
Active: active (mounted) since Thu 2022-10-20 09:01:05 CEST; 13s ago
Until: Thu 2022-10-20 09:01:05 CEST; 13s ago
Where: /mnt/y
What: /dev/mapper/vg_sys-lv_root
Docs: man:fstab(5)
man:systemd-fstab-generator(8)
Tasks: 0 (limit: 9333)
Memory: 16.0K
CPU: 6ms
CGroup: /system.slice/mnt-y.mount
Oct 20 09:01:05 demo-lab systemd[1]: Mounting mnt-y.mount - /mnt/y...
Oct 20 09:01:05 demo-lab systemd[1]: Mounted mnt-y.mount - /mnt/y.
# mount | fgrep /mnt/y
/dev/mapper/vg_sys-lv_root on /mnt/y type ext4
(rw,relatime,seclabel,errors=remount-ro)
# findmnt
TARGET SOURCE
FSTYPE OPTIONS
...
├─/mnt/y /dev/mapper/vg_sys-lv_root[/mnt/x] ext4
rw,relatime,seclabel,errors=remount-ro
...
# ls -1 /mnt
x
y
The systemd.mount unit created both directories - the destination directory
/mnt/y (Where=) and also the source directory /mnt/x (What=). Additionally,
this behavior for What= is not mentioned in the man page.
Thank you and with best regards,
--
Karel Ziegler
e-mail: ziegleka at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20221020/50ad1f6a/attachment.htm>
More information about the systemd-devel
mailing list