NotePublic/Software/Applications/Samba/Samba_Fails_to_Create_The_F...

4.4 KiB
Raw Blame History

Samba Fails to Create The Folder

问题描述

Samba 突然无法自动运行:

$ 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 配置文件创建的:

$ 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。

$ 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

发现根目录的权限不对。

解决方案

sudo chown root:root /
sudo chmod 0755 /
ls /

如果根下还有权限不对的文件夹则一起修改了,结果如下:

$ 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