Jump to content

Recommended Posts

Posted

Hi,

 

I am currently working on a OLinuxIno A20 limeX system which works in read only mode.

 

I use the code I developped here: https://github.com/lauhub/debian-to-readonly

 

I have small problems with armbian evolutions, since it uses, creates and modifies some files in some directories that should not be modified according to this page.

 

Example of files :

 

  • /etc/init.d/armhwinfo (modifies permissions of /etc/logrotate.d/armhwinfo)
  • /sbin/fake-hwclock (creates /etc/fake-hwclock.data)
  • /etc/update-motd.d/40-updates
  • /usr/local/bin/armbianmonitor (modifies /etc/armbianmonitor/datasources/soctemp)

I can easily disable these files for my purposes, but I would be glad to help or discuss about how to integrate this "read only mode" into Armbian project.

 

Does it interest someone ?

 

Posted

Better than read only is overlay file system aka "virtual read only". If you use recent kernel:

apt-get install overlayroot
echo 'overlayroot="tmpfs"' >> /etc/overlayroot.conf
reboot

After reboot you can't make any permanent changes unless you use it within:

overlayroot-chroot

Overlay is done (with current settings) to RAM which is very fast but small. You can have overlay on any other device ...

Posted

Thank you for this lead. I had forgotten that solution.

 

Overlayfs was not OK for me two years ago, because of my needs of 3.4 kernel with NAND support. At that time, it was not as simple as you indicate (there were some patches, but it gave me some headaches). So I developed my own solution.

 

(it sounds like I re-invented the wheel ;) )

 

Do you know if there are consequences in term of speed, boot time, reliability, ram footprint (I will run a Java VM (or more on a 1Gb RAM machine)) ?

Posted
  Quote
Do you know if there are consequences in term of speed, boot time, reliability, ram footprint (I will run a Java VM (or more on a 1Gb RAM machine)) ?

 

If you can, rather use modern kernel but it works on our 3.4.x out of the box. I only made few tests but one of my friends is using this on several Cubietruck workstations with 3.4 and he just confirmed "yes it works perfectly".

Posted

Thanks,

 

I change hardware from NAND based A20-Lime to eMMC based ones. So I now use 4.x kernel. I will give it a try.

Posted

Hi again,

Sorry, but it seems that overlayroot package is not available for Debian (package is missing from both Jessie an Wheezy). Seems to be an Ubuntu only package.

 

As I am stuck (for now) to Debian, I have to use my solution.

Posted
  On 7/1/2016 at 2:13 PM, lauhub said:

Sorry, but it seems that overlayroot package is not available for Debian (package is missing from both Jessie an Wheezy). Seems to be an Ubuntu only package.

 

As I am stuck (for now) to Debian, I have to use my solution.

This package doesn't have any OS specific dependencies, so you should be able to install Ubuntu package on Debian manually without any issues.

Posted

Thank you for this info,

I will try it, hoping that the package version are not too old (initramfs-tools 0.109 under Wheezy, although 0.122 under Ubuntu Xenial).

 

I will try it with Trusty packages as soon as I have some time.

Posted

Hi Lauhub,

  On 7/1/2016 at 2:51 PM, lauhub said:

Thank you for this info,

I will try it, hoping that the package version are not too old (initramfs-tools 0.109 under Wheezy, although 0.122 under Ubuntu Xenial).

 

I will try it with Trusty packages as soon as I have some time.

Do you have success in using overlayfs to make rootfs read only on Armbian?

 

I am using Lime2-eMMC and latest Armbian (5.21), U-Boot (2016.09) and Kernel (4.7.6) and need to make rootfs read only when installed on eMMC and have:

  • SSD for system and data and make the system to boot from both eMMC and SSD;
  • succeeded to use overlayfs for merging read only and read/write data staff easily.

Unfortunately, described by Igor way is not possible because overlayfs-root packet is not in Debian.

In my opinion it is not good idea to rely on other distribution packages.

 

