I configured Raspbian Stretch to mount rootfs in read-only mode. Basically I did the following:
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
and put this in 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
all works fine expect samba that doesn't start if rootfs is mounted in ro mode. To be sure, I temporary mounter / as rw and it started as expected.
Here the relevant part of the debug output of 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
It's pretty clear it doesn't like the read-only file system, but I don't understand what prevents it from starting. And hence how to fix it!
If I didn't provide all the information to understand the scenario, please ask me in comments!
UPDATE
After adding the symlink for var/lib
and var/cache
I also symlinked /etc/samba
to the writable partition (I don't like this, but I don't know how to symlink only /etc/samba/dhcp.conf.new
when created).
Now the output is a bit different:
...
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
but:
$ls -l /var/run/samba
drwxr-xr-x 2 root root 40 Sep 4 13:28 msg.lock
ls -dl /var/run/samba
? What (Linux) user does your samba run as?drwxr-xr-x 4 root root 340 Sep 4 17:59 /var/run/samba
. Theguest account
ispi
, that is also the current and only user available.smbd
(a daemon) runs asroot
. If you run it aspi
theninvalid ownership on directory /var/run/samba/msg.lock
may be because it's owned byroot
. But you said it used to work. While testing, are you sure you run samba as user it's supposed to run as?smbd.service
is started bysystemd
asroot
.pi
is just the normal user the theguest account
insmb.conf
.