1

I'm currently using a slightly modified script https://github.com/JasperE84/root-ro for booting system from squashfs image. It works almost as expected.

It does boot to the new read-only filesystem from the image, however, it boots with the kernel from the "main" system, the system that initramfs was built on it. I tried with the switch_root command from initramfs, but I can't get it working, actually since this script creates overlay I don't think I should use switch_root at all.

Could somebody help me with an idea or solution on how to boot to the kernel that is in the read-only image instead of the one that initramfs was built with?

Uros

Uros
  • 61
  • 5
  • The more I think about it the more it seems that my way is not correct. My next idea of how to solve this is to broke initramfs boot select/overlay script into two parts. The first part - on the main boot partition I should just check and load the image and switch to it with switch_root command. And then on read-only image, again initramfs root-ro script that will establish overlay. I'm not sure at the moment if switch_root will go to full boot process of the image - will it start initramfs on the image? Uros – Uros Apr 08 '21 at 06:31

1 Answers1

0

If you want to use the kernel inside a squashfs file, you either need a boot loader that can read squashfs files, or you need to use kexec to start on a kernel that your boot loader can read and jump into a kernel from any filesystem that the first kernel can read.

To elaborate on the kexec option, you would have

  • A kernel and initramfs stored normally in the boot partition on a common filesystem
  • A simple init script in the initramfs that would mount the squashfs file and then find the new kernel
  • Call kexec to switch to the new kernel
  • Run another initramfs that again mounts the squashfs, (because it was lost during kexec) initializes the overlay like in your example, and finish booting the system

switch_root might still be needed in the second initramfs, but it only changes the view of the filesystem for userspace. It doesn't change kernels.

U-Boot could simplify this by loading the initial kernel directly from the squashfs file, but I've never used it and don't know if it is compatible with raspberry pi, so I can't make recommendations.

dataless
  • 388
  • 4
  • 9