3

I've been hacking on a Raspberry Pi with an Ubuntu 15.04 image. Since I've got an encrypted boot setup, I need to generate an initramfs.gz image in the first partition of the filesystem, which is the plaintext boot device.

Ubuntu automatically generates initramfs images in /boot/initrd.img-$(uname -r). Is there a hook that I can catch with a script so I can automatically copy the latest built image over to /boot/firmware/initramfs.gz?

1

2 Answers 2

2

Read initramfs-tools manual and write a hook script. You can look at system supplied scripts placed in /usr/share/initramfs-tools/hooks/ for your reference. Your own script should go in /etc/initramfs-tools/hooks/. Scripts in both folders are merged and executed resolving its dependencies by mkinitramfs.

In a temporary folder, you can generate initramfs and examine its contents.

mkinitramfs -o initramfs.gz
zcat initramfs.gz | cpio -id initramfs.gz

Once it looks ready, update system initramfs in /boot using update-initramfs -u.

EDIT: I misunderstood your problem.

You can see hook script dirs in /etc/kernel which are called by postinst/postrm/preinst/prerm scripts of each kernel package. update-initramfs is invoked in /etc/kernel/postinst.d/initramfs-tools, so you can add another script there which will be called after initramfs-tools.

5
  • 1
    IIRC, the hooks are executed during build of the initramfs. I'm looking for something which executes after the build is completed with preferably an environment variable pointing to the new image. Can I do that with a hook like that? I could just use a hook, does it pass the kernel version in? Commented Jun 4, 2015 at 3:02
  • Worse yet, calling mkinitramfs from an initramfs hook will likely cause an endless loop and crash the system, fill the process tree, and fill the disk. Commented Jun 4, 2015 at 3:04
  • Oh, I misunderstood your problem, sorry for that. It would be difficult to do in the hook script. Symlinks are not useful either?
    – yaegashi
    Commented Jun 4, 2015 at 3:30
  • A symlink isn't useful, unfortunately, as it's on a different block device. Commented Jun 4, 2015 at 3:47
  • 1
    @NaftuliTzviKay Updated my answer. Use /etc/kernel/postinst.d/ hooks.
    – yaegashi
    Commented Jun 4, 2015 at 4:21
1

I know, this is an old question, but I was looking for an answer to the same question and this is it:

Use a script in /etc/initramfs/post-update.d/

It isn't well documented for Ubuntu but it is for Debian as described in this question. The update-initramfs script checks if that directory exists and runs scripts in that directory after creating the initramfs.

First create the directory:

mkdir -p /etc/initramfs/post-update.d

And in your case the script would be:

/etc/initramfs/post-update.d/zz-copy-to-firmware

#!/bin/sh
cp /boot/initrd.img-$(uname -r) /boot/firmware/initramfs.gz

and make it executable:

chmod +x /etc/initramfs/post-update.d/zz-copy-to-firmware

Note: Ubuntu creates a symlink to the latest initramfs in /boot/initrd.img, so you could use that in the script instead of querying uname -r.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .