I would like to create an initramfs image for Debian Stretch which includes additional configuration files (say /etc/a.conf
).
What do I have to do prior to running mkinitramfs -o initrd.img
in order for the image to include such files?
I have chosen to do this with an initramfs hook for this ensures (if I understand correctly) that the change will also persist across future kernel upgrades. The hook takes the form of a script /etc/initramfs-tools/hooks/copy_etc
as follows:
#!/bin/sh -e
if [ "$1" = "prereqs" ]; then exit 0; fi
. /usr/share/initramfs-tools/hook-functions
cp /etc/a.conf $DESTDIR/etc/a.conf
The tool you want for modifying the initrd/initramfs is called cpio. You can find a bunch of tutorials on this out on the internet, now that you know what to look for. Here's a quick example:
mkdir initrd-tmp
cd initrd-tmp
lzma -dc -S .lz /mnt/casper/initrd.lz | cpio -id
And then when done:
find . | cpio --quiet --dereference -o -H newc | lzma -7 > ~/new-initrd.lz
Source: https://wiki.ubuntu.com/CustomizeLiveInitrd
Note that a fun property of cpio archives is that you can simply append to them and later files overwrite earlier files—probably due to their heritage as a file system for tape archival. So if you don't want the hassle of actually unpacking the whole archive (especially as it may require root to create paths like /proc
), you can simply append your customization files to it. See:
https://wiki.debian.org/DebianInstaller/NetbootFirmware#Example_.231:_add_debs_from_firmware.cpio.gz