Any way did you try suggested by Zador way to install it in Armbian?

 

I am interested in getting work done with Armbian customization features only.

On the other hand read only root fs is a very frequent use case in embedded systems.

 

@Igor,

Is it possible to add overlayfs-root packet (will not be a precedent) in Armbian?

 

Best regards

Chris

 

Posted

Hi to All,

 

Is it possible to use bindfs as alternative of overlayfs to make root fs read only?

 

Best regards

Chris

Posted

Hi Igor,

  On 10/6/2016 at 12:17 PM, Igor said:

I can add this package to our repo if it works on Debian?

http://packages.ubuntu.com/xenial/overlayroot

I have installed manually overlayroot and change its configuration as mentioned above.

Before installation I have to install cryptsetup and cryptsetup-bin dependencies and installation had no problem.

 

After adding 'overlayroot="tmpfs"' to /etc/overlayroot.conf and reboot I try to test it by creating of some file in the root home directory.

Unfortunately, after rebooting the created file was still there and command 'overlayroot-chroot' says:

ERROR: Unable to find an overlayroot filesystem

which means there is something wrong.

 

Where could be the problem?

 

EDIT: I have removed the line for rootfs from /etc/fstab file for ability to support boot from any device without changing any files.

At overlayroot installation initrd.img was rebuild with warnings because of rootfs line lack in /etc/fstab file.

cryptsetup: WARNING: could not determine root device from /etc/fstab

Could it be the reason of the problem?

 

EDIT2: I try to install and configure overlayroot with rootfs line added to /etc/fstab and the installation (rebuilding initrd.img) completed without errors and warnings. Unfortunately, the problem is still there.

 

Best regards

Chris

Posted

Hi Igor,

  On 10/6/2016 at 12:17 PM, Igor said:

I can add this package to our repo if it works on Debian?

http://packages.ubuntu.com/xenial/overlayroot

 

I have tried to get overlayroot working with migration from Jessie to Xenial.

Unfortunately, the result is the same with a difference that overlayroot exists as a package in Ubuntu Xenial distribution.

 

Any ideas what is wrong?

 

Best regards

Chris

Posted

None. I made quick investigation and haven't found a solution. Anyway, there are at least two ways to go from here - close examine of overlayroot scripts or DIY. You need an overlay modules, which is build in and few proper mounts, which you can find in driver documentation. This way is also userspace independent and must work. It's just a bit more rough way.

Posted

Thanks Igor,

  On 10/7/2016 at 4:04 AM, Igor said:

None. I made quick investigation and haven't found a solution. Anyway, there are at least two ways to go from here - close examine of overlayroot scripts or DIY. You need an overlay modules, which is build in and few proper mounts, which you can find in driver documentation. This way is also userspace independent and must work. It's just a bit more rough way.

I have already used overlayfs to merge both RO and RW staff in a single directory used by our application. It was very easy to setup and it is working perfect.

 

Unfortunately, overlaying the root fs is more troublesome that is why I prefer to rely on a working and reliable solution.

 

Is it possible to use btrfs or bindfs as alternative of overlayfs to make root fs read only?

 

Best regards

Chris

Posted

Hi to All,

 

As Igor recommended I start looking into overlayroot package staff.

 

After a brief search I find that overlayroot is looking for overlayfs Kernel module which do not exists (trying with modeprobe).

In my experience the Kernel module is 'overlay' instead of 'overlayfs' and probably this is a problem.

 

On the other hand in overlayroot script '/usr/share/initramfs-tools/scripts/init-bottom/overlayroot' can be read:

# overlayroot_driver *could* be defined in one of the configs above
# but we're not documenting that.
overlayroot_driver=${overlayroot_driver:-overlayfs}

I try to put in /etc/overlayroot.config following line:

overlayroot_driver="overlay"

and add 'overlay' to /etc/modules abut without success in activating overlayroot.

 

May be it is related with initrd image usage for early preparation to mount of overlayed root.

By default it is not loaded because U-Boot searches for /boot/initramfs-linux.img file.

