psuter
Posts: 2
Joined: Mon Jan 30, 2017 1:57 pm

Readonly Root with OverlyFS

Mon Jan 30, 2017 2:23 pm

I recently had a Raspberry Pi where the ext4 root filesystem was destroyed beyond repair due to a loose contact on the power connector which led to many cold-resets. I noticed that an ext4 formatted SD card is less than ideal to run in a headless appliance where nobody ever issues a clean shutdown before unplugging it. I am sure that I'm not the only one out there who is using RPI's mainly as such headless appliances and I therefore think that a distribution such as Raspbian, which was specifically designed to run on the RPI should include a mechanism to avoid SD card corruption in such environments.
I have therefore written a small script that can be used as alternate init script which will mount the root filesystem from the SD card in read-only mode and then use overlayFS to overlay a writeable ramdisk on top of it. this means, that all applications will be able to write whatever logs and temp files they need wherever they usually do it but in the same time the contents of the sd card will be protected against alteration and corruption. of course this also means, that in order to store any data permanently one would need to create a second partiton on the sd card where data is stored and wirte to that partition rather than the root filesystem.

the script can simply be enabled by adding "init=/sbin/overlayRoot.sh" to the end of cmdline.txt. No further changes are necessary and by removing the init= entry it can be disabled agin to perform changes on the OS for mainenance or updates.

I would like to propose adding my script to the Raspbian distribution, so that people can simply enable it when needed with the above mentioned entry in cmdline.txt.

Also i would like to ask the maintainers of the raspbian images to take a look at f2fs as an alternative filesystem since raspbian will probably run out of flash memory (sd card or usb stick) in almost all installs out there and f2fs is especially optimized and supposedly even faster than ext4 in on flash media.

here is a link to my script and the description of it:
http://wiki.psuter.ch/doku.php?id=solve ... _partition

spock
Posts: 205
Joined: Sun Oct 02, 2011 10:33 am

Re: Readonly Root with OverlyFS

Fri Feb 03, 2017 1:46 pm

thanks for posting this! :)
yes, it would be nice if something like this was added to raspbian. or maybe even to raspi-config?

spock
Posts: 205
Joined: Sun Oct 02, 2011 10:33 am

Re: Readonly Root with OverlyFS

Mon Mar 27, 2017 5:50 pm

your script doesn't seem to work anymore with the newest raspbian. do you have an idea why?

psuter
Posts: 2
Joined: Mon Jan 30, 2017 1:57 pm

Re: Readonly Root with OverlyFS

Mon Mar 27, 2017 11:03 pm

i dont, especially sice i've installed my last raspbian on march 3 just after the current version must have been published and the script woked as expected.
what is the error you are seeing?
regards
pascal

bitz
Posts: 4
Joined: Tue May 27, 2014 7:21 pm

Re: Readonly Root with OverlyFS

Tue Apr 18, 2017 5:04 pm

I am also having an issue with your script. Seems to be a Kernel panic
---[ end Kernel panic - not syncing: Requested init /sbin/overlayRoot.sh failed (error -2).

Recent version of Jessi light. Perhaps Ill try a fresh image, as I was messing with this one a little first

binlanden
Posts: 1
Joined: Wed Apr 19, 2017 6:08 am

Re: Readonly Root with OverlyFS

Wed Apr 19, 2017 6:17 am

Hi, i have tried clean images (LXDE installed) with Jessie Lite 10.4.2017 and 27.2.2017. Both gives same errors: Kernel Panic - not syncing: Requested init /sbin/overlayRoot.sh failed (error -2).

TMcB
Posts: 5
Joined: Fri Apr 21, 2017 2:43 am

Re: Readonly Root with OverlyFS

Fri Apr 21, 2017 9:13 pm

I'm also getting the Kernel panic.

Freshly built system from 2017-04-10 raspbian-jessie image.

I suspect one of the following may be the case:
- recent change in the distribution creating a conflict with the procedure
- a system change to *your* system upon which the procedure is dependent.

Would LOVE to see this working ...

TMcB
Posts: 5
Joined: Fri Apr 21, 2017 2:43 am

Re: Readonly Root with OverlyFS

Sat Apr 22, 2017 4:01 am

OK, I think I know what the problem is.

First, I believe the kernel panic is caused by downloading the overlayRoot.sh script using a Windows browser, then copying the file to the RPi. The windows download insert's ^Ms (ctrl-M, aka carriage-return) at EOL. Not sure how or why that results in a panic, but it seems to be the cause.

Either download directly from a network connected RPi or run the file through an appropriate filter to remove the ^M line terminators.

Second, the fragment of code that identifies the root file system block device (circa line 76) relies on the first field of /etc/fstab, which is in the form "PARTUUID=cee13cfa-01":

Code: Select all

# mount root filesystem readonly 
rootDev=`awk '$2 == "/" {print $1}' /etc/fstab`
rootMountOpt=`awk '$2 == "/" {print $4}' /etc/fstab`
rootFsType=`awk '$2 == "/" {print $3}' /etc/fstab`
mount -t ${rootFsType} -o ${rootMountOpt},ro ${rootDev} /mnt/lower
if [ $? -ne 0 ]; then
    fail "ERROR: could not ro-mount original root partition"
fi
That doesn't work for the following mount(8).

I changed that fragment to utilize blkid(8) to grab the device name:

Code: Select all

# Identify root fs device, PARTUUID, mount options and fs type
rootDev=`blkid -o list | awk '$3 == "/" {print $1}'`
rootPARTUUID=`awk '$2 == "/" {print $1}' /etc/fstab`
rootMountOpt=`awk '$2 == "/" {print $4}' /etc/fstab`
rootFsType=`awk '$2 == "/" {print $3}' /etc/fstab`


# Mount original root filesystem readonly under /mnt/lower
mkdir /mnt/lower
mount -t ${rootFsType} -o ${rootMountOpt},ro ${rootDev} /mnt/lower
if [ $? -ne 0 ]; then
    fail "ERROR: could not ro-mount original root partition"
fi
I kept the logic to extract the PARTUUID since it's used later in the script (circa line 91):

Code: Select all

# remove root mount from fstab (this is already a non-permanent modification)
grep -v "$rootDev" /mnt/lower/etc/fstab > /mnt/newroot/etc/fstab
echo "#the original root mount has been removed by overlayRoot.sh" >> /mnt/newroot/etc/fstab
echo "#this is only a temporary modification, the original fstab" >> /mnt/newroot/etc/fstab
echo "#stored on the disk can be found in /ro/etc/fstab" >> /mnt/newroot/etc/fstab
Here's another version of overlayRoot.sh for convenience. It's essentially the same as the original, with the aforementioned changes. I also made some minor changes to the comments, just to clarify for myself what was going on as I was going through it:

Code: Select all

#!/bin/sh
#  Read-only Root-FS for Raspian using overlayfs
#  Version 1.0
#
#  Created 2017 by Pascal Suter @ DALCO AG, Switzerland
#  to work on Raspian as custom init script
#  (raspbian does not use an initramfs on boot)
#
#  Modified 2017-Apr-21 by Tony McBeardsley 
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see
#    <http://www.gnu.org/licenses/>.
#
#
#  Tested with Raspbian mini, 2017-01-11
#
#  This script will mount the root filesystem read-only and overlay it with a temporary tempfs 
#  which is read-write mounted. This is done using the overlayFS which is part of the linux kernel 
#  since version 3.18. 
#  when this script is in use, all changes made to anywhere in the root filesystem mount will be lost 
#  upon reboot of the system. The SD card will only be accessed as read-only drive, which significantly
#  helps to prolong its life and prevent filesystem coruption in environments where the system is usually
#  not shut down properly 
#
#  Install: 
#  copy this script to /sbin/overlayRoot.sh and add "init=/sbin/overlayRoot.sh" to the cmdline.txt 
#  file in the raspbian image's boot partition. 
#  I strongly recommend to disable swapping before using this. it will work with swap but that just does 
#  not make sens as the swap file will be stored in the tempfs which again resides in the ram.
#  run these commands on the booted raspberry pi BEFORE you set the init=/sbin/overlayRoot.sh boot option:
#  sudo dphys-swapfile swapoff
#  sudo dphys-swapfile uninstall
#  sudo update-rc.d dphys-swapfile remove
#
#  To install software, run upgrades and do other changes to the raspberry setup, simply remove the init= 
#  entry from the cmdline.txt file and reboot, make the changes, add the init= entry and reboot once more. 

fail(){
	echo -e "$1"
	/bin/bash
}


# Load overlay module
modprobe overlay
if [ $? -ne 0 ]; then
    fail "ERROR: missing overlay kernel module"
fi


# Mount /proc
mount -t proc proc /proc
if [ $? -ne 0 ]; then
    fail "ERROR: could not mount proc"
fi


# Create a writable fs on /mnt to then create our mountpoints 
mount -t tmpfs inittemp /mnt
if [ $? -ne 0 ]; then
    fail "ERROR: could not create a temporary filesystem to mount the base filesystems for overlayfs"
fi


# Mount a tmpfs under /mnt/rw
mkdir /mnt/rw
mount -t tmpfs root-rw /mnt/rw
if [ $? -ne 0 ]; then
    fail "ERROR: could not create tempfs for upper filesystem"
fi



# Identify root fs device, PARTUUID, mount options and fs type
rootDev=`blkid -o list | awk '$3 == "/" {print $1}'`
rootPARTUUID=`awk '$2 == "/" {print $1}' /etc/fstab`
rootMountOpt=`awk '$2 == "/" {print $4}' /etc/fstab`
rootFsType=`awk '$2 == "/" {print $3}' /etc/fstab`


# Mount original root filesystem readonly under /mnt/lower
mkdir /mnt/lower
mount -t ${rootFsType} -o ${rootMountOpt},ro ${rootDev} /mnt/lower
if [ $? -ne 0 ]; then
    fail "ERROR: could not ro-mount original root partition"
fi


# Mount the overlay filesystem
mkdir /mnt/rw/upper
mkdir /mnt/rw/work
mkdir /mnt/newroot
mount -t overlay -o lowerdir=/mnt/lower,upperdir=/mnt/rw/upper,workdir=/mnt/rw/work overlayfs-root /mnt/newroot
if [ $? -ne 0 ]; then
    fail "ERROR: could not mount overlayFS"
fi


# Create mountpoints inside the new root filesystem-overlay
mkdir /mnt/newroot/ro
mkdir /mnt/newroot/rw

# Remove root mount from fstab (this is already a non-permanent modification)
grep -v "$rootPARTUUID" /mnt/lower/etc/fstab > /mnt/newroot/etc/fstab
echo "#the original root mount has been removed by overlayRoot.sh" >> /mnt/newroot/etc/fstab
echo "#this is only a temporary modification, the original fstab" >> /mnt/newroot/etc/fstab
echo "#stored on the disk can be found in /ro/etc/fstab" >> /mnt/newroot/etc/fstab


# Change to the new overlay root
cd /mnt/newroot
pivot_root . mnt
exec chroot . sh -c "$(cat <<END

	# Move ro and rw mounts to the new root
	mount --move /mnt/mnt/lower/ /ro
	if [ $? -ne 0 ]; then
	    echo "ERROR: could not move ro-root into newroot"
	    /bin/bash
	fi
	mount --move /mnt/mnt/rw /rw
	if [ $? -ne 0 ]; then
	    echo "ERROR: could not move tempfs rw mount into newroot"
	    /bin/bash
	fi

	# Unmount unneeded mounts so we can unmout the old readonly root
	umount /mnt/mnt
	umount /mnt/proc
	umount /mnt/dev
	umount /mnt

	# Continue with regular init
	exec /sbin/init
END
)"
Good luck with it!

