From 8ee212910bfcc958dadec3ccb24dde8fdf0ff255 Mon Sep 17 00:00:00 2001 From: Ruben Steinbacher Date: Wed, 29 Apr 2020 07:09:31 +0200 Subject: [PATCH 1/6] Switch to release version of Ubuntu Server 20.04 This is the one that now uses subiquity instead of debian-installer --- ubuntu2004/box-config.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ubuntu2004/box-config.json b/ubuntu2004/box-config.json index c8fcd3c..cec92e5 100755 --- a/ubuntu2004/box-config.json +++ b/ubuntu2004/box-config.json @@ -58,11 +58,11 @@ "headless": false, "http_directory": "http", "iso_urls": [ - "iso/focal-legacy-server-amd64.iso", - "http://cdimage.ubuntu.com/ubuntu-legacy-server/releases/20.04/release/ubuntu-20.04-legacy-server-amd64.iso" + "iso/ubuntu-20.04-live-server-amd64.iso", + "https://releases.ubuntu.com/20.04/ubuntu-20.04-live-server-amd64.iso" ], "iso_checksum_type": "sha256", - "iso_checksum": "36f15879bd9dfd061cd588620a164a82972663fdd148cce1f70d57d314c21b73", + "iso_checksum": "caf3fd69c77c439f162e2ba6040e9c320c4ff0d69aad1340a514319a9264df9f", "ssh_username": "vagrant", "ssh_password": "vagrant", "ssh_port": 22, From 2cd389c062e6a36e9e0a527cee37304a890f7c14 Mon Sep 17 00:00:00 2001 From: Ruben Steinbacher Date: Wed, 29 Apr 2020 07:14:37 +0200 Subject: [PATCH 2/6] Update boot_command and boot_wait Boot command is now a tad bit shorter. Thanks to @nickcharlton for finding this out! The keyword "autoinstall" needs to be present. Boot_wait needs to be long enough for the VM to have actually started, but short enough to keep the ISO's bootloader from executing the installer. Here we may need a more robust way of dropping into the grub command line... --- ubuntu2004/box-config.json | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/ubuntu2004/box-config.json b/ubuntu2004/box-config.json index cec92e5..8e47fbf 100755 --- a/ubuntu2004/box-config.json +++ b/ubuntu2004/box-config.json @@ -28,31 +28,11 @@ { "type": "virtualbox-iso", "boot_command": [ - "", - "", - "", - "/install/vmlinuz", - " auto=true", - " url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg", - " locale=en_US", - " console-setup/ask_detect=false", - " console-setup/layoutcode=us", - " console-setup/modelcode=pc105", - " debconf/frontend=noninteractive", - " debian-installer=en_US", - " fb=false", - " initrd=/install/initrd.gz", - " kbd-chooser/method=us", - " keyboard-configuration/layout=USA", - " keyboard-configuration/variant=USA", - " netcfg/get_domain=vm", - " netcfg/get_hostname=vagrant", - " grub-installer/bootdev=/dev/sda", - " noapic", - " -- ", - "" + " ", + "autoinstall ds=nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/", + "" ], - "boot_wait": "10s", + "boot_wait": "5s", "disk_size": 81920, "guest_os_type": "Ubuntu_64", "headless": false, From 5a121723abad2588ef1f8f59fd4679b3c242bb6b Mon Sep 17 00:00:00 2001 From: Ruben Steinbacher Date: Wed, 29 Apr 2020 07:19:47 +0200 Subject: [PATCH 3/6] Add new autoinstall descriptions instead of a preseed file, subiquity / cloud-init now want a yaml formated file with #cloud-init as a sort of she-bang on the first line. @nickcharlton did an awesome blog post about the principle setup of these files: https://nickcharlton.net/posts/automating-ubuntu-2004-installs-with-packer.html The old preseed file is no longer needed. --- ubuntu2004/http/meta-data | 0 ubuntu2004/http/preseed.cfg | 40 ---------------------------------- ubuntu2004/http/user-data | 43 +++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 40 deletions(-) create mode 100755 ubuntu2004/http/meta-data delete mode 100644 ubuntu2004/http/preseed.cfg create mode 100644 ubuntu2004/http/user-data diff --git a/ubuntu2004/http/meta-data b/ubuntu2004/http/meta-data new file mode 100755 index 0000000..e69de29 diff --git a/ubuntu2004/http/preseed.cfg b/ubuntu2004/http/preseed.cfg deleted file mode 100644 index 1417746..0000000 --- a/ubuntu2004/http/preseed.cfg +++ /dev/null @@ -1,40 +0,0 @@ -choose-mirror-bin mirror/http/proxy string -d-i base-installer/kernel/override-image string linux-server -d-i clock-setup/utc boolean true -d-i clock-setup/utc-auto boolean true -d-i finish-install/reboot_in_progress note -d-i grub-installer/only_debian boolean true -d-i grub-installer/with_other_os boolean true -d-i partman-auto/disk string /dev/sda -d-i partman-auto-lvm/guided_size string max -d-i partman-auto/choose_recipe select atomic -d-i partman-auto/method string lvm -d-i partman-lvm/confirm boolean true -d-i partman-lvm/confirm boolean true -d-i partman-lvm/confirm_nooverwrite boolean true -d-i partman-lvm/device_remove_lvm boolean true -d-i partman/choose_partition select finish -d-i partman/confirm boolean true -d-i partman/confirm_nooverwrite boolean true -d-i partman/confirm_write_new_label boolean true -d-i pkgsel/include string openssh-server cryptsetup build-essential libssl-dev libreadline-dev zlib1g-dev linux-source dkms nfs-common -d-i pkgsel/install-language-support boolean false -d-i pkgsel/update-policy select none -d-i pkgsel/upgrade select full-upgrade -d-i time/zone string UTC -tasksel tasksel/first multiselect standard, ubuntu-server - -d-i console-setup/ask_detect boolean false -d-i keyboard-configuration/layoutcode string us -d-i keyboard-configuration/modelcode string pc105 -d-i debian-installer/locale string en_US.UTF-8 - -# Create vagrant user account. -d-i passwd/user-fullname string vagrant -d-i passwd/username string vagrant -d-i passwd/user-password password vagrant -d-i passwd/user-password-again password vagrant -d-i user-setup/allow-password-weak boolean true -d-i user-setup/encrypt-home boolean false -d-i passwd/user-default-groups vagrant sudo -d-i passwd/user-uid string 900 diff --git a/ubuntu2004/http/user-data b/ubuntu2004/http/user-data new file mode 100644 index 0000000..2294370 --- /dev/null +++ b/ubuntu2004/http/user-data @@ -0,0 +1,43 @@ +#cloud-config +autoinstall: + version: 1 + apt: + geoip: true + preserve_sources_list: true +# primary: +# - arches: [amd64, i386] +# uri: http://de.archive.ubuntu.com/ubuntu +# - arches: [default] +# uri: http://ports.ubuntu.com/ubuntu-ports + packages: + - ubuntu-standard + - ubuntu-server + - openssh-server + - cryptsetup + - build-essential + - libssl-dev + - libreadline-dev + - zlib1g-dev + - linux-source + - dkms + - nfs-common + - software-properties-common + identity: {hostname: vagrant, password: $6$H6dENrige2G2YwQQ$ip2nRmBQDm5OXtQ.xpxOoq.f32XOuNkHm6KgMiPH7LFcYhbWnEiVS8bGD3UGRDRstnL4nn/0Av8rtaXfPjGMz1, + realname: vagrant, username: vagrant} + keyboard: {layout: us, variant: ''} + locale: en_US + network: + network: + ethernets: + enp0s3: {dhcp4: true, dhcp-identifier: mac} + version: 2 + ssh: + allow-pw: true + authorized-keys: [] + install-server: false + storage: + layout: + name: lvm + late-commands: + - sed -i 's/^#*\(send dhcp-client-identifier\).*$/\1 = hardware;/' /target/etc/dhcp/dhclient.conf + - 'sed -i "s/dhcp4: true/&\n dhcp-identifier: mac/" /target/etc/netplan/00-installer-config.yaml' From 4b535fe2d544f4071c49ee97e425885a17366daf Mon Sep 17 00:00:00 2001 From: Ruben Steinbacher Date: Wed, 29 Apr 2020 07:34:29 +0200 Subject: [PATCH 4/6] Implement workaround for packer ssh The new Ubuntu Server installer starts an SSH server. The credentials are installer: Packer wrongfully tries to connect to this SSH, thinking the VM is ready for further provisioning steps - which it is NOT. Thanks to @JulyIghor we found a workaround. We simply change the port packer expects the ssh server to run at to something else AND during cloud-init late_commands we override the servers port accordingly. That way once the cloud-init finishes and reboots the VM the ssh server will run at the new port - now packer picks up on that and continues provisiong as we are used to. As a last step durng provision, we remove the conf file, essentially resettign the ssh server port back to default 22. @SwampDragons: https://github.com/hashicorp/packer/issues/9115 Please check on the logic behind communicator setting "pause_before_connecting". That setting actually does still try to connect ONCE and then waits, instead of waiting for the specified duration and then and only then trying to connect. Thanks! --- ubuntu2004/box-config.json | 11 ++++++++++- ubuntu2004/http/user-data | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) mode change 100644 => 100755 ubuntu2004/http/user-data diff --git a/ubuntu2004/box-config.json b/ubuntu2004/box-config.json index 8e47fbf..acb4ea9 100755 --- a/ubuntu2004/box-config.json +++ b/ubuntu2004/box-config.json @@ -22,6 +22,15 @@ "type": "shell", "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'", "script": "scripts/cleanup.sh" + }, + { + "type": "shell", + "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'", + "inline_shebang": "#!/bin/bash -e", + "inline": [ + "echo 'Resetting SSH port to default!'", + "rm /etc/ssh/sshd_config.d/packer-init.conf" + ] } ], "builders": [ @@ -45,7 +54,7 @@ "iso_checksum": "caf3fd69c77c439f162e2ba6040e9c320c4ff0d69aad1340a514319a9264df9f", "ssh_username": "vagrant", "ssh_password": "vagrant", - "ssh_port": 22, + "ssh_port": 2222, "ssh_wait_timeout": "1800s", "shutdown_command": "echo 'vagrant'|sudo -S shutdown -P now", "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso", diff --git a/ubuntu2004/http/user-data b/ubuntu2004/http/user-data old mode 100644 new mode 100755 index 2294370..3b1af8d --- a/ubuntu2004/http/user-data +++ b/ubuntu2004/http/user-data @@ -41,3 +41,4 @@ autoinstall: late-commands: - sed -i 's/^#*\(send dhcp-client-identifier\).*$/\1 = hardware;/' /target/etc/dhcp/dhclient.conf - 'sed -i "s/dhcp4: true/&\n dhcp-identifier: mac/" /target/etc/netplan/00-installer-config.yaml' + - 'echo "Port 2222" > /target/etc/ssh/sshd_config.d/packer-init.conf' \ No newline at end of file From dc61d2f269b2adf8d9d6939ecb5d3fcad338c3a7 Mon Sep 17 00:00:00 2001 From: Ruben Steinbacher Date: Wed, 29 Apr 2020 14:42:17 +0200 Subject: [PATCH 5/6] Implement @nickcharlton code review suggestions - use ssh: install-server: true instead of manually adding it - unify syntax from mixed yaml and json to just yaml - uniformly quote late-commands --- ubuntu2004/http/user-data | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/ubuntu2004/http/user-data b/ubuntu2004/http/user-data index 3b1af8d..9b2db0b 100755 --- a/ubuntu2004/http/user-data +++ b/ubuntu2004/http/user-data @@ -12,7 +12,6 @@ autoinstall: packages: - ubuntu-standard - ubuntu-server - - openssh-server - cryptsetup - build-essential - libssl-dev @@ -22,23 +21,30 @@ autoinstall: - dkms - nfs-common - software-properties-common - identity: {hostname: vagrant, password: $6$H6dENrige2G2YwQQ$ip2nRmBQDm5OXtQ.xpxOoq.f32XOuNkHm6KgMiPH7LFcYhbWnEiVS8bGD3UGRDRstnL4nn/0Av8rtaXfPjGMz1, - realname: vagrant, username: vagrant} - keyboard: {layout: us, variant: ''} + identity: + hostname: vagrant + password: $6$H6dENrige2G2YwQQ$ip2nRmBQDm5OXtQ.xpxOoq.f32XOuNkHm6KgMiPH7LFcYhbWnEiVS8bGD3UGRDRstnL4nn/0Av8rtaXfPjGMz1 + realname: vagrant + username: vagrant + keyboard: + layout: us + variant: '' locale: en_US network: network: ethernets: - enp0s3: {dhcp4: true, dhcp-identifier: mac} + enp0s3: + dhcp4: true + dhcp-identifier: mac version: 2 ssh: allow-pw: true authorized-keys: [] - install-server: false + install-server: true storage: layout: name: lvm late-commands: - - sed -i 's/^#*\(send dhcp-client-identifier\).*$/\1 = hardware;/' /target/etc/dhcp/dhclient.conf + - 'sed -i "s/^#*\(send dhcp-client-identifier\).*$/\1 = hardware;/" /target/etc/dhcp/dhclient.conf' - 'sed -i "s/dhcp4: true/&\n dhcp-identifier: mac/" /target/etc/netplan/00-installer-config.yaml' - 'echo "Port 2222" > /target/etc/ssh/sshd_config.d/packer-init.conf' \ No newline at end of file From 46a1da387cc4af3be74c6e0bc1983cf96f312295 Mon Sep 17 00:00:00 2001 From: Ruben Steinbacher Date: Sat, 2 May 2020 18:05:41 +0200 Subject: [PATCH 6/6] Implement suggested change by @nickcharlton This admittedly adds less noise to the actual provisioning steps. Simply increase the allowed number of failed cssh connection attempts to make it through the initial setup until reboot. This may however add a bunch of false positives to the packer log if anyone looks in there. + change ssh_wait_timeout value to be more . --- ubuntu2004/box-config.json | 14 +++----------- ubuntu2004/http/user-data | 3 +-- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/ubuntu2004/box-config.json b/ubuntu2004/box-config.json index acb4ea9..a6077e7 100755 --- a/ubuntu2004/box-config.json +++ b/ubuntu2004/box-config.json @@ -22,15 +22,6 @@ "type": "shell", "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'", "script": "scripts/cleanup.sh" - }, - { - "type": "shell", - "execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'", - "inline_shebang": "#!/bin/bash -e", - "inline": [ - "echo 'Resetting SSH port to default!'", - "rm /etc/ssh/sshd_config.d/packer-init.conf" - ] } ], "builders": [ @@ -54,8 +45,9 @@ "iso_checksum": "caf3fd69c77c439f162e2ba6040e9c320c4ff0d69aad1340a514319a9264df9f", "ssh_username": "vagrant", "ssh_password": "vagrant", - "ssh_port": 2222, - "ssh_wait_timeout": "1800s", + "ssh_port": 22, + "ssh_wait_timeout": "25m", + "ssh_handshake_attempts": "20", "shutdown_command": "echo 'vagrant'|sudo -S shutdown -P now", "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso", "virtualbox_version_file": ".vbox_version", diff --git a/ubuntu2004/http/user-data b/ubuntu2004/http/user-data index 9b2db0b..e930dad 100755 --- a/ubuntu2004/http/user-data +++ b/ubuntu2004/http/user-data @@ -46,5 +46,4 @@ autoinstall: name: lvm late-commands: - 'sed -i "s/^#*\(send dhcp-client-identifier\).*$/\1 = hardware;/" /target/etc/dhcp/dhclient.conf' - - 'sed -i "s/dhcp4: true/&\n dhcp-identifier: mac/" /target/etc/netplan/00-installer-config.yaml' - - 'echo "Port 2222" > /target/etc/ssh/sshd_config.d/packer-init.conf' \ No newline at end of file + - 'sed -i "s/dhcp4: true/&\n dhcp-identifier: mac/" /target/etc/netplan/00-installer-config.yaml' \ No newline at end of file