--- /home/tange/tmp//cryptroot.orig 2018-02-24 22:16:39.920392548 +0100 +++ usr/share/initramfs-tools/scripts/local-top/cryptroot 2018-02-24 22:30:03.527007065 +0100 @@ -188,7 +188,21 @@ parse_options "$opts" || return 1 + # Wait for USB to settle + /bin/sleep 3 + if [ -z "$cryptkeyscript" ]; then + # Test all devices + mkdir /mnt + echo -n "Searching for cryptkey.txt on available disks... " + for partition in `cat /proc/partitions |awk '{print $4}'|tail -n +3`; do + if mount /dev/$partition /mnt 2>/dev/null; then + cat /mnt/cryptkey.txt >> /tmp/cryptkeys.txt 2>/dev/null + umount /dev/$partition + fi + done + echo "done." + if [ ${cryptsource#/dev/disk/by-uuid/} != $cryptsource ]; then # UUIDs are not very helpful diskname="$crypttarget" @@ -305,11 +319,30 @@ count=$(( $count + 1 )) if [ ! -e "$NEWROOT" ]; then + keyfound=0 + if [ -e /tmp/cryptkeys.txt ] ; then + echo Trying keys from cryptkey.txt + for key in `cat /tmp/cryptkeys.txt`; do + if crypttarget="$crypttarget" cryptsource="$cryptsource" \ + echo -n "$key" | $cryptopen; then + # Found the key + echo Key found in cryptkey.txt + keyfound=1 + key="" + fi + done + # Remove traces of the key + rm /tmp/cryptkeys.txt + unset key + fi + if [ "$keyfound" = "0" ]; then + # Fall back to manual entry if ! crypttarget="$crypttarget" cryptsource="$cryptsource" \ $cryptkeyscript "$cryptkey" | $cryptopen; then message "cryptsetup ($crypttarget): cryptsetup failed, bad password or options?" continue fi + fi fi if [ ! -e "$NEWROOT" ]; then