From 581b3972d1e139c2dae7a09d9a00a01dcfb07ea0 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Thu, 13 Apr 2023 20:42:03 -0700 Subject: [PATCH] packer: update boards and base images. The base images make sure to remove snapd and fake-hwclock, as well as using installing the rng-tools package. --- packer/boards/cm4-cdev-ubuntu-22.04.2.json | 61 ++++++++++++++++++++++ packer/build-image.sh | 20 +++---- packer/files/user-data | 21 +++++--- packer/scripts/install-base.sh | 6 ++- packer/scripts/setup-cdev.sh | 2 +- packer/ubuntu-boards.yml | 3 +- 6 files changed, 87 insertions(+), 26 deletions(-) create mode 100644 packer/boards/cm4-cdev-ubuntu-22.04.2.json diff --git a/packer/boards/cm4-cdev-ubuntu-22.04.2.json b/packer/boards/cm4-cdev-ubuntu-22.04.2.json new file mode 100644 index 0000000..a96ebd8 --- /dev/null +++ b/packer/boards/cm4-cdev-ubuntu-22.04.2.json @@ -0,0 +1,61 @@ +{ + "variables": {}, + "builders": [ + { + "type": "arm", + "file_urls": [ + "build/ubuntu-22.04.2-preinstalled-server-arm64+raspi.img.xz", + "https://cdimage.ubuntu.com/releases/22.04.2/release/ubuntu-22.04.2-preinstalled-server-arm64+raspi.img.xz" + ], + "file_checksum_url": "http://cdimage.ubuntu.com/releases/22.04.2/release/SHA256SUMS", + "file_checksum_type": "sha256", + "file_target_extension": "xz", + "file_unarchive_cmd": [ + "xz", + "--decompress", + "$ARCHIVE_PATH" + ], + "image_build_method": "reuse", + "image_path": "build/cm4-cdev-ubuntu-22.04.2.img", + "image_size": "32G", + "image_type": "dos", + "image_partitions": [ + { + "name": "boot", + "type": "c", + "start_sector": 2048, + "size": "256M", + "mountpoint": "/boot/firmware" + }, + { + "name": "root", + "type": "83", + "start_sector": 526336, + "size": "31.7G", + "mountpoint": "/" + } + ], + "image_chroot_env": [ + "PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin" + ], + "qemu_binary_source_path": "/usr/bin/qemu-aarch64-static", + "qemu_binary_destination_path": "/usr/bin/qemu-aarch64-static" + } + ], + "provisioners": [ + { + "destination": "/boot/firmware/user-data", + "source": "files/user-data", + "type": "file" + }, + { + "scripts": [ + "scripts/install-base.sh", + "scripts/setup-ssh.sh", + "scripts/setup-cdev.sh" + ], + "type": "shell" + } + ], + "post-processors": null +} \ No newline at end of file diff --git a/packer/build-image.sh b/packer/build-image.sh index bfd5825..8195e52 100755 --- a/packer/build-image.sh +++ b/packer/build-image.sh @@ -18,33 +18,24 @@ errmsg () { echo "$@" > /dev/stderr } -IMAGE_TYPE="${1:-ubuntu}" +IMAGE_TYPE="${1:-cnode}" preflight () { case "${IMAGE_TYPE}" in - ubuntu) - PACKER_BUILD_FILE="boards/cm4-cluster-ubuntu-22.04.2.json" - if [ "${SKIP_LOCAL_CACHE}" != "yes" ] - then - REMOTE_IMAGE_URL="$(jq '.builders[0].file_urls' ${PACKER_BUILD_FILE} | grep https | tr -d ' \",')" - fi - ;; + cdev) PACKER_BUILD_FILE="boards/cm4-cdev-ubuntu-22.04.2.json" ;; + cnode) PACKER_BUILD_FILE="cm4-cluster-ubuntu-22.04.2.img" ;; custom) if [ -z "${PACKER_BUILD_FILE}" ] then errmsg "[!] custom board requires a board file path" exit 1 fi - - if [ "${SKIP_LOCAL_CACHE}" != "yes" ] - then - REMOTE_IMAGE_URL="$(jq '.builders[0].file_urls' ${PACKER_BUILD_FILE} | grep https | tr -d ' \",')" - fi ;; *) errmsg "[!] invalid image type ${IMAGE_TYPE}." errmsg "[!] valid image types are" - errmsg " - ubuntu" + errmsg " - cdev" + errmsg " - cnode" errmsg " - custom path/to/board/file" exit 1 ;; @@ -58,6 +49,7 @@ cache_remote_url () { return 0 fi + local REMOTE_IMAGE_URL="$(jq '.builders[0].file_urls' ${PACKER_BUILD_FILE} | grep https | tr -d ' \",')" local CACHED_FILE="$(jq '.builders[0].file_urls' ${PACKER_BUILD_FILE} | grep -v https | grep \" | tr -d ' \",')" if [ -z "${CACHED_FILE}" ] then diff --git a/packer/files/user-data b/packer/files/user-data index 152e7b4..6574f18 100644 --- a/packer/files/user-data +++ b/packer/files/user-data @@ -1,15 +1,13 @@ #cloud-config -# This is the user-data configuration file for cloud-init. By default this sets -# up an initial user called "ubuntu" with password "ubuntu", which must be -# changed at first login. However, many additional actions can be initiated on -# first boot from this file. The cloud-init documentation has more details: -# -# https://cloudinit.readthedocs.io/ +# NOTE: this is a dev-environment fixture where I want a known user:pass to +# login on the serial console if things go sideways. chpasswd: expire: false list: - - ubuntu:ubuntu + - name: ubuntu + password: ubuntu + type: text hostname: rp3b-cdev ssh_pwauth: true @@ -48,4 +46,11 @@ network: ethernets: eth0: dhcp4: yes - + dhcp6: yes + eth1: + dhcp4: no + dhcp6: no + addresses: + "192.168.4.64/24" + label: "cluster" + lifetime: forever diff --git a/packer/scripts/install-base.sh b/packer/scripts/install-base.sh index 6b1d854..42a0718 100755 --- a/packer/scripts/install-base.sh +++ b/packer/scripts/install-base.sh @@ -8,5 +8,7 @@ echo 'nameserver 8.8.8.8' > /etc/resolv.conf echo "==> installing base updates" apt-get -y update -apt-get -y install ansible apt-transport-https ca-certificates wpasupplicant -apt-get -y clean \ No newline at end of file +apt-get -y install ansible apt-transport-https ca-certificates rng-tools +apt-get -y remove fake-hwclock snapd +apt-get -y clean +apt-get -y autoremove diff --git a/packer/scripts/setup-cdev.sh b/packer/scripts/setup-cdev.sh index 53925e7..f536478 100755 --- a/packer/scripts/setup-cdev.sh +++ b/packer/scripts/setup-cdev.sh @@ -2,4 +2,4 @@ set -euxo pipefail -sudo apt-get -y install picocom wpasupplicant \ No newline at end of file +apt-get -y install picocom wpasupplicant \ No newline at end of file diff --git a/packer/ubuntu-boards.yml b/packer/ubuntu-boards.yml index a871a04..c85c5f1 100644 --- a/packer/ubuntu-boards.yml +++ b/packer/ubuntu-boards.yml @@ -10,10 +10,11 @@ boards: - scripts/setup-ssh.sh - version: 22.04.2 size: 32G - name: rp4-cdev-ubuntu-22.04.2.img + name: cm4-cdev-ubuntu-22.04.2.img files: - source: files/user-data destination: /boot/firmware/user-data scripts: - scripts/install-base.sh - scripts/setup-ssh.sh + - scripts/setup-cdev.sh