Skip to content

Instantly share code, notes, and snippets.

Created July 4, 2018 09:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# This hook is for fixing busybox-initramfs issue while unlocking a luks
# encrypted rootfs. The problem is that the included busybox version
# is stripped down to the point that it breaks cryptroot-unlock script:
# This is a non-aggressive fix based on the original busybox-initramfs hook
# until the bug is fixed.
# busybox or busybox-static package must be present for this to work
# This file should be placed in /etc/initramfs-tools/hooks/ and have +x flag set
# after that you need to rebuild the initramfs with 'update-initramfs -u'
# This is only tested in Ubuntu Server 17.04 . May or may not work in other
# Ubuntu/Debian releases.
# Also note that this does not replace busybox-initramfs package.
# The package must be present, this hook just fixes what's broken.
# Hamy -
set -e
case "${1:-}" in
prereqs) echo ""; exit 0;;
[ n = "$BUSYBOX" ] && 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
[ -x $BB_BIN_ORG ] || exit 0
# The one we want to replace it with
[ -x /bin/busybox ] || exit 0
# Ensure the original busybox lacks extended options
# and the soon-to-be-replaced-by one does not
if $BB_BIN_ORG ps -eo pid,args >/dev/null 2>&1; then
exit 0
elif ! $BB_BIN ps -eo pid,args >/dev/null 2>&1; then
exit 0
# Get the inode number of busybox-initramfs binary
BB_BIN_ORG_IND=$(stat --format=%i $BB_BIN_ORG)
# Replace the binary
rm -f $BB_BIN_ORG
copy_exec $BB_BIN /bin/busybox
echo -n "Fixing busybox-initramfs for:"
for alias in $($BB_BIN --list-long); do
case "$alias" in
# strip leading /usr, we don't use it
usr/*) alias="${alias#usr/}" ;;
*/*) ;;
*) alias="bin/$alias" ;; # make it into /bin
# Remove (and then re-add) all the hardlinks added by busybox-initramfs
if [ -e "$DESTDIR/$alias" ] && [ $(stat --format=%i "$DESTDIR/$alias") -eq $BB_BIN_ORG_IND ]; then
echo -n " ${alias##*/}"
rm -f "$DESTDIR/$alias"
ln "$DESTDIR/bin/busybox" "$DESTDIR/$alias"
# To get a trailing new line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment