我需要将目录从另一个硬盘挂载到我当前的主目录。我可以通过以下命令执行此操作,并且它正常工作:
sudo mount --bind /media/username/HDD3TB/'Мои документы'/Фото /home/username/Pictures/HDD_Photo
但我希望它在系统初始化期间自动挂载。我尝试将以下条目添加到 /etc/fstab:
/media/username/HDD3TB/'Мои документы'/Фото /home/username/Pictures/HDD_Photo none bind 0 0
但这种方式不起作用并且会导致系统初始化时出现错误。
在 journalctl 中我发现了以下错误消息:
kernel: ACPI Error: [\_SB_.PCI0.XHC_.RHUB.HS11] Namespace lookup failure, AE_NOT_FOUND (20170831/dswload-210)
kernel: ACPI Exception: AE_NOT_FOUND, During name lookup/catalog (20170831/psobject-253)
kernel: ACPI Exception: AE_NOT_FOUND, (SSDT:xh_rvp08) while loading table (20170831/tbxfload-228)
kernel: ACPI Error: 1 table load failures, 5 successful (20170831/tbxfload-246)
kernel: clocksource: hpet: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 79635855245 ns
和
-- The start-up result is RESULT.
июн 30 20:03:24 elementaryOS systemd-remount-fs[448]: mount: /etc/fstab: parse error at line 19 -- ignored
июн 30 20:03:24 elementaryOS systemd[1]: Started Remount Root and Kernel File Systems.
-- Subject: Unit systemd-remount-fs.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit systemd-remount-fs.service has finished starting up.
...
-- The start-up result is RESULT.
июн 30 20:03:32 elementaryOS systemd-fsck[1055]: fsck: /etc/fstab: parse error at line 19 -- ignored
июн 30 20:03:32 elementaryOS systemd[1]: Started File System Check Daemon to report status.
-- Subject: Unit systemd-fsckd.service has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
...
-- Unit systemd-fsck@dev-disk-by\x2duuid-4e02e814\x2d86be\x2d4995\x2d9989\x2dbe965304d5ea.service has begun starting up.
июн 30 20:03:32 elementaryOS systemd-fsck[1078]: fsck: /etc/fstab: parse error at line 19 -- ignored
июн 30 20:03:32 elementaryOS systemd[1]: Found device ST1000DM003-9YN162 1.
-- Subject: Unit dev-disk-by\x2duuid-c6e31fc0\x2d90ae\x2d48c3\x2dba37\x2db124bffc57f3.device has finished start-up
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Unit dev-disk-by\x2duuid-c6e31fc0\x2d90ae\x2d48c3\x2dba37\x2db124bffc57f3.device has finished starting up.
我可以在路径中使用空格和西里尔符号吗?或者我应该使用另一种方式自动挂载此目录?
答案1
您不需要使用/etc/fstab/
,而可以创建以下systemd
服务来挂载该文件。
我改编了:这个答案由用户撰写:@detuur以适应这一特殊情况。
使用以下方式创建一个新文件:sudo vim /etc/systemd/system/boot-shadow-mount.service
然后复制并粘贴以下内容,然后保存文件并退出vim
# Automatically mounts and binds HDD3TB directory to /Pictures/HDD_Photo
#
[Unit]
Description=bind mount HDD3TB drive directory to /Pictures/HDD_Photo
Requires=bindmount@home-username-Pictures-HDD_Photo.mount
Conflicts=umount.target
[Service]
Type=oneshot
ExecStart=/bin/mount --bind /media/username/HDD3TB/'Мои документы'/Фото /home/username/Pictures/HDD_Photo
ExecStop=/bin/umount /home/username/Pictures/HDD_Photo
RemainAfterExit=True
[Install]
RequiredBy=local-fs.target unattended-upgrades.service
接下来运行以下命令来更正文件中的“用户名”:
sudo sed -i "s/username/$USER/g" /etc/systemd/system/boot-shadow-mount.service
然后,运行以下命令“启用”新服务,以便该服务在启动系统时自动启动:
sudo systemctl daemon-reload
sudo systemctl enable boot-shadow-mount
当您重新启动时,该文件将自动挂载。
请发布任何错误。谢谢!
附加来源:blog.iwakd.de/systemd-fstab-and-bind-mounts-with-options