Skip to content

Instantly share code, notes, and snippets.

@mallardduck
Last active April 8, 2022 16:44
Show Gist options
  • Save mallardduck/9645ec7847e1743bef43dc0d456a9ac7 to your computer and use it in GitHub Desktop.
Save mallardduck/9645ec7847e1743bef43dc0d456a9ac7 to your computer and use it in GitHub Desktop.
How to unpack and modify/customize the initrd (using zstd compression)
export LANG=C
TMP=`mktemp -d`
umask 022
mkdir -p $TMP/earlycpio
mkdir $TMP/initramfs
umask 077
cd $TMP/earlycpio
chmod 755 $TMP/earlycpio
cat /boot/initrd-5.14.21-150400.11-default | cpio -idmv
cd $TMP/initramfs
/usr/lib/dracut/skipcpio /boot/initrd-5.14.21-150400.11-default 2>/dev/null | unzstd -- |cpio -idvm
To repackage initrd:
cd $TMP/earlycpio
find . -print0| cpio -H newc --null -o > ../initrd.new
cd $TMP/initramfs
find . -print0| sort -z | cpio --null -H newc --quiet -o > ../initramfs.img
cd $TMP
cat initramfs.img |zstd >> initrd.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment