我想在启动时挂载 UBI 文件系统。根据配置,MTD 设备号可能因版本而异,但它始终是名为 的分区add
。
我添加了以下文件
# /usr/lib/udev/rules.d/76-mtd-alias.rules
ACTION!="add", GOTO="mtd_alias_end"
SUBSYSTEM=="mtd", SYMLINK="mtd-byname/$attr{name}", TAG+="systemd"
LABEL="mtd_alias_end"
这会创建类似于/dev/mtd-by-name/add
相关/dev/mtdblockX
文件的符号链接的文件(X
取决于配置)。
# /usr/lib/systemd/system/mnt-data.mount
[Unit]
Description=Mount data partition
Requires=data-attach.service
After=data-attach.service
[Mount]
What=ubi0_0
Where=/mnt/data
Type=ubifs
和...一起
#/usr/lib/systemd/system/data-attach.service
[Unit]
Description=Attach data ubi partition
[Service]
Type=oneshot
RemainAfterExit=yes
Requires=dev-mtd\x2dbyname-add.device
After=dev-mtd\x2dbyname-add.device
ExecStart=/usr/sbin/ubiattach /dev/ubi_ctrl -p /dev/mtd-byname/add
ExecStop=/usr/sbin/ubidetach /dev/ubi_ctrl -p /dev/mtd-byname/add
问题是,尽管systemd
做启动data-attach.service
,它仍然在udev
创建符号链接之前执行此操作。
系统启动后,我可以看到已经device
启动,尽管挂载失败:
# systemctl status data-attach.service
● data-attach.service - Attach data ubi partition
Loaded: loaded (/lib/systemd/system/data-attach.service; static; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2018-06-22 11:11:50 UTC; 7min ago
Process: 164 ExecStart=/usr/sbin/ubiattach /dev/ubi_ctrl -p /dev/mtd-byname/add (code=exited, status=255)
Main PID: 164 (code=exited, status=255)
Jun 22 11:11:50 LogiPeru ubiattach[164]: libubi: error!: cannot stat "/dev/mtd-byname/add"
Jun 22 11:11:50 LogiPeru ubiattach[164]: error 2 (No such file or directory)
Jun 22 11:11:50 LogiPeru ubiattach[164]: ubiattach: error!: cannot attach "/dev/mtd-byname/add"
Jun 22 11:11:50 LogiPeru ubiattach[164]: error 2 (No such file or directory)
Jun 22 11:11:50 LogiPeru systemd[1]: Starting Attach data ubi partition...
Jun 22 11:11:50 LogiPeru systemd[1]: data-attach.service: Main process exited, code=exited, status=255/n/a
Jun 22 11:11:50 LogiPeru systemd[1]: data-attach.service: Failed with result 'exit-code'.
Jun 22 11:11:50 LogiPeru systemd[1]: Failed to start Attach data ubi partition.
但确实device
加载了:
# systemctl status 'dev-mtd\x2dbyname-add.device'
● dev-mtd\x2dbyname-add.device - /dev/mtd-byname/add
Follow: unit currently follows state of sys-devices-virtual-mtd-mtd10.device
Loaded: loaded
Active: active (plugged) since Fri 2018-06-22 11:11:50 UTC; 10min ago
Device: /sys/devices/virtual/mtd/mtd10
# ls -l /dev/mtd-byname/add
lrwxrwxrwx 1 root root 8 Jun 22 11:11 /dev/mtd-byname/add -> ../mtd10
我哪里做错了?为什么Requires
和After
标签data-attach.service
被忽略了?如果我等到我可以登录,那么我就可以运行systemctl start mnt-data.mount
并且挂载成功。
答案1
[Service] <...> Requires=dev-mtd\x2dbyname-add.device After=dev-mtd\x2dbyname-add.device
你必须把Requires=
和After=
指令放入[Unit]
单元文件的部分。它们不会在或[Service]
任何其他部分中起作用。
未来诊断的建议:systemctl daemon-reload
与其他systemctl
动词一样, 仅将其警告和错误写入系统日志,而不写入 的systemctl
stdout/stderr(即控制台)。systemctl daemon-reload
特别是, 仅报告严重错误,例如无法与 通信。 因此,在任何命令之后systemd
使用类似命令手动检查系统日志可能会有所帮助。journalctl -e _PID=1
systemctl