Guide: How to enable Samba server on the Pi's read only file system

Enabling Samba on the Raspberry Pi enables its files to be read easily in Windows, its very useful if like me your day to day work is from a Windows machine. To allow it to work with the read only file system requires a few extra steps which I'll detail below. This guide applies to Jessie, it should work on Wheezy if the servicectl commands are changed to the correct syntax for Wheezy.
First of all if its not already been done, put the Pi into read write mode by entering RPI-RW then open the ports on the firewall by entering

sudo ufw allow proto udp to any port 137 from 192.168.1.0/24
sudo ufw allow proto udp to any port 138 from 192.168.1.0/24
sudo ufw allow proto tcp to any port 139 from 192.168.1.0/24
sudo ufw allow proto tcp to any port 445 from 192.168.1.0/24

you will need to change the 192.168.1.0/24 so it reflects your network settings. Once this is done Samba needs installing, I followed the guide at
http://www.homeautomationforgeeks.com/samba.shtml

Edit the configuration file to stop it spamming the logs with printer support messages

sudo nano /etc/samba/smb.conf

add to the [global] section

printing = bsd
printcap name = /dev/null

On my Pi, I also added entries for the /tmp and /var/log folders at the bottom of the file. Save the file and move on.

IT WILL NOT WORK AT THIS STAGE AFTER THE REBOOT, so if you want to test if it works so far enter 

rpi-rw
sudo systemctl restart smbd
sudo systemctl restart nmbd

Once Samba is installed and configured, put the system into read write mode (rpi-rw) and create a file in /home/pi called fixsamba.sh containing the following

#!/bin/bash
# This script fixes samba which doesn't start properly if the Pi is in read only mode, its runs at start from crontab -e
mkdir /tmp/samba
mkdir /tmp/cache
mkdir /tmp/cache/samba
​sudo mkdir /var/log/samba
sudo systemctl restart smbd
​sudo systemctl restart nmbd

save and exit. Then make the script executable by typing

​sudo chmod 777 /home/pi/fixsamba.sh

make the script execute at startup by typing

​crontab -e

and adding

@reboot sudo /home/pi/fixsamba.sh

to the file. Save the crontab and edit the file that puts the pi into read only mode
If you are running the EMONPI Image type

​sudo nano /home/pi/emonpi/rpi-ro

if you are on the full image you will need

​sudo nano /usr/bin/rpi-ro

If you end up with an empty file at this stage its likely you need the emonpi command.

change the file so it reads

#!/bin/sh
​sudo systemctl stop smbd
​sudo systemctl stop nmbd
​sudo mount -o remount,ro /dev/mmcblk0p2  /
​sudo systemctl start smbd
echo "Filesystem is locked - Read Only access"
echo "type ' rpi-rw ' to unlock"

save and exit, now we need to move where samba stores its parameter files. Enter 

​sudo systemctl stop smbd
sudo systemctl stop nmbd
mv /var/lib/samba to /home/pi/samba
sudo ln -s /home/pi/data/samba /var/lib/samba
sudo chown -R root /home/pi/samba
sudo rm -r /var/cache/samba
mkdir /tmp/cache
mkdir /tmp/cache/samba
sudo ln -s /tmp/cache/samba /var/cache/samba

Reboot the Pi and check that the file system is in read only mode by typing

mount

if it is you will see something like

/dev/mmcblk0p2 on / type ext4 (ro,noatime,nodiratime,errors=remount-ro,data=ordered)

on the first line, the important thing is that it says "ro" after the first bracket.

All should now be working and you should be able to find your Pi file shares in windows by entering \\emonpi into explorer

Bill Thomson's picture

Re: Guide: How to enable Samba server on the Pi's read only file system

Hi Sheppy,

Have you looked into accessing your Pi from Windows?

Here's an article about 3 methods. One of them is does the job without the hassles of installation, i.e. you simply run the app. Here's the link: www.howtogeek.com/112888/3-ways-to-access-your-linux-partitions-from-windows/

sheppy's picture

Re: Guide: How to enable Samba server on the Pi's read only file system

Hi Bill,

I use Samba as it allows me to use the Openhab designer to access my Pi via the network from Windows to work on my live system for editing the rules etc. It runs so many things these days that I try and avoid taking it offline if possible.

Thanks for the informative article - I've used ext2fs before and it worked well 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.