#! /bin/sh # ------------------------------------------------------------------------------ # # fix-busybox-hook # update-initramfs hook to provided functional BusyBox tools in initramfs # alexandru.panoiu@gmail.com # 2017-10-13 # # This file must be made executable and symlinked from # /etc/initramfs-tools/hooks # # update-initramfs tools to replace the crippled BusyBox provided by default in # the initramfs environment by Ubuntu 17.10 with a variant compatible with the # dropbear and cryptsetup boot scripts. # # Adapted from the hook script written by Hamy; see "Remote unlocking of # LUKS-encrypted root in Ubuntu/Debian", https://hamy.io/post/0005/. # # ------------------------------------------------------------------------------ if test "/$1/" = '/prereqs/'; then echo '' exit 0 fi [ "$BUSYBOX" = 'n' ] && exit 0 [ -r /usr/share/initramfs-tools/hook-functions ] || exit 0 . /usr/share/initramfs-tools/hook-functions # Testing the presence of busybox-initramfs hook [ -x /usr/share/initramfs-tools/hooks/zz-busybox-initramfs ] || exit 0 # The original busybox binary added by busybox-initramfs BUSYBOX_ORIGINAL=$DESTDIR/bin/busybox [ -x $BUSYBOX_ORIGINAL ] || exit 0 # The one we want to replace it with [ -x /bin/busybox ] || exit 0 BUSYBOX_NEW=/bin/busybox # Ensure the original busybox lacks extended options # and the soon-to-be-replaced-by one does not if $BUSYBOX_ORIGINAL ps -eo pid,args >/dev/null 2>&1; then exit 0 elif ! $BUSYBOX_NEW ps -eo pid,args >/dev/null 2>&1; then exit 0 fi # Get the inode number of busybox-initramfs binary BUSYBOX_ORIGINAL_INODE=$(stat --format=%i $BUSYBOX_ORIGINAL) # Replace the binary rm -f $BUSYBOX_ORIGINAL copy_exec $BUSYBOX_NEW /bin/busybox echo "Fixing busybox-initramfs for:" for alias in $( $BUSYBOX_NEW --list-long | sed -e 's@/\?\(usr/\)\?\(bin/\)\?@bin/@' ); do # Remove (and then re-add) all the hardlinks added by busybox-initramfs if [ -e "$DESTDIR/$alias" ] && [ $(stat --format=%i "$DESTDIR/$alias") -eq $BUSYBOX_ORIGINAL_INODE ] then echo -n " ${alias#bin/}" rm -f "$DESTDIR/$alias" ln "$DESTDIR/bin/busybox" "$DESTDIR/$alias" fi done | fmt -s # vim: set ai bs=2 com=\:# et ft=sh sw=2 tw=80: