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.)


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

$ cat /usr/share/initramfs-tools/hooks/curl
#!/bin/sh -e
case $1 in
        prereqs) echo "${PREREQS}"; exit 0;;
. /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
  • 1
    This is a good start (installing curl) however it doesn't explain how to run a script during boot – thom_nic Jul 16 '18 at 18:35

First thing you wanna know is that Ubuntu is using a system called Upstart instead of the traditional init. The initial ramdisk is still used, but you'll be reconfiguring upstart instead of init.

Second, are you wanting to do this entirely within the context of an initrd? If so, this would be much more complicated.

  • 1
    I actually new about Upstart, but thanks for the heads up. I have also learned that initrd isn't used with the 2.6 kernels, it's initramfs nowdays. And yes, I do want to do this inside the initramfs. What I am actually trying to do is more complicated than using curl, but it's a step in the right direction. I am trying to make it possible to login using SSH and provide the cryptphrase from my encrypted LVM. – Deleted Jun 20 '10 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.