Linux – Configure initramfs-tools to add curl to the initramfs, and run curl in a script at boot while in intitrd in Ubuntu 10.04 Server

initramfslinuxUbuntu

I'm trying to learn how the initramfs works and how it may be configured. I would like curl to be added to the packages available in the initramfs, and run a script which uses curl during boot (which means the network has to be set up, before it).

How should I do it? (I need it to work when upgrading my kernel too.)

Best Answer

You need to edit your initramfs hooks. Create your own file like so:

$ cat /usr/share/initramfs-tools/hooks/curl
#!/bin/sh -e
PREREQS=""
case $1 in
        prereqs) echo "${PREREQS}"; exit 0;;
esac
. /usr/share/initramfs-tools/hook-functions
copy_exec /usr/bin/curl /bin

Rebuild your initramfs:

$ sudo update-initramfs -u
update-initramfs: Generating /boot/initrd.img-3.8.0-4-generic

Check that it actually landed in there:

$ lsinitramfs -l /boot/initrd.img-3.8.0-4-generic | grep curl
-rw-r--r--   1 root     root       385704 Nov 28 18:32 usr/lib/x86_64-linux-gnu/libcurl.so.4
-rwxr-xr-x   1 root     root       150344 Nov 28 18:32 bin/curl