Samba 拒绝使用 ro rootfs 启动

Samba 拒绝使用 ro rootfs 启动

我将 Raspbian Stretch 配置为以只读模式挂载 rootfs。基本上我做了以下事情:

apt-get -y remove --purge triggerhappy logrotate dphys-swapfile
apt-get -y install busybox-syslogd; dpkg --purge rsyslog
rm -rf /var/lib/dhcp/ /var/run /var/spool /var/lock
ln -s /tmp /var/lib/dhcp; ln -s /tmp /var/run; ln -s /tmp /var/spool; ln -s /tmp /var/lock

并将其放入etc/fstab

proc            /proc           proc    defaults                0       0
/dev/mmcblk0p1  /boot           vfat    defaults,ro             0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime,ro     0       1
/dev/mmcblk0p3  /home           ext4    defaults,noatime        0       2
tmpfs           /tmp            tmpfs   nosuid,nodev            0       0
tmpfs           /var/log        tmpfs   nosuid,nodev            0       0
tmpfs           /var/tmp        tmpfs   nosuid,nodev            0       0

一切正常,只是如果 rootfs 以 ro 模式挂载,samba 不会启动。为确保万无一失,我临时将 / 挂载为 rw,它按预期启动了。

以下是 smbd 调试输出的相关部分:

...
Paths:
SBINDIR: /usr/sbin
BINDIR: /usr/bin
CONFIGFILE: /etc/samba/smb.conf
LOGFILEBASE: /var/log/samba
LMHOSTSFILE: /etc/samba/lmhosts
LIBDIR: /usr/lib/arm-linux-gnueabihf
MODULESDIR: /usr/lib/arm-linux-gnueabihf/samba
SHLIBEXT: so
LOCKDIR: /var/run/samba
STATEDIR: /var/lib/samba
CACHEDIR: /var/cache/samba
PIDDIR: /var/run/samba
SMB_PASSWD_FILE: /etc/samba/smbpasswd
PRIVATE_DIR: /var/lib/samba/private
...
Processing section "[global]"
doing parameter workgroup = WORKGROUP
doing parameter netbios name = MYSAMBA
doing parameter security = user
doing parameter map to guest = Bad User
doing parameter guest account = pi
doing parameter wins support = yes
pm_process() returned Yes
lp_servicenumber: couldn't find homes
get_current_groups: user is in 1 groups: 0
unix_msg_init failed: Read-only file system
messaging_dgm_ref: messaging_dgm_init returned Read-only file system
messaging_dgm_init failed: Read-only file system
messaging_dgm_ref failed: Read-only file system

很明显它不喜欢只读文件系统,但我不明白是什么阻止它启动。因此如何修复它!

如果我没有提供所有信息来帮助您理解该场景,请在评论中询问我!

更新

添加符号链接后var/libvar/cache我还将其符号链接/etc/samba到可写分区(我不喜欢这样,但我不知道如何仅/etc/samba/dhcp.conf.new在创建时进行符号链接)。

现在输出有点不同:

...
lp_servicenumber: couldn't find homes
get_current_groups: user is in 16 groups: 4, 7, 20, 24, 27, 29, 44, 46, 60, 100, 101, 108, 997, 998, 999, 1000
directory_create_or_exist_strict: invalid ownership on directory /var/run/samba/msg.lock
messaging_init: Could not create lock directory: No such file or directory

但:

$ls -l /var/run/samba
drwxr-xr-x 2 root root 40 Sep 4 13:28 msg.lock

答案1

这些行

LOCKDIR: /var/run/samba
STATEDIR: /var/lib/samba
CACHEDIR: /var/cache/samba
PIDDIR: /var/run/samba

指向只读位置,但我认为服务器需要在那里写入。读取smb.conf 的手册页. 相应的设置为lock directorystate directorycache directorypid directory至少这四个应该指向可写位置。

相关内容