gello
Posts: 5
Joined: Tue Apr 25, 2017 1:29 am

Re: Readonly Root with OverlyFS

Tue Apr 25, 2017 1:42 am

simple setup compared to my current readonly method. works great as long as hdmi is plugged in and active. with no hdmi plugged in it hangs on boot. when i hotplug the hdmi in the hung boot process the screen has errors about "no job control". sounds like it needs a controlling tty for the overlayRoot.sh shell to execute. any hints on how to get around this one? readonly root is particularly useful on headless embedded systems so this would be quite useful.

gello
Posts: 5
Joined: Tue Apr 25, 2017 1:29 am

Re: Readonly Root with OverlyFS

Tue Apr 25, 2017 1:53 am

Tried this out. Works well with hdmi connected.
When using without hdmi monitor, the system hangs on boot.
During the hang, if i hot plug the monitor, the following error is on the screen:

sh: cannot set terminal process group (-1): Inappropriate ioctl for device
sh: no job control in this shell

Using in headless embedded system where power goes often, yours is a far simpler solution than
my previous one if I can get it to work without hdmi.
thanks
gello

TMcB
Posts: 5
Joined: Fri Apr 21, 2017 2:43 am

Re: Readonly Root with OverlyFS

Tue Apr 25, 2017 6:57 am

Have you tried redirecting stdin, stdout and stderr to /dev/null (or log files)?

gello
Posts: 5
Joined: Tue Apr 25, 2017 1:29 am

Re: Readonly Root with OverlyFS

Tue Apr 25, 2017 2:00 pm

i will try that tonight. i dont think it will work.
i assume the init= is an exec so there is no shell to do the redirection. i tried invoking overlay with a sh -c /sbin/overlayRoot.sh to force a non interactive shell but that paniced the kernel immediately.

i can write a cstub to fix stdin stdout and set a process group then invoke shell then your script then finally exec init but hoping for something simpler to solve this in keeping with your script.

and yes i vote for an addition to raspi-config. i use read only root on a dozen pi's doing off grid control functions on heavy equipment with iffy power. latest version of raspbian jessie broke them all for readonly using an initramfs as i have been doing for 2 yrs. be nice to have official support so new releases dont require recode.

gello
Posts: 5
Joined: Tue Apr 25, 2017 1:29 am

Re: Readonly Root with OverlyFS

Fri Apr 28, 2017 6:57 pm

this is what i used previously.
https://gist.github.com/kidapu/a03dd5bb ... 28bacde1d3

just fixed a problem with device naming and now it works again on raspbian jessie. semi supported on github and part of utils in several linux versions so should be around a while till rpi officially supports ro.

mnt points are sane in mount table and accessible in filesystem for dynamic remount rw without reboot which is handy when you edit files and forget you are ro.

swap is handled dynamically instead of just turned off.

works headless fine.

your overlayRoot is simple, no mkinitfs nonsense but im going to have to stub it to go headless.

cheerio.

TMcB
Posts: 5
Joined: Fri Apr 21, 2017 2:43 am

Re: Readonly Root with OverlyFS

Sat Apr 29, 2017 2:34 am

gello wrote:Tried this out. Works well with hdmi connected.
When using without hdmi monitor, the system hangs on boot.
During the hang, if i hot plug the monitor, the following error is on the screen:

sh: cannot set terminal process group (-1): Inappropriate ioctl for device
sh: no job control in this shell
What is displayed immediately before these two lines? Any complaints from mount(8)?

I'm seeing the same thing when trying to boot from a USB thumb drive. I'm thinking it's got to do with the difference in blkid(8) output between sd card and USB drive root file systems.

gello
Posts: 5
Joined: Tue Apr 25, 2017 1:29 am

