Where can I configure which binaries update-initramfs copies into the /sbin directory inside the initrd image?

I have been looking under /etc/initramfs-tools and /usr/lib/initramfs-tools but couldn't find the list of binaries anywhere

# grep -ri sbin /etc/initramfs-tools
# grep -ri sbin /usr/lib/initramfs-tools

You have to use the entries in /usr/share/initramfs-tools/hooks. These files are executed when you type update-initramfs. Create your own hook script or remove scripts.

Another folder is /etc/initramfs-tools/hook

From man initramfs-tools

   Hooks can be found in two places: /usr/share/initramfs-tools/hooks  and
   /etc/initramfs-tools/hooks.  They are executed during generation of the
   initramfs-image and are responsible for  including  all  the  necessary
   components  in the image itself. No guarantees are made as to the order
   in which the different scripts are  executed  unless  the  prereqs  are
   setup in the script.

Note, the hook-scripts are part of the packages, e.g. kmod. The package creates the file kmod in /usr/share/initramfs-tools/hooks.

Sample script

#!/bin/sh -e
# Copy the compatibility symlinks until initramfs-tools will be converted
# to use the kmod program.

if [ "$1" = "prereqs" ]; then exit 0; fi

. /usr/share/initramfs-tools/hook-functions

copy_exec /bin/kmod
cp -a /sbin/modprobe /sbin/rmmod $DESTDIR/sbin/

mkdir -p $DESTDIR/lib/modprobe.d/
if [ "$(echo /lib/modprobe.d/*)" != "/lib/modprobe.d/*" ]; then
  cp -a /lib/modprobe.d/* $DESTDIR/lib/modprobe.d/

As you can see, the hook-script copies all files in /lib/modprobe.d/ into initramfs/lib/modprobe.d/

cp -a /lib/modprobe.d/* $DESTDIR/lib/modprobe.d/

and modprobe into initramfs/sbin

cp -a /sbin/modprobe /sbin/rmmod $DESTDIR/sbin/

Your own initrd.img with one file foo

mkdir initrd
cd initrd
touch foo   # an example file
find . | cpio -o -H newc > ../initrd.img
cd ..
gzip initrd.img
cp initrd.img.gz initrd.img

Check the content of your initrd.img

mkdir initrd_out
cd initrd_out
cpio -i < ../initrd.img

And with ls you should see one file

% ls
| improve this answer | |
  • Thank you! I also found a directory for hooks in /etc/initramfs-tools/hooks, I might try placing my own hook there instead? – lara michaels Oct 10 '15 at 17:52
  • Updated my answer – A.B. Oct 10 '15 at 17:56
  • Is removing scripts the "correct" thing to do? Is there any way to create an override? I notice that the hooks are set +x so I can just remove that to disable them, but a package update might re-enable them. – Ken Sharp May 1 at 10:49

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.