From 9f1ac0b45e77f923017b25fb60187c975b9391e3 Mon Sep 17 00:00:00 2001 From: "rick.chan" Date: Sat, 9 May 2020 09:59:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Samba=20Fails=20to=20Creat?= =?UTF-8?q?e=20The=20Folder.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rick.chan --- .../Samba/Samba_Fails_to_Create_The_Folder.md | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 Software/Applications/Samba/Samba_Fails_to_Create_The_Folder.md diff --git a/Software/Applications/Samba/Samba_Fails_to_Create_The_Folder.md b/Software/Applications/Samba/Samba_Fails_to_Create_The_Folder.md new file mode 100644 index 0000000..7d43c5e --- /dev/null +++ b/Software/Applications/Samba/Samba_Fails_to_Create_The_Folder.md @@ -0,0 +1,93 @@ +# Samba Fails to Create The Folder + +## 问题描述 + +Samba 突然无法自动运行: + +```sh +$ systemctl status smb +● smb.service - Samba SMB Daemon + Active: failed (Result: exit-code) since Mon 2019-03-18 10:05:14 EET; 40min ago + +Mar 18 10:05:13 arch systemd[1]: Starting Samba SMB Daemon... +Mar 18 10:05:13 arch smbd[695]: mkdir failed on directory /run/samba/ncalrpc: No > +Mar 18 10:05:13 arch smbd[695]: Failed to create pipe directory /run/samba/ncalrp> +Mar 18 10:05:14 arch systemd[1]: smb.service: Main process exited, code=exited, status=> +Mar 18 10:05:14 arch systemd[1]: smb.service: Failed with result 'exit-code'. +Mar 18 10:05:14 arch systemd[1]: Failed to start Samba SMB Daemon. +``` + +ls /run 文件夹发现没有 /run/samba 目录,如果手动创建该文件夹则可以重新启动 Samba 服务,但是这样每次重启都需要手动运行 Samba 服务。 + +## 原因分析 + +/run/samba 文件夹是由 /usr/lib/tmpfiles.d/samba.conf 配置文件创建的: + +```sh +$ journalctl -b | grep tmpfiles + +May 09 09:05:32 HCenter systemd-tmpfiles[611]: Detected unsafe path transition / → /var during canonicalization of /var/lib/systemd. +May 09 09:05:32 HCenter systemd-tmpfiles[611]: Detected unsafe path transition / → /var during canonicalization of /var/lib. +May 09 09:05:32 HCenter systemd-tmpfiles[611]: Detected unsafe path transition / → /var during canonicalization of /var/log. +May 09 09:05:32 HCenter systemd-tmpfiles[611]: Detected unsafe path transition / → /var during canonicalization of /var/cache. +May 09 09:05:32 HCenter systemd-tmpfiles[611]: Detected unsafe path transition / → /var during canonicalization of /var. +May 09 09:05:32 HCenter systemd-tmpfiles[611]: Detected unsafe path transition / → /var during canonicalization of /var/log. +May 09 09:05:32 HCenter systemd-tmpfiles[611]: Detected unsafe path transition / → /var during canonicalization of /var/log. +May 09 09:05:32 HCenter systemd-tmpfiles[611]: Detected unsafe path transition / → /var during canonicalization of /var/log. +May 09 09:05:32 HCenter systemd-tmpfiles[611]: Detected unsafe path transition / → /var during canonicalization of /var. +May 09 09:05:32 HCenter systemd-tmpfiles[611]: Detected unsafe path transition / → /tmp during canonicalization of /tmp. +May 09 09:05:32 HCenter systemd-tmpfiles[611]: Detected unsafe path transition / → /tmp during canonicalization of /tmp. +May 09 09:05:32 HCenter systemd-tmpfiles[611]: Detected unsafe path transition / → /tmp during canonicalization of /tmp. +May 09 09:05:32 HCenter systemd-tmpfiles[611]: Detected unsafe path transition / → /tmp during canonicalization of /tmp. +May 09 09:05:32 HCenter systemd-tmpfiles[611]: Detected unsafe path transition / → /tmp during canonicalization of /tmp. +May 09 09:05:32 HCenter systemd-tmpfiles[611]: Detected unsafe path transition / → /run during canonicalization of /run. +May 09 09:05:32 HCenter systemd-tmpfiles[611]: Detected unsafe path transition / → /run during canonicalization of /run. +``` + +出现了大量的 unsafe path。 + +```sh +$ stat / + File: / + Size: 4096 Blocks: 8 IO Block: 4096 directory +Device: 802h/2050d Inode: 2 Links: 19 +Access: (0775/drwxrwxr-x) Uid: (43655/ UNKNOWN) Gid: (43655/ UNKNOWN) +Access: 2019-12-21 22:28:31.809605109 +0800 +Modify: 2020-04-27 11:23:32.869912052 +0800 +Change: 2020-04-27 11:23:32.869912052 +0800 +Birth: 2019-09-21 19:13:51.000000000 +0800 +``` + +发现根目录的权限不对。 + +## 解决方案 + +```sh +sudo chown root:root / +sudo chmod 0755 / +ls / +``` + +如果根下还有权限不对的文件夹则一起修改了,结果如下: + +```sh +$ stat / + File: / + Size: 4096 Blocks: 8 IO Block: 4096 directory +Device: 802h/2050d Inode: 2 Links: 19 +Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) +Access: 2019-12-21 22:28:31.809605109 +0800 +Modify: 2020-04-27 11:23:32.869912052 +0800 +Change: 2020-05-09 09:35:50.049985653 +0800 +Birth: 2019-09-21 19:13:51.000000000 +0800 +``` + +之后重启,Samba 服务恢复自动运行。 + +## 总结 + +再出现问题之前进行了一次系统升级,升级过程中出现了一些小问题。很可能是升级错误导致根目录权限发生了改变,根目录权限错误可能导致各种各样奇怪的问题。 + +## 参考 + +[samba fails to create the folder /var/run/samba](https://bbs.archlinux.org/viewtopic.php?id=245050)