Re: Readonly Root with OverlyFS

Tue May 02, 2017 3:48 pm

if u are referring to overlayRoot.sh than no, no mount complaints all control tty issues only.

on root-ro, yes. mount issues. raspbian went to using PARTID in cmdline .txt which chokes the script. correct soln is to make script use partids. quick soln was to simply change my cmdline.txt back to spec'ing root as /dev/mmcblkp02. (check that dev name spelling, on the road now and cant look). everything went back to working.

Sompom
Posts: 1
Joined: Wed May 31, 2017 9:02 pm

Re: Readonly Root with OverlyFS

Wed May 31, 2017 9:21 pm

Could I make the suggestion to, instead of reading /etc/fstab, read /proc/mounts? There's no promise mounted filesystems are going to be in /etc/fstab, but they should be in /proc/mounts (For instance, in the case of netbooting, where the rootfs is passed on the command line)
Additionally, for the case of netbooting, trying to parse rootMountOpts and rootDev is a pain (Maybe just because I don't know awk), but you can do a bind mount of the old root to /mnt/lower -- bind mounts survive even the source being unmounted.
In other words, the script I have is:

Code: Select all

#!/bin/sh
#  Read-only Root-FS for Raspian using overlayfs
#  Version 1.0
#
#  Created 2017 by Pascal Suter @ DALCO AG, Switzerland
#  to work on Raspian as custom init script
#  (raspbian does not use an initramfs on boot)
#
#  Modified 2017-Apr-21 by Tony McBeardsley
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see
#    <http://www.gnu.org/licenses/>.
#
#
#  Tested with Raspbian mini, 2017-01-11
#
#  This script will mount the root filesystem read-only and overlay it with a temporary tempfs
#  which is read-write mounted. This is done using the overlayFS which is part of the linux kernel
#  since version 3.18.
#  when this script is in use, all changes made to anywhere in the root filesystem mount will be lost
#  upon reboot of the system. The SD card will only be accessed as read-only drive, which significantly
#  helps to prolong its life and prevent filesystem coruption in environments where the system is usually
#  not shut down properly
#
#  Install:
#  copy this script to /sbin/overlayRoot.sh and add "init=/sbin/overlayRoot.sh" to the cmdline.txt
#  file in the raspbian image's boot partition.
#  I strongly recommend to disable swapping before using this. it will work with swap but that just does
#  not make sens as the swap file will be stored in the tempfs which again resides in the ram.
#  run these commands on the booted raspberry pi BEFORE you set the init=/sbin/overlayRoot.sh boot option:
#  sudo dphys-swapfile swapoff
#  sudo dphys-swapfile uninstall
#  sudo update-rc.d dphys-swapfile remove
#
#  To install software, run upgrades and do other changes to the raspberry setup, simply remove the init=
#  entry from the cmdline.txt file and reboot, make the changes, add the init= entry and reboot once more.

fail(){
	echo -e "$1"
		/bin/bash
}


# Load overlay module
modprobe overlay
if [ $? -ne 0 ]; then
fail "ERROR: missing overlay kernel module"
fi


# Mount /proc
mount -t proc proc /proc
if [ $? -ne 0 ]; then
fail "ERROR: could not mount proc"
fi


# Create a writable fs on /mnt to then create our mountpoints
mount -t tmpfs inittemp /mnt
if [ $? -ne 0 ]; then
fail "ERROR: could not create a temporary filesystem to mount the base filesystems for overlayfs"
fi


# Mount a tmpfs under /mnt/rw
mkdir /mnt/rw
mount -t tmpfs root-rw /mnt/rw
if [ $? -ne 0 ]; then
fail "ERROR: could not create tempfs for upper filesystem"
fi



# Identify root fs device, PARTUUID, mount options and fs type
rootDev=`blkid -o list | awk '$3 == "/" {print $1}'`
rootPARTUUID=`awk '$2 == "/" {print $1}' /proc/mounts`
rootMountOpt=`awk '$2 == "/" {print $4}' /proc/mounts`
rootFsType=`awk '$2 == "/" {print $3}' /proc/mounts`


# Mount original root filesystem readonly under /mnt/lower
mkdir /mnt/lower
mount -o bind,ro / /mnt/lower
if [ $? -ne 0 ]; then
fail "ERROR: could not ro-mount original root partition"
fi


# Mount the overlay filesystem
mkdir /mnt/rw/upper
mkdir /mnt/rw/work
mkdir /mnt/newroot
mount -t overlay -o lowerdir=/mnt/lower,upperdir=/mnt/rw/upper,workdir=/mnt/rw/work overlayfs-root /mnt/newroot
if [ $? -ne 0 ]; then
fail "ERROR: could not mount overlayFS"
fi


# Create mountpoints inside the new root filesystem-overlay
mkdir /mnt/newroot/ro
mkdir /mnt/newroot/rw

# Remove root mount from fstab (this is already a non-permanent modification)
grep -v "$rootPARTUUID" /mnt/lower/etc/fstab > /mnt/newroot/etc/fstab
echo "#the original root mount has been removed by overlayRoot.sh" >> /mnt/newroot/etc/fstab
echo "#this is only a temporary modification, the original fstab" >> /mnt/newroot/etc/fstab
echo "#stored on the disk can be found in /ro/etc/fstab" >> /mnt/newroot/etc/fstab


# Change to the new overlay root
cd /mnt/newroot
pivot_root . mnt
exec chroot . sh -c "$(cat <<END

# Move ro and rw mounts to the new root
mount --move /mnt/mnt/lower/ /ro
if [ $? -ne 0 ]; then
echo "ERROR: could not move ro-root into newroot"
/bin/bash
fi
mount --move /mnt/mnt/rw /rw
if [ $? -ne 0 ]; then
echo "ERROR: could not move tempfs rw mount into newroot"
/bin/bash
fi

# Unmount unneeded mounts so we can unmout the old readonly root
umount /mnt/mnt
umount /mnt/proc
umount /mnt/dev
umount /mnt

# Continue with regular init
exec /sbin/init
END
)"
Where the difference between that and the latest version you published is

Code: Select all

--- /tmp/overlayRoot.sh	2017-05-31 15:14:32.364329557 -0600
+++ /tftpboot/rpi_debian/rootfs/sbin/overlayRoot.sh	2017-05-31 15:12:08.430672049 -0600
@@ -84,14 +84,14 @@
 
 # Identify root fs device, PARTUUID, mount options and fs type
 rootDev=`blkid -o list | awk '$3 == "/" {print $1}'`
-rootPARTUUID=`awk '$2 == "/" {print $1}' /etc/fstab`
-rootMountOpt=`awk '$2 == "/" {print $4}' /etc/fstab`
-rootFsType=`awk '$2 == "/" {print $3}' /etc/fstab`
+rootPARTUUID=`awk '$2 == "/" {print $1}' /proc/mounts`
+rootMountOpt=`awk '$2 == "/" {print $4}' /proc/mounts`
+rootFsType=`awk '$2 == "/" {print $3}' /proc/mounts`
 
 
 # Mount original root filesystem readonly under /mnt/lower
 mkdir /mnt/lower
-mount -t ${rootFsType} -o ${rootMountOpt},ro ${rootDev} /mnt/lower
+mount -o bind,ro / /mnt/lower
 if [ $? -ne 0 ]; then
 fail "ERROR: could not ro-mount original root partition"
 fi
With my version of the script, I am able to netboot following* the instructions here: https://www.raspberrypi.org/documentati ... utorial.md
as well as normal sdcard boot a brand new Raspbian Lite image.

Also, you are my hero of the day :) . Thanks very much for the base script!

*Actually, I didn't follow those instructions because I needed a totally different setup, but the idea is pure...

ingeniapp
Posts: 4
Joined: Thu Jan 21, 2016 3:07 pm
Location: Madrid, Spain

Re: Readonly Root with OverlyFS

Thu Jun 01, 2017 3:25 pm

I find your script very useful, thank you very much.
But I have some question about how this work.

I've tested script and when raspbian finish booting I can see two partitions:
root-rw with 462MB and writable
mmcblk0p2 (7.2GB for 8GB sdcard) and read-only

I understand that the writable partition is on ram, and if I make changes to the system, e.g. apt-get update, the system work over root-rw partition, and the changes will be lost on the next reboot. So, I should prepare the system with the packages I needed and the software I developed to later modify the cmdline.txt and apply the overlayRoot. I'm right?

What happend with system logs? If these are modified in /var/log (by default) will be lost every reboot. Another doubt that worries me is about create a third partition to save no volatile info and its repercussion on wear leveling. When creating the partition, we will have less space in the microsd, reason why the probability of corruption is greater. If the third partition were to be corrupted, would the system continue to boot or give an error during startup by blocking the system waiting a user interaction (normally a 'run fsck manually')?

Thanks for your great work

tjlusco
Posts: 10
Joined: Sun Feb 12, 2017 3:32 am

Re: Readonly Root with OverlyFS

Wed Jun 21, 2017 3:08 am

Just an update,

I'd been using this method for read-only FS quite successfully for some time.
https://gist.githubusercontent.com/niun ... 13/root-ro

Updated some images to 2017-04-10-raspbian-jessie-lite.img, and the image would no longer boot.

What seems to have changed is how the root mount is found, inside /boot/cmdline there is the new entry root=PARTUUID=21d82248-02. If you change this to root=/dev/mmcblk0p2 as per gello's suggestion, everything works again. I'm not sure any other side effects of doing this. Older images did not have any entry for root=, but changing it to nothing does not fix the problem.

Kidapu's update is quite nice, it's just changing how the initramfs is loaded. Using this method means that you do not have to redo update-initramfs if you change between a pizero and a pi3 (they use different kernels, different images). The different initramfs method doesn't fix the mounting issue though.
https://gist.github.com/kidapu/a03dd5bb ... 28bacde1d3

RE: ingeniapp
So, I should prepare the system with the packages I needed and the software I developed to later modify the cmdline.txt and apply the overlayRoot. I'm right?
Correct. Set the cmdline flag, reboot, make changes, remove flag, reboot. Quick changes can be made by re-mounting the root filesystem as per instructions in /etc/fstab (in readonly).

Syslogs will obviously now be temporary. Apparently (I've never been able to confirm this), the biggest issue with SD cards is the internal wear leveling which can happen on any write. If it happens on an unexpected shutdown you can lose data, but this could be anything on the SD card, not just what was written. Simply repartitioning with a log partition will not stop this form of data loss.

I've been using the boot partition for storing application configuration which only changes occasionally, seems relatively low risk. Writing log files however occurs quite frequently, thus enabling a write partition just for logs will probably negate any benefit of using a read-only file system. A better solution would be to use a usb mounted drive if you really need logging.

racer993
Posts: 60
Joined: Mon Feb 18, 2013 7:27 pm

Re: Readonly Root with OverlyFS

Tue Jan 02, 2018 11:01 am

I tried the script on a fresh raspbian-lite image (Strectch 2017-11-29) which didn't seem to work. I was still able to write to the home directory.

Is the script not compatible with the new Raspbian Stretch?

jacob.alberty
Posts: 3
Joined: Wed Jan 24, 2018 9:36 pm

Re: Readonly Root with OverlyFS

Wed Jan 24, 2018 10:03 pm

@racer which script did you try they should all allow writing to the filesystem, you just lose it when you reboot? there've been a couple in here. I had good luck with https://gist.github.com/kidapu/a03dd5bb ... 28bacde1d3 . I modified it to support jumpering a gpio pin for a read/write fs then pull jumper and its back to read only. Modifications are posted here https://github.com/jacobalberty/root-ro

nalbee
Posts: 10
Joined: Fri Jan 19, 2018 5:02 am

which is better overlay or this other method?

Fri Jan 26, 2018 5:10 am

Looking to have a nice read-only system that I can unplug and not worry about it dying when its deployed. I'm finding that there are a few different ways to go and not sure what is accurate or the best practice to achieve this goal.

How does Overlay compare to this approach? What do you think?

Overlay FS vs
http://hallard.me/raspberry-pi-read-only/
https://petr.io/en/blog/2015/11/09/read ... th-jessie/
http://k3a.me/how-to-make-raspberrypi-t ... uble-free/

And does anyone have a guide for Stretch (not Lite) for pi3b.

boelle
Posts: 224
Joined: Wed May 01, 2013 11:52 am

Re: Readonly Root with OverlyFS

Tue Nov 06, 2018 8:04 pm

i'm using this on the latest raspbian stretch image and i also get an error

i thought a pic would say more than words

https://photos.app.goo.gl/SCSbzyUQexqht8Qe9


also tried the version of the script by @TMcB

and the scrip was updated 25.10.2018 http://wiki.psuter.ch/doku.php?id=solve ... the_script

will read through the thread and try the other versions

ejolson
Posts: 3244
Joined: Tue Mar 18, 2014 11:47 am

Re: which is better overlay or this other method?

Tue Nov 06, 2018 11:17 pm

nalbee wrote:
Fri Jan 26, 2018 5:10 am
Looking to have a nice read-only system that I can unplug and not worry about it dying when its deployed. I'm finding that there are a few different ways to go and not sure what is accurate or the best practice to achieve this goal.

How does Overlay compare to this approach? What do you think?

Overlay FS vs
http://hallard.me/raspberry-pi-read-only/
https://petr.io/en/blog/2015/11/09/read ... th-jessie/
http://k3a.me/how-to-make-raspberrypi-t ... uble-free/

And does anyone have a guide for Stretch (not Lite) for pi3b.
There is also the method outlined here, which is similar. In my opinion, the method you understand is the best to use, because then you can fix it when it breaks.

boelle
Posts: 224
Joined: Wed May 01, 2013 11:52 am

Re: Readonly Root with OverlyFS

Tue Nov 06, 2018 11:35 pm

I ended up using the adafruit script (https://learn.adafruit.com/read-only-raspberry-pi/)

I dont need to understand it, it just have to work.

The pi(a zero wireless) is controlling an electrical heating panel and over the last year i have spent time getting the PCB desing correct
I'm a trained electrician myself and also i know a chartered engineer so no saftety lectures please :D

The pi and PCB are a drop in replacement of the org. electronics which was prone to overheating and failing, and also was very unprecise. With the pi i have +/- 0.2 degree precission and on top of that i have a central pi that is running emoncms (logging), each heating panel reports in every minute


so once settings etc are dialed in it will pretty much stay in read mode an only VERY rare will settings like target temp be changed

ejolson
Posts: 3244
Joined: Tue Mar 18, 2014 11:47 am

Re: Readonly Root with OverlyFS

Wed Nov 07, 2018 5:52 pm

boelle wrote:
Tue Nov 06, 2018 11:35 pm
I dont need to understand it, it just have to work.
Congratulations on fixing your heating panel. Did you include some sort of hysteresis so the Pi doesn't turn the panel on and off too frequently?

The idea that it is easier to make something work which you don't understand than it is to first understand and then make it work seems a common one. Although driving a car is often cited as proof of such a belief, people actually know more about how cars work than they care to admit. For example, most people know the wheels need to point downward toward the ground rather than towards the sky. On the other hand, many people actually know much less about how computers work than they care to admit. Imagine trying to drive a car that was upside down and not knowing it.

Return to “Raspbian”