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
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!
After adding the symlink for
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
$ls -l /var/run/samba drwxr-xr-x 2 root root 40 Sep 4 13:28 msg.lock