It is rising a question is there any special reason for the lack of the link to initrd.img-4.7.6-sunxi in /boot directory?

 

That why I make appropriate link:

cd /boot && ln -sf initrd.img-4.7.6-sunxi initramfs-linux.img

and reboot. After loading the initram disk following messages can be read:

Begin: Running /scripts/init-bottom ... Warning: overlayroot: debug is busted
Warning: overlayroot: configuring overlayroot with mode=tmpfs opts='' per /dev/mmcblk0p1/etc/overlayroot.conf
Failure: overlayroot: missing kernel module overlayfs
/scripts/init-bottom/plymouth: line 18: /bin/plymouth: not found

which shows that overlayroot is looking for overlayfs kernel module but it is missing. Even 'overlay' module is missing in initram disk image.

On the other hand it looks for overlayroot.conf file on /dev/mmcblk0p1/etc/ which may be a problem when booting from other device (eMMC, SSD etc.).

 

Did somebody have such a problem and find a proper solution?

 

Best regards

Chris

 

Posted

Hi to All,

 

After findings that overlayroot initialization is invoked in initram disk I have tried to make use of it in Jessie build by running:

cd /boot && ln -sf initrd.img-4.7.6-sunxi initramfs-linux.img

and after rebooting following is printed:

## Flattened Device Tree blob at 43000000
   Booting using the fdt blob at 0x43000000
   Loading Ramdisk to 49b93000, end 49fff18f ... OK
   Loading Device Tree to 49b84000, end 49b92f95 ... OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
Loading, please wait...
Begin: Loading essential drivers ... done.
Begin: Running /scripts/init-premount ... done.
Begin: Mounting root file system ... Begin: Running /scripts/local-top ... done.
Begin: Running /scripts/local-premount ... Scanning for Btrfs filesystems
done.
Begin: Will now check root file system ... fsck from util-linux 2.25.2
fsck: error 2 (No such file or directory) while executing fsck.ext4 for /dev/sda1
fsck exited with status code 8
done.
Warning: File system check failed but did not detect errors
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 ... trap: EXIT: bad trap
Warning: overlayroot: debug is busted
mount: No such file or directory
done.
Could not copy file: No such file or directory
No init found. Try passing init= bootarg.
Rebooting automatically due to panic= boot argument

and the system continuously reboots itself. Trying the same on a build without overlayroot installed the situation is the almost the same:

## Flattened Device Tree blob at 43000000
   Booting using the fdt blob at 0x43000000
   Loading Ramdisk to 49c25000, end 49fff4cd ... OK
   Loading Device Tree to 49c16000, end 49c24f95 ... OK

Starting kernel ...

Uncompressing Linux... done, booting the kernel.
Loading, please wait...
Begin: Loading essential drivers ... done.
Begin: Running /scripts/init-premount ... done.
Begin: Mounting root file system ... Begin: Running /scripts/local-top ... done.
Begin: Running /scripts/local-premount ... Scanning for Btrfs filesystems
done.
Begin: Will now check root file system ... fsck from util-linux 2.25.2
[/sbin/fsck.ext4 (1) -- /dev/mmcblk1p1] fsck.ext4 -a -C0 /dev/mmcblk1p1
/dev/mmcblk1p1: clean, 64029/228928 files, 291923/895744 blocks
done.
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= bootarg.
Rebooting automatically due to panic= boot argument

In my opinion there is some problem in default initram disk staff causing system panic and reboot.

 

On the other hand one of the problems in overlayroot is trying to use not existing 'overlayfs' module instead of existing 'overlay' one.

 

Last one is very rough difference with Kernel module name which is unlikely to be simply bug.

 

Does somebody knows working solution using overlayroot?

 

Best egards

Chris

 

Posted

Hi Chris,

I think I found at least a lead to that problem

 

There are some missing parts into the initramfs scripts / configuration problem in boot.cmd.

 

I experienced the same problem with a small difference

 

