1

I'm working on a custom version of initramfs for RaspberryPi 3, where I'd like to run some commands to validate CPU serial number and other validations before start init process itself.

I was trying to modify /usr/share/initramfs-tools/scripts files but after running update-initramfs, my Linux system crashes of kernel boot and I have to create a new Raspbian image to make it work again.

Someone here had this kind of issue trying to do this and could give me a hand and give some references doing this kind of customization?

I appreciate any comments and links.

Best, Cesar.

2 Answers2

3

I'm using an initramfs for a long time. I need it for Easy backups and snapshots of a running system with LVM to load the lvm driver before mounting the root partition. But it is a little bit dangerous because automatic updating a initramfs isn't supported by Raspbian. The trigger of installing software packages to update-initramfs simply does not work. You have always to take attention on updates for kernel packages, drivers and modules that may be needed for booting and then you have to create the initramfs by hand. I had a look at the trigger function but have given up after a short time. If you find a way to adapt it to Raspbian, that would be great.

For now I have attention if one of these packages are updated:

rpi ~$ apt list *raspberrypi*
Listing... Done
libraspberrypi-bin/stable,now 1.20180924-1 armhf [installed]
libraspberrypi-dev/stable,now 1.20180924-1 armhf [installed]
libraspberrypi-doc/stable,now 1.20180924-1 armhf [installed]
libraspberrypi0/stable,now 1.20180924-1 armhf [installed]
raspberrypi-archive-keyring/stable 2016.10.31 all
raspberrypi-artwork/stable 20150921 all
raspberrypi-bootloader/stable,now 1.20180924-1 armhf [installed]
raspberrypi-kernel/stable,now 1.20180924-1 armhf [installed]
raspberrypi-kernel-headers/stable 1.20180924-1 armhf
raspberrypi-net-mods/stable,now 1.2.7 all [installed]
raspberrypi-sys-mods/stable,now 20180328+1 armhf [installed]
raspberrypi-ui-mods/stable 1.20180706 all

Another important indicator is:

rpi ~$ uname -r
4.14.70-v7+

and

rpi ~$ ls /lib/modules
4.14.71+  4.14.71-v7+

If this differ then the modules where updated but the old kernel is still running. If you boot now with your old initramfs.gz then you are lost. To make a new initramfs I execute:

rpi ~$ sudo mkinitramfs -o /boot/initramfs.gz -v 4.14.71-v7+

If you are unsure that you have updated the initramfs you can look with lsinitramfs /boot/initramfs.gz what modules are in it. And yes, only for the completeness for other readers: you have to insert a line with initramfs initramfs.gz (without =) into /boot/config.txt to use it.

Ingo
  • 40,606
  • 15
  • 76
  • 189
0

The stock Pi kernel doesn't use an initramfs, because the predominant use for such is to load drivers appropriate to the hardware in cases where the kernel is being used on a wide variety of machines (such as a normal linux distro is). It's done that way because the drivers may be mutually exclusive, and packing them all into the kernel itself would produce an excessively large binary.

Since the Pi kernel is only used on the pi, there is no need to provide a variety of loadable modular drivers for the kernel to pick from. The necessary set is just built into the kernel.

However, you can use an initramfs, but you'll need to compile your own kernel too, since I believe the stock one does not have support for such (but I could be wrong about that, I did not check).

So why doing this would leave the machine unbootable is a good question. It could be that update-initramfs did something bad to the boot partition mounted on /boot, since it is likely identical to the stock Debian version which is intended for something different.

goldilocks
  • 56,430
  • 17
  • 109
  • 217