Install fully featured busybox in initramfs (Ubuntu 18.04)

Whoops

If we activate full busybox in initramfs, cryptroot-unlock fails with numerous errors. It is not compatible with the full busybox executable. Workaround: install the busybox as /bin/busybox2 and execute busybox2 commands with e.g."busybox2 vi"


Stock Ubuntu initramfs includes only a limited busybox executable from package "busybox-initramfs" in /usr/lib/initramfs-tools/bin/busybox.

Sadly, this is not configureable as the busybox install hook in /usr/share/initramfs-tools/hooks/zz-busybox-initramfs hardcodes "BB_BIN=/usr/lib/initramfs-tools/bin/busybox".

Here is a solution which does not tamper with files in /usr and is therefore upgrade safe:

  • cp /usr/share/initramfs-tools/hooks/zz-busybox-initramfs /etc/initramfs-tools/hooks/zzz-use-full-busybox

  • vi /etc/initramfs-tools/hooks/zzz-use-full-busybox

    • # Disable limited busybox from "busybox-initramfs" package
      #BB_BIN=/usr/lib/initramfs-tools/bin/busybox
      # Use full busybox executable from "busybox-static" package
      BB_BIN=/bin/busybox
      
      # Include initramfs hook helper functions directly below the line with "BB_BIN=..."
      . /usr/share/initramfs-tools/hook-functions
  • update-initramfs -u

Test

Boot into initramfs

Before:

  • busybox
    • Currently defined functions:
          [, [[, acpid, ash, awk, basename, blockdev, cat, chmod, chroot,
          chvt, clear, cmp, cp, cut, deallocvt, deluser, devmem, df, du,
          dumpkmap, echo, egrep, env, expr, false, fbset, fgrep, find,
          fstrim, grep, gunzip, gzip, hostname, hwclock, ifconfig, ip, kill,
          ln, loadfont, loadkmap, ls, lzop, mkdir, mkfifo, mknod, mkswap,
          mktemp, modinfo, more, mount, mv, openvt, pidof, printf, ps, pwd,
          readlink, reset, rm, rmdir, sed, seq, setkeycodes, sh, sleep, sort,
          stat, static-sh, stty, switch_root, sync, tail, tee, test, touch,
          tr, true, tty, umount, uname, uniq, wc, wget, which, yes

After:

  • busybox
    • Currently defined functions:
          [, [[, acpid, adjtimex, ar, arp, arping, ash, awk, basename,
          blkdiscard, blockdev, brctl, bunzip2, bzcat, bzip2, cal, cat,
          chgrp, chmod, chown, chpasswd, chroot, chvt, clear, cmp, cp, cpio,
          crond, crontab, cttyhack, cut, date, dc, dd, deallocvt, depmod,
          devmem, df, diff, dirname, dmesg, dnsdomainname, dos2unix, dpkg,
          dpkg-deb, du, dumpkmap, dumpleases, echo, ed, egrep, env, expand,
          expr, factor, fallocate, false, fatattr, fdisk, fgrep, find, fold,
          free, freeramdisk, fsfreeze, fstrim, ftpget, ftpput, getopt, getty,
          grep, groups, gunzip, gzip, halt, head, hexdump, hostid, hostname,
          httpd, hwclock, i2cdetect, i2cdump, i2cget, i2cset, id, ifconfig,
          ifdown, ifup, init, insmod, ionice, ip, ipcalc, ipneigh, kill,
          killall, klogd, last, less, link, linux32, linux64, linuxrc, ln,
          loadfont, loadkmap, logger, login, logname, logread, losetup, ls,
          lsmod, lsscsi, lzcat, lzma, lzop, md5sum, mdev, microcom, mkdir,
          mkdosfs, mke2fs, mkfifo, mknod, mkpasswd, mkswap, mktemp, modinfo,
          modprobe, more, mount, mt, mv, nameif, nc, netstat, nl, nproc,
          nsenter, nslookup, od, openvt, partprobe, passwd, paste, patch,
          pidof, ping, ping6, pivot_root, poweroff, printf, ps, pwd, rdate,
          readlink, realpath, reboot, renice, reset, rev, rm, rmdir, rmmod,
          route, rpm, rpm2cpio, run-parts, sed, seq, setkeycodes, setpriv,
          setsid, sh, sha1sum, sha256sum, sha512sum, shred, shuf, sleep,
          sort, ssl_client, start-stop-daemon, stat, static-sh, strings,
          stty, su, sulogin, svc, swapoff, swapon, switch_root, sync, sysctl,
          syslogd, tac, tail, tar, taskset, tee, telnet, telnetd, test, tftp,
          time, timeout, top, touch, tr, traceroute, traceroute6, true,
          truncate, tty, tunctl, ubirename, udhcpc, udhcpd, uevent, umount,
          uname, uncompress, unexpand, uniq, unix2dos, unlink, unlzma,
          unshare, unxz, unzip, uptime, usleep, uudecode, uuencode, vconfig,
          vi, w, watch, watchdog, wc, wget, which, who, whoami, xargs, xxd,
          xz, xzcat, yes, zcat