Investigation

 

To investigate the problem, I modified the /usr/share/initramfs-tools/init first line as follow (shell debug mode):

#!/bin/sh -x

To correct the problem, I did the following:

 

FIrst bug correction: creating the /root/dev mount point

 

I had to modify the script /usr/share/initramfs-tools/scripts/init-bottom/udev adding a line prior to the mount command:

#This line prevents the "mount: No such file or directory" error:
mkdir -p ${rootmnt}/dev

#The following mount call was leading to "mount: No such file or directory" error
#Creating the directory works better
# move the /dev tmpfs to the rootfs
mount -n -o move /dev ${rootmnt}/dev

Second bug: modification of boot.cmd

 

I changed my boot.cmd script. I replaced boot parameters PARTUUID=e8198e69-01 with the UUID value (root=UUID=abcdef-012345-abcdef-123456)

 

My script is (if I remember well) is close to the one you provided:

setenv verbosity 7
part uuid ${devtype} ${devnum}:${distro_bootpart} uuid

#Old line:
#setenv bootargs "console=${console} root="PARTUUID=${uuid}" rw rootwait nomodeset mac_addr=02:8f:06:c0:f4:31 loglevel=${verbosity} ${extended_bootargs}"

#New line
setenv bootargs "console=${console} root="UUID=6b742ea8-78e6-403f-8558-d57ec67755c4" rw rootwait nomodeset mac_addr=02:8f:06:c0:f4:31 loglevel=${verbosity} ${extended_bootargs}"

if load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} /boot/zImage; then
  if load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} /boot/dtb/${fdtfile}; then
    if load ${devtype} ${devnum}:${distro_bootpart} ${ramdisk_addr_r} /boot/initramfs-linux.img; then
      bootz ${kernel_addr_r} ${ramdisk_addr_r}:${filesize} ${fdt_addr_r};
    else
      bootz ${kernel_addr_r} - ${fdt_addr_r};
    fi;
  fi;
fi

if load ${devtype} ${devnum}:${distro_bootpart} 0x48000000 /boot/uImage; then
  if load ${devtype} ${devnum}:${distro_bootpart} 0x43000000 /boot/script.bin; then
    setenv bootm_boot_mode sec;
    bootm 0x48000000;
  fi;
fi
# Recompile with:
# mkimage -C none -A arm -T script -d boot.cmd boot.scr

This make my initramfs work.

 

Now, I have to make overlayfs work.

 

Conclusion

 

Two bugs, and two ways to correct the second one.

 

The second way:

 

I think it could be possible to retrieve UUID from PARTUUID in u-boot, but I don't know how to do this.

 

Another way could be to change the scripts/functions script (resolve_device function) by adding the PARTUUID parsing (line 327), and/or the scripts/local (function local_mount_root, line 152 adn 154, replacing "mount" with "mount -f ")

 

EDIT:

There is a bug about PARTUUID in Debian BTS: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=801154

 

Version 0.121 of initramfs-tools support PARTUUID

Posted

Hi again,

 

I successfully made overlayroot work under Debian Jessie.

 

Ubuntu package

 

I installed overlayroot_0.27ubuntu1.2_all.deb package

wget http://fr.archive.ubuntu.com/ubuntu/pool/main/c/cloud-initramfs-tools/overlayroot_0.27ubuntu1.2_all.deb
dpkg -i overlayroot_0.27ubuntu1.2_all.deb

Correcting overlayfs module name

 

About the following error:

Failure: overlayroot: missing kernel module overlayfs

I had to modify the /usr/share/initramfs-tools/scripts/init-bottom/overlayroot file:

Here is a diff:

diff --suppress-common-lines -r -y ./usr/share/initramfs-tools/scripts/init-bottom/overlayroot /usr/share/initramfs-tools/scripts/init-bottom/overlayroot
VARIABLES="overlayroot overlayroot_cfgdisk"                   | VARIABLES="overlayroot overlayroot_cfgdisk overlayroot_driver
        overlayfs)                                            |         overlayfs|overlay)
                mount_type="overlayfs"                        |                 mount_type="overlay"
                mount_opts="${mount_opts} overlayroot ${ROOTM |                 mount_opts="${mount_opts} overlay ${ROOTMNT}"
mount --move "${ROOTMNT}" "${root_ro}" ||                     | mount -o move "${ROOTMNT}" "${root_ro}" ||
        mount --move ${root_ro} ${ROOTMNT}                    |         mount -o move ${root_ro} ${ROOTMNT}
mount --move ${root_ro} "${ROOTMNT}${root_ro}" ||             | mount -o move ${root_ro} "${ROOTMNT}${root_ro}" ||
mount --move "${root_rw}" "${ROOTMNT}${root_rw}" ||           | mount -o move "${root_rw}" "${ROOTMNT}${root_rw}" ||

As you can see, I added one variable to the VARIABLES list and made some changes to mount parameters.

 

Here is the complete file:

 

  Reveal hidden contents

 

 

I modified the /usr/share/initramfs-tools/hooks/overlayroot:

diff --suppress-common-lines -r -y ./usr/share/initramfs-tools/hooks/overlayroot /usr/share/initramfs-tools/hooks/overlayroot
manual_add_modules overlayfs                                  | manual_add_modules overlay

Configuration

 

I added a file named /etc/overlayroot.local.conf (instead of modifying /etc/overlayroot.conf):

overlayroot_cfgdisk="disabled"
overlayroot="tmpfs"
overlayroot_driver="overlay"

Chrooting to R/W

 

Last but not least, I had to modify the overlayroot-chroot executable

diff --suppress-common-lines -r -y ./usr/sbin/overlayroot-chroot /usr/sbin/overlayroot-chroot
        overlay=$(grep -m1 "^overlayroot / overlayfs " /proc/ |         overlay=$(grep -m1 "^overlay / overlay " /proc/mounts

 

  Reveal hidden contents

 

 

Fast-forward

 

I attached an archive with the modifications.

 

Using

tar zxvf overlayroot-debian-lauhub.tar.gz -C / 

after package installation should do the trick

overlayroot-debian.tar.gzFetching info...

Posted

Hi Lauhub,

  On 11/12/2016 at 12:24 PM, lauhub said:

I successfully made overlayroot work under Debian Jessie.

 

Ubuntu package

 

I installed overlayroot_0.27ubuntu1.2_all.deb package

Why did you base your solution on Debian Jessie and Ubuntu overlayroot package while it is available in Xenial?

As I have noted here the problem is probably the same in both cases.

 

Any way I will try your modification a.s.a.p.

 

Best regards

Chris

Posted

Hi,

  On 11/13/2016 at 10:17 PM, chradev said:
Why did you base your solution on Debian Jessie and Ubuntu overlayroot package while it is available in Xenial?
 

 

Because all the work I have already done on my current project is based on Jessie

Posted

you can use unionfs-fuse, available on debian, that do the same stuff. I'm using it right now on several boards. You have to search on google how to conf it, but basically you need to unite the static and read-only /etc and /var with a temporary rw /etc /var that is mounted as tempfs file system. unionfs do that for you if you configure /usr/local/bin/mount_unionfs with

 

 

echo '[ -z "$1" ] && exit 1 || DIR=$1' > /usr/local/bin/mount_unionfs
echo 'ROOT_MOUNT=$(grep -v "^#" /etc/fstab | awk '"'"'$2=="/" {print substr($4,1,2)}'"'"')' >> /usr/local/bin/mount_unionfs
echo 'if [ "$ROOT_MOUNT" != "ro" ]; then' >> /usr/local/bin/mount_unionfs
echo '/bin/mount --bind ${DIR}_org ${DIR}' >> /usr/local/bin/mount_unionfs
echo 'else' >> /usr/local/bin/mount_unionfs
echo '/bin/mount -t tmpfs ramdisk ${DIR}_rw' >> /usr/local/bin/mount_unionfs
echo '/usr/bin/unionfs-fuse -o cow,allow_other,suid,dev,nonempty ${DIR}_rw=RW:${DIR}_org=RO ${DIR}' >> /usr/local/bin/mount_unionfs
echo 'fi' >> /usr/local/bin/mount_unionfs

chmod +x /usr/local/bin/mount_unionfs

 

 

and then switch to ro the partitions and add on fstab

 

 

mount_unionfs /etc fuse defaults 0 0

mount_unionfs /var fuse defaults 0 0

 

 

before it you need to create those 2 direcories and copy the static /etc and /var on them, you can do that by:

 

cp -al /etc /etc_org
mv /var /var_org
mkdir /etc_rw
mkdir /var /var_rw

 

Posted

Thanks for your suggestion Dottgonzo,

  On 11/21/2016 at 2:17 PM, dottgonzo said:

you can use unionfs-fuse, available on debian, that do the same stuff. I'm using it right now on several boards...

I tried it and succeeded out-of-the-box following your description also applied for RPi.

 

Of course there was a small obstacle because in my use case rootfs options are transferred from uboot to kernel via its command line but it can be solved by a small change in mount_unionfs script.

 

Fortunately, simplicity and long life time (9+ years) of the project are more important for me at the moment than possible speed lost.

 

The only question for now is can we rely on Debian support to continue?

 

Best regards

Chris

Posted

Thanks Dottgonzo,

  On 11/23/2016 at 9:24 AM, dottgonzo said:

on unionfs rely many projects, relax :)

After your words I am definitely more peaceful.

 

Best regards

Chris

Posted

Does this work? How is it done? Is there any guide for dummies?
Ubuntu xenial is not valid for me for missing php5 and something else, but if it works overlayroot. I really liked how it works.
In debian jessie with kernel 4.8.4 it works but I want to freeze the system. I just need to make overlayroot work.

PD: On behalf of google, sorry for the translation.

Posted

@lauhub

 

I am facing SD card corruption problem on power off (https://forum.armbian.com/index.php/topic/3427-armbian-sd-card-image-gets-corrupted-when-power-off-without-proper-shutdown/.

 

I am following your steps to make my rootfs read only with overlayfs  debian jessie/orange pi zero.  However I am not able to make it readonly. If I save any file and reboot file is present. There are some differences from your setup so looking forward to your help comment.

 

Your scripts in the attachment is expected to be applied on overlayroot_0.27ubuntu1.2_all.deb however this package is replaced with overlayroot_0.27ubuntu1.3_all.deb and it has some changes so not able to apply your changes directly. 

 

If you have a copy of overlayroot_0.27ubuntu1.2_all.deb can you please provide it Or if you have any suggestion to make it work on overlayroot_0.27ubuntu1.3_all.deb please let me know.

 

Based on diffs you provided I made changes, while I do not see any error, I am not able to make it readonly.

 

Thanks 

Posted

Same problem with me @gailu. :( Were you able to solve this? 
I too couldn't find overlayroot_0.27ubuntu1.2_all.deb and I just can't get overlayroot_0.27ubuntu1.3_all.deb to work with modifications based on @lauhub's patch

Posted

Solusion for overlayroot in Armbian Jessie:

 

1) install overlayroot_0.27ubuntu1.4_all.deb

dpkg -i overlayroot_0.27ubuntu1.4_all.deb

 

2) add following lines to /usr/share/initramfs-tools/hooks/overlayroot file:

 

copy_exec /bin/grep /bin
copy_exec /usr/bin/stat /bin
copy_exec /bin/echo /bin

 

This will load missing tools required by /usr/share/initramfs-tools/scripts/init-bottom/overlayroot script.

 

3) replace all "mount --move" with "mount -o move" in /usr/share/initramfs-tools/scripts/init-bottom/overlayroot file.

 

4) update-initramfs -u

 

:-)

overlayroot_0.27ubuntu1.4_all.deb

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines