Fix EFI boot off of USB, and don't select USB key for install destination

Change-Id: I5d22e6f27507276607e6c550e162fc9634f218e2
diff --git a/templates/boot.ipxe.j2 b/templates/boot.ipxe.j2
index ed8ecc7..e58def9 100644
--- a/templates/boot.ipxe.j2
+++ b/templates/boot.ipxe.j2
@@ -84,7 +84,7 @@
 #  https://ipxe.org/appnote/debian_preseed
 :ub1804a
 echo Booting Ubuntu 18.04 Installer
-kernel ${http_server_url}/ubuntu1804/linux
+kernel ${http_server_url}/ubuntu1804/linux initrd=initrd.gz initrd=preseed.cfg
 initrd ${http_server_url}/ubuntu1804/initrd.gz
 initrd ${http_server_url}/ubuntu1804/${serial}_preseed.cfg preseed.cfg
 # imgargs {{ pxeboot_ubuntu1804_linux_args }}
diff --git a/templates/ubuntu1804_preseed.cfg.j2 b/templates/ubuntu1804_preseed.cfg.j2
index 10fb4a3..3212a14 100644
--- a/templates/ubuntu1804_preseed.cfg.j2
+++ b/templates/ubuntu1804_preseed.cfg.j2
@@ -25,7 +25,7 @@
 # network and hostname
 d-i netcfg/choose_interface select auto
 d-i netcfg/hostname string {{ item['hostname'] }}
-d-i netcfg/domain string {{ item['domain'] }}
+d-i netcfg/get_domain string {{ item['domain'] }}
 d-i hw-detect/load_firmware boolean true
 
 ## Storage
@@ -61,9 +61,20 @@
 d-i partman/confirm boolean true
 d-i partman/confirm_nooverwrite boolean true
 
-# fix issue with grub hang on install
+### Do NOT install on the USB stick(!)
+#
+# The Debian installer will install on the first disk it finds which can
+# sometimes be the USB stick itself. Work around this by rolling our own auto
+# detect logic which disallows installing on USB devices.
+#
+# Also, fix issue with grub hang on install
 #  https://bugs.launchpad.net/ubuntu/+source/os-prober/+bug/1663645
 d-i partman/early_command string \
+  USBDEV_LIST="$(mktemp)"; \
+  list-devices usb-partition | sed "s/\(.*\)./\1/" > "$USBDEV_LIST"; \
+  BOOTDEV="$(list-devices disk | grep -vf "$USBDEV_LIST" | head -n 1)"; \
+  debconf-set partman-auto/disk "$BOOTDEV"; \
+  debconf-set grub-installer/bootdev "$BOOTDEV"; \
   while /bin/true; do sleep 0.01; rm -f /target/etc/grub.d/30_os-prober; done &
 
 d-i grub-installer/only_debian boolean true