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

Re: Raspbian with Read-only Root

Fri Apr 21, 2017 2:58 am

I started with a newly installed image

# uname -a
Linux raspberry 4.4.50-v7+ #911 SMP Thu Sep 15 14:22:38 BST 2016 armv7l GNU/Linux

then ran through the process, rebooted and the system hung on startup, right after recognizing the keyboard.

Undid the changes then did it all over again. Same result. Repeat 7-8 times. Same result.

Any ideas?

User avatar
TimG
Posts: 285
Joined: Tue Apr 03, 2012 12:15 am
Location: Switzerland

Re: Raspbian with Read-only Root

Fri Apr 21, 2017 9:34 am

TMcB wrote:Any ideas?
The recipe works, so all I can suggest is checking the modifications you made and the permissions of the new files. For example:

Code: Select all

ls -l /usr/share/initramfs-tools/hook-functions
grep -B4 -A3 usbhid /usr/share/initramfs-tools/hook-functions

ls -l /usr/share/initramfs-tools/scripts/overlay
diff /usr/share/initramfs-tools/scripts/local /usr/share/initramfs-tools/scripts/overlay

ls -l /usr/share/initramfs-tools/scripts/overlay-premount

ls -l /boot/initrd7.img

grep img /boot/config.txt

cat /boot/cmdline.txt
Be sure there are no line-breaks in cmdline.txt

lpsmith
Posts: 2
Joined: Mon Apr 24, 2017 7:53 pm

Re: Raspbian with Read-only Root

Mon Apr 24, 2017 8:05 pm

Hello,

Once performed all steps described the system gets an error when tries to execute the init script. I get the following messages:

Code: Select all

mount: No such file or directory
done.
Target filesystem doesn't have requested /sbin/init.
Begin: Running /scripts/local-bottom ... done.
Begin: Running /scripts/init-bottom ... mount: No such file or directory
done.
Could not copy file: No such file or directory
No init found. Try passing init= bootargs.
(initramfs)
Seems that the mount operation of the /lower filesystem fails, and consequently fails the init execution.

Can anybody help to solve this problem?

The rasp is the model 3B and the raspbian release date 2017-04-10.

Thank you in advance

kami
Posts: 2
Joined: Tue Apr 25, 2017 6:23 pm

Re: Raspbian with Read-only Root

Tue Apr 25, 2017 6:45 pm

lpsmith wrote:
Can anybody help to solve this problem?

The rasp is the model 3B and the raspbian release date 2017-04-10.
Hi,

check /boot/cmdline.txt ... there must be root=/dev/mmcblk0p2 (not root=PARTUID=something_something)...

And I had to change order of parameters in "overlay" script, part "mount overlay" (not sure why)

Code: Select all

mount -olowerdir=/lower,upperdir=/upper/data,workdir=/upper/work -t overlay overlay ${rootmnt}
thanks for the guide, helped a lot

User avatar
TimG
Posts: 285
Joined: Tue Apr 03, 2012 12:15 am
Location: Switzerland

Re: Raspbian with Read-only Root

Wed Apr 26, 2017 1:23 pm

kami wrote: check /boot/cmdline.txt ... there must be root=/dev/mmcblk0p2 (not root=PARTUID=something_something)...
Good catch. I had not spotted the change to cmdline.txt in the 2017-04-10 Raspbian image.
The PARTUUID= parameter trips up the initramfs scripts, in particular the function resolve_device() in /usr/share/initramfs-tools/scripts/functions
This is fixed in initramfs-tools 0.121 - see https://lists.debian.org/debian-kernel/ ... 00538.html
Debian Jessie is still on initramfs-tools 0.120, so for now it's best to modify cmdline.txt as kami describes.

PS. Kami, could you double check your /usr/share/initramfs-tools/scripts/overlay? I found I did not need to modify the mount overlay parameters.

kami
Posts: 2
Joined: Tue Apr 25, 2017 6:23 pm

Re: Raspbian with Read-only Root

Thu Apr 27, 2017 1:18 pm

TimG wrote: PS. Kami, could you double check your /usr/share/initramfs-tools/scripts/overlay? I found I did not need to modify the mount overlay parameters.
You are right, changes in "mount overlay" are not needed. When I was trying to write mount commands in initramfs console by hand, only this worked, but probably i had some typing errors...

Thanks for the explanation, what's wrong with PARTUUID.

daboross
Posts: 1
Joined: Sat Apr 29, 2017 7:07 am

Re: Raspbian with Read-only Root

Sat Apr 29, 2017 7:48 am

Would anyone be able to help with setting this up on an older Pi? I have a "minimal" raspbian install downloaded today installed on a Raspberry Pi B - I have the service I want to run working, but I can't seem to set up this overlay correctly.

I realize the hardware is a bit old, but it's what I have available, and it has been working fine - just want to add some extra reliability with this. I tried to complete the guide, with removing the '7's at the end of the kernel/initrd since it's an armv6 board, but it does not boot successfully with the `config.txt` changes.

If I use `ramfsfile=initrd.img` instead of `initramfs initrd.img` it does boot, but does not have the overlay. Looking at https://www.raspberrypi.org/documentati ... xt/boot.md, I thought that this would be equivalent, but apparently not. I don't really know how to debug the not booting, especially since the only input/output I have is either inspecting the sdcard or an ssh connection (no compatible screens nor keyboard).

Edit: After finding a screen to plug into to debug, I seem to have fixed this!

The problem was the latest image has 'root=PARTUUID=...' in `/boot/cmdline.txt', and 'root=/dev/mmcblk0p2' is needed for initramfs images to work correctly. Thanks to viewtopic.php?f=63&t=161416&start=50 for having this problem already and fixing it.

Thank you for making this guide, glad I can have more reliability with the pi!

lpsmith
Posts: 2
Joined: Mon Apr 24, 2017 7:53 pm

Re: Raspbian with Read-only Root

Tue May 02, 2017 5:45 pm

kami wrote:
lpsmith wrote:
Can anybody help to solve this problem?

The rasp is the model 3B and the raspbian release date 2017-04-10.
Hi,

check /boot/cmdline.txt ... there must be root=/dev/mmcblk0p2 (not root=PARTUID=something_something)...

And I had to change order of parameters in "overlay" script, part "mount overlay" (not sure why)

Code: Select all

mount -olowerdir=/lower,upperdir=/upper/data,workdir=/upper/work -t overlay overlay ${rootmnt}
thanks for the guide, helped a lot
Thanks kami, it solves the problem of the overlay root mounting on the raspbian release 2017-04-10.
Finally I decided to not implement the overlayfs over the root directory, as I get a bad behaviour umounting the overlay when I need to install or update any other software. I was looking for something that allows me to quickly mount and umount the writing layer.

I finally use the ovelayfs over the /etc and /var (using a custom service) and mount / and /boot as readonly (using fstab), which finally works like a charm.

I would like to share the mountOverlays service, as it could be useful for other people.
The mountOverlays.sh script, which is used to create a tmpfs as upper filesystem and mount the overlay:

Code: Select all

#!/bin/bash
### BEGIN INIT INFO
# Provides:          blabla
# Required-Start:    $syslog
# Required-Stop:     $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: blabla
# Description:
#
### END INIT INFO

#List of directories to bury
DIRS="/etc /var"

lsmod | grep -q overlay
if [ $? -ne 0 ] ; then
   modprobe overlay
fi

for dir in $DIRS ; do
   if ! mountpoint -q $dir ; then
      #Create upper fs
      [ ! -d ${dir}_upper ] && mkdir ${dir}_upper
      if ! mountpoint -q "${dir}_upper/" ; then
         mount -o defaults -t tmpfs $tmpfs ${dir}_upper
      fi  

      #Create upper and workdir
      [ ! -d ${dir}_upper/work ] && mkdir ${dir}_upper/work
      [ ! -d ${dir}_upper/data ] && mkdir ${dir}_upper/data

      mount -o defaults,lowerdir=${dir},upperdir=${dir}_upper/data,workdir=${dir}_upper/work -t overlay overlay ${dir}
   else
      echo "${dir} already mounted"
   fi  
done
Now any time I need to edit some file under /etc or /var and store it in the sd card, I firstly umount the overlay using the following script (umountOverlays.sh):

Code: Select all

#!/bin/bash

DIRS="/etc /var"

for dir in $DIRS ; do
   if mountpoint -q $dir ; then
      #Umount merged fs
      umount -l ${dir}
   else
      echo "${dir} already unmounted"
   fi  
done
Then move these scripts to /sbin/ to be accessible from the cli. To run the mountOverlays.sh script at boot time, make symbolic links using the commands:

Code: Select all

ln -s /sbin/mountOverlays.sh /etc/init.d/mountOverlays.sh
ln -s /etc/init.d/mountOverlays.sh /etc/rc3.d/S17mountOverlay.sh
For some reason raspbian does not let me mount a tmpfs on /etc_upper and /var_upper if they are not present in the fstab file. So adding the following lines to the fstab file:

Code: Select all

tmpfs           /etc_upper      tmpfs   defaults,noatime,nosuid,nodev,noexec,mode=1777  0       0
tmpfs           /var_upper      tmpfs   defaults,noatime,nosuid,nodev,noexec,mode=1777  0       0
Finally, create the upper directories used on the fstab:

Code: Select all

mkdir /etc_upper /var_upper

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

Re: Raspbian with Read-only Root

Wed May 03, 2017 4:02 am

lpsmith, I'm a little dense. Does your script work on it's own, or meant as an addition to ejolson's work?

larcam
Posts: 2
Joined: Sat May 06, 2017 11:56 am

Re: Raspbian with Read-only Root

Sat May 06, 2017 12:04 pm

Just tried this procedure and it booted. But how do I determine if it actually worked?

Thanks

User avatar
TimG
Posts: 285
Joined: Tue Apr 03, 2012 12:15 am
Location: Switzerland

Re: Raspbian with Read-only Root

Sat May 06, 2017 4:26 pm

'df' or 'mount' will show that / is an overlay filesystem. Something like this:

Code: Select all

 $ df
Filesystem     1K-blocks    Used Available Use% Mounted on
udev               10240       0     10240   0% /dev
tmpfs              46836    4476     42360  10% /run
overlay           117080     320    116760   1% /
tmpfs             117080       0    117080   0% /dev/shm
tmpfs               5120       4      5116   1% /run/lock
tmpfs             117080       0    117080   0% /sys/fs/cgroup
/dev/mmcblk0p1     64456   49288     15168  77% /boot
You can also try creating a file, check it exists, reboot, and check it is gone. Something like this:

Code: Select all

 $ date > thing.txt
 $ sync; echo -n 3 | sudo tee /proc/sys/vm/drop_caches; sync # flush caches
 $ cat thing.txt # check ramdisk overlay is working
Sat May  6 18:20:49 CEST 2017
 $ sudo reboot
[...]

Code: Select all

 $ cat thing.txt # check SD card was not modified
cat: thing.txt: No such file or directory

larcam
Posts: 2
Joined: Sat May 06, 2017 11:56 am

Re: Raspbian with Read-only Root

Sat May 06, 2017 7:21 pm

Thanks TimG! Looks like it does what it is supposed to do.

propergol
Posts: 21
Joined: Mon Aug 15, 2016 1:39 pm

Re: Raspbian with Read-only Root

Mon May 15, 2017 9:46 am

Many thanks for this thread ejolson !
I am building a small wifi radio and I was first after clean shutdown and power up push button.
Then reading this thread I did realized that this was a much easier solution for me.

Just a side note : I follow the first post instructions but it is not ultra clear :mrgreen: on some part if we need to replace all code or just modify it.
Anyway I did manage to get it working.
Reverting to writable state also works perfectly for me, at least for installing new packages.

One question : is it normal that the /boot folder is still writable?
I am still able for example to write some changes inside the /boot/config.txt

User avatar
jbeale
Posts: 3469
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Raspbian with Read-only Root

Fri May 19, 2017 3:57 pm

Excellent work. For my first few years of RPi I did not experience SD card corruption, and I did not understand why people complained about it. This past year, having done quite a few deployments using applications doing a lot of file I/O over time, I've had four different SD cards become corrupt, so it's now a big issue for me. I believe this approach should absolutely be available as a setup option in Raspbian.

User avatar
jbeale
Posts: 3469
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Raspbian with Read-only Root

Sat May 20, 2017 2:32 pm

Trying to follow the instructions in the top post, but hit a snag here:

Code: Select all

# cd /usr/share/initramfs-tools/scripts
# cp local overlay
# cp -rp local-premount overlay-premount
# cp -rp local-bottom overlay-bottom
The last line fails because /usr/share/initramfs-tools/scripts/local-bottom does not exist on the current Raspbian Lite (just updated as of today). Do I just leave that line out, or has the name changed and I need to use something else?

uname -a: Linux raspberry 4.9.24+ #993 Wed Apr 26 17:56:54 BST 2017 armv6l GNU/Linux

EDIT: Nevermind, I see upon reading further to just leave it out. And also to change the root=PARTUUID... part in "cmdline.txt" back to root=/dev/mmcblk0p2

Just realized I left out the last part of the 4th group, in my case cd /boot ; mv initrd.img-4.9.24+ initrd.img
after that, success!

Code: Select all

[email protected]:~ $ df
Filesystem     1K-blocks   Used Available Use% Mounted on
udev               10240      0     10240   0% /dev
tmpfs              75916   4524     71392   6% /run
overlay           189788 103904     85884  55% /
tmpfs             189788      0    189788   0% /dev/shm
tmpfs               5120      4      5116   1% /run/lock
tmpfs             189788      0    189788   0% /sys/fs/cgroup
/dev/mmcblk0p1     41322  26904     14419  66% /boot
/dev/sda1       29916756  53052  28320972   1% /home/pi/pikrellcam/media

miguel.g123
Posts: 1
Joined: Mon Jun 12, 2017 4:15 pm

Re: Raspbian with Read-only Root

Mon Jun 12, 2017 4:31 pm

lpsmith wrote:Hello,

Once performed all steps described the system gets an error when tries to execute the init script. I get the following messages:

Code: Select all

mount: No such file or directory
done.
Target filesystem doesn't have requested /sbin/init.
Begin: Running /scripts/local-bottom ... done.
Begin: Running /scripts/init-bottom ... mount: No such file or directory
done.
Could not copy file: No such file or directory
No init found. Try passing init= bootargs.
(initramfs)
Seems that the mount operation of the /lower filesystem fails, and consequently fails the init execution.

Can anybody help to solve this problem?

The rasp is the model 3B and the raspbian release date 2017-04-10.

Thank you in advance
I'm running Raspbian 4.9.24-v7+ and I too am having this same issue where I follow the guide exactly and my Pi won't boot. So far none of the solutions are working for me, I checked that

Code: Select all

 root=/dev/mmcblk0p2 
and I also changed the parameter order for the "mount overlay" part as suggested by kami to no avail. Any suggestions?

User avatar
chrisoh
Posts: 217
Joined: Sun Dec 06, 2015 8:50 pm
Location: Essex, UK

Re: Raspbian with Read-only Root

Tue Jul 18, 2017 5:41 pm

miguel.g123 wrote:
lpsmith wrote:Hello,

Once performed all steps described the system gets an error when tries to execute the init script. I get the following messages:

Code: Select all

mount: No such file or directory
done.
Target filesystem doesn't have requested /sbin/init.
Begin: Running /scripts/local-bottom ... done.
Begin: Running /scripts/init-bottom ... mount: No such file or directory
done.
Could not copy file: No such file or directory
No init found. Try passing init= bootargs.
(initramfs)
Seems that the mount operation of the /lower filesystem fails, and consequently fails the init execution.

Can anybody help to solve this problem?

The rasp is the model 3B and the raspbian release date 2017-04-10.

Thank you in advance
I'm running Raspbian 4.9.24-v7+ and I too am having this same issue where I follow the guide exactly and my Pi won't boot. So far none of the solutions are working for me, I checked that...
That makes three of us. Using Pi Zero and 4.9.35+ here. Anybody have some tipperoos :?:
Raspberry Pi 3 model B Idle @ 250mA
  • HDMI +200mA
  • Minecraft 1.9 Server +100mA
  • 2.4Ghz dongle +20mA

TheComputerGuyLTD
Posts: 2
Joined: Wed Jul 19, 2017 2:11 pm

Re: Raspbian with Read-only Root

Wed Jul 19, 2017 2:15 pm

There seems to be a change to the hook-functions file in the latest versions!

Code: Select all

 for arg in "[email protected]" ; do
                case "$arg" in
                base)
                        modules="$modules btrfs ext2 ext3 ext4 ext4dev "
Where do I put overlay now that used to go into this line -

modules="$modules ehci-pci ehci-orion ehci-hcd ohci-hcd ohci-pci uhci-hcd usbhid overlay"


?

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Raspbian with Read-only Root

Wed Jul 19, 2017 6:25 pm

TheComputerGuyLTD wrote:There seems to be a change to the hook-functions file in the latest versions!

Code: Select all

 for arg in "[email protected]" ; do
                case "$arg" in
                base)
                        modules="$modules btrfs ext2 ext3 ext4 ext4dev "
Where do I put overlay now that used to go into this line -

modules="$modules ehci-pci ehci-orion ehci-hcd ohci-hcd ohci-pci uhci-hcd usbhid overlay"


?
While it's the same, I added a new line:

Code: Select all

modules="$modules overlay"

TheComputerGuyLTD
Posts: 2
Joined: Wed Jul 19, 2017 2:11 pm

Re: Raspbian with Read-only Root

Thu Jul 20, 2017 9:32 am

Ah excellent, as simple as that!

I'll give that a go.

Thank you.

User avatar
chrisoh
Posts: 217
Joined: Sun Dec 06, 2015 8:50 pm
Location: Essex, UK

Re: Raspbian with Read-only Root

Sun Jul 23, 2017 1:13 am

TheComputerGuyLTD wrote:There seems to be a change to the hook-functions file in the latest versions!

Code: Select all

 for arg in "[email protected]" ; do
                case "$arg" in
                base)
                        modules="$modules btrfs ext2 ext3 ext4 ext4dev "
Where do I put overlay now that used to go into this line -

modules="$modules ehci-pci ehci-orion ehci-hcd ohci-hcd ohci-pci uhci-hcd usbhid overlay"


?
Good catch! I tagged overlay onto the end of one of the existing $modules lines and it seems to be working with Pi Zero and 4.9.35+ now.
Raspberry Pi 3 model B Idle @ 250mA
  • HDMI +200mA
  • Minecraft 1.9 Server +100mA
  • 2.4Ghz dongle +20mA

Heater
Posts: 12959
Joined: Tue Jul 17, 2012 3:02 pm

Re: Raspbian with Read-only Root

Sun Jul 30, 2017 8:35 pm

I finally got around to trying the ro root with overlay instructions of the opening post.

How can I get it to work when my Raspbian does not have an overlay module?!

# uname -a
Linux raspberrypi-5 4.9.35-v7+ SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux

The update-initranfs command complains about ... overlay.ko not found.

A simple modprobe overlay also fails.

What to do?

Heater
Posts: 12959
Joined: Tue Jul 17, 2012 3:02 pm

Re: Raspbian with Read-only Root

Sun Jul 30, 2017 11:16 pm

OK. I'm using raspbian lite. Some bugger removed the overlay lernel module from raspbian lite.

So, I snagged the overlay kernel module from a full raspbian image and put it on my lite image.

The following the OP instructions the initrd builds cleanly now. All looks well. But on reboot files are still persistently changed on the SD card.

What to do?

What can I check?

User avatar
TimG
Posts: 285
Joined: Tue Apr 03, 2012 12:15 am
Location: Switzerland

Re: Raspbian with Read-only Root

Sun Jul 30, 2017 11:42 pm

I haven't yet applied the recipe to the latest Raspbian Lite image, but I did take a quick look at the kernel modules and overlay.ko is there. Could it be that your image didn't get written properly?

Code: Select all

$ ls -l /mnt/tmp/lib/modules/*/kernel/fs/overlayfs/
/mnt/tmp/lib/modules/4.9.35+/kernel/fs/overlayfs/:
total 64
-rw-r--r-- 1 root root 62476 Jul  3 12:07 overlay.ko

/mnt/tmp/lib/modules/4.9.35-v7+/kernel/fs/overlayfs/:
total 64
-rw-r--r-- 1 root root 64160 Jul  3 12:07 overlay.ko

User avatar
chrisoh
Posts: 217
Joined: Sun Dec 06, 2015 8:50 pm
Location: Essex, UK

Re: Raspbian with Read-only Root

Sun Jul 30, 2017 11:46 pm

Heater wrote:
Sun Jul 30, 2017 11:16 pm
OK. I'm using raspbian lite. Some bugger removed the overlay lernel module from raspbian lite.

So, I snagged the overlay kernel module from a full raspbian image and put it on my lite image.

The following the OP instructions the initrd builds cleanly now. All looks well. But on reboot files are still persistently changed on the SD card.

What to do?

What can I check?
I used a fresh install of the latest Raspbian Jessie Lite on a Pi Zero 1.3 a few days ago and (with the edit mentioned above) it works as expected afaict. Is there anything particularly different about your setup?
Raspberry Pi 3 model B Idle @ 250mA
  • HDMI +200mA
  • Minecraft 1.9 Server +100mA
  • 2.4Ghz dongle +20mA

Return to “General discussion”