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:

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
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/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


$ls -l /var/run/samba
drwxr-xr-x 2 root root 40 Sep 4 13:28 msg.lock
  • What is the output of ls -dl /var/run/samba? What (Linux) user does your samba run as? – Kamil Maciorowski Sep 4 '17 at 12:10
  • drwxr-xr-x 4 root root 340 Sep 4 17:59 /var/run/samba. The guest account is pi, that is also the current and only user available. – Mark Sep 4 '17 at 16:01
  • On my friend's Raspbian smbd (a daemon) runs as root. If you run it as pi then invalid ownership on directory /var/run/samba/msg.lock may be because it's owned by root. But you said it used to work. While testing, are you sure you run samba as user it's supposed to run as? – Kamil Maciorowski Sep 4 '17 at 19:10
  • Perhaps I didn't understand your question. The smbd.service is started by systemd as root. pi is just the normal user the the guest account in smb.conf. – Mark Sep 5 '17 at 5:28
  • Saying it in other words: how would you configure samba to work with a read-only file-system? Perhaps it would be easier begin from scratch than try to guess my mistakes! – Mark Sep 5 '17 at 5:28

These lines

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

point to read-only locations but the server needs to write there, I think. Read the manpage for smb.conf. The respective settings are lock directory, state directory, cache directory and pid directory. At least these four should point to writable locations.

| improve this answer | |
  • I added symbolic links also for /var/lib and /var/cache to /tmp and now those directories are writable even with the filesystem in ro. But the samba behavior is the same. – Mark Sep 4 '17 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.