From dbd3d59354a90e6a142d3694c4e0a516d34e948b Mon Sep 17 00:00:00 2001 From: Mischa Taylor Date: Sun, 23 Jun 2024 15:00:08 -0400 Subject: [PATCH] Add debian 12 aarch64 template --- debian/cloud/aarch64/README.md | 92 +++++ .../aarch64/debian-12-aarch64.pkrvars.hcl | 3 + debian/cloud/aarch64/debian.pkr.hcl | 117 ++++++ .../cloud/docs/MOUNT_CLOUD_IMAGE_AARCH64.md | 357 +++++++++++++++++- debian/cloud/docs/MOUNT_CLOUD_IMAGE_X86_64.md | 2 +- ..._JETSON_ARM64_DEBIAN_CLOUD_IMAGE_MANUAL.md | 122 ++++++ 6 files changed, 678 insertions(+), 15 deletions(-) create mode 100644 debian/cloud/aarch64/README.md create mode 100644 debian/cloud/aarch64/debian-12-aarch64.pkrvars.hcl create mode 100644 debian/cloud/aarch64/debian.pkr.hcl create mode 100644 debian/cloud/docs/QEMU_NVIDIA_JETSON_ARM64_DEBIAN_CLOUD_IMAGE_MANUAL.md diff --git a/debian/cloud/aarch64/README.md b/debian/cloud/aarch64/README.md new file mode 100644 index 0000000..c8c92f8 --- /dev/null +++ b/debian/cloud/aarch64/README.md @@ -0,0 +1,92 @@ +# Debian aarch64 cloud images + +## Debian 12 + +``` +cd debian/cloud/aarch64 +packer init . +PACKER_LOG=1 packer build \ + -var-file debian-12-aarch64.pkrvars.hcl \ + debian.pkr.hcl +``` + +``` + +$ sudo qemu-img convert \ + -f qcow2 \ + -O qcow2 \ + output-debian-12-aarch64/debian-12-aarch64.qcow2 \ + /var/lib/libvirt/images/debian-12-aarch64.qcow2 +$ sudo qemu-img resize \ + -f qcow2 \ + /var/lib/libvirt/images/debian-12-aarch64.qcow2 \ + 32G +``` + +``` +$ sudo apt-get install libosinfo-bin +$ osinfo-query os +``` + +``` +virt-install \ + --connect qemu:///system \ + --name debian-12 \ + --boot uefi \ + --memory 4096 \ + --vcpus 2 \ + --os-variant debian10 \ + --disk /var/lib/libvirt/images/debian-12-aarch64.qcow2,bus=virtio \ + --network network=host-network,model=virtio \ + --noautoconsole \ + --console pty,target_type=serial \ + --import \ + --debug + +virsh console debian-12 + +# login with packer user + +# Check networking - you may notice that the network interface is down and +# the name of the interface generated in netplan doesn't match. If not +# correct, can regenerate with cloud-init +# ip reports that enp1s0 is down +$ ip --brief a +lo UNKNOWN 127.0.0.1/8 ::1/128 +enp1s0 UP 10.63.34.169/22 metric 100 fe80::5054:ff:fee1:b969/64 + +# Check to make sure cloud-init is greater than 23.4 +$ cloud-init --version +/usr/bin/cloud-init 22.4.2 + +# NOTE: Because Ubuntu 20.04 has a version of cloud-init earlier than 23.4 +# it does not have the "clean" parameter, instead regenerate the netplan +# config with the following + +# Make cloud-init regenerate the network configuration +sudo rm /var/lib/cloud/data/instance-id +sudo cloud-init init --local + +$ sudo reboot + +# Verify image boots with the networking enabled +$ ip --brief a +lo UNKNOWN 127.0.0.1/8 ::1/128 +enp1s0 UP 10.63.46.11/22 metric 100 fe80::5054:ff:fe04:483/64 + + +$ cloud-init status +status: done + +# Disable cloud-init +$ sudo touch /etc/cloud/cloud-init.disabled + +# Verify cloud-init is disabled +$ cloud-init status +status: disabled +``` + +``` +$ virsh shutdown debian-12 +$ virsh undefine debian-12 --nvram --remove-all-storage +``` diff --git a/debian/cloud/aarch64/debian-12-aarch64.pkrvars.hcl b/debian/cloud/aarch64/debian-12-aarch64.pkrvars.hcl new file mode 100644 index 0000000..afe383d --- /dev/null +++ b/debian/cloud/aarch64/debian-12-aarch64.pkrvars.hcl @@ -0,0 +1,3 @@ +iso_checksum = "file:https://cloud.debian.org/images/cloud/bookworm/latest/SHA512SUMS" +iso_url = "https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-arm64.qcow2" +vm_name = "debian-12-aarch64" diff --git a/debian/cloud/aarch64/debian.pkr.hcl b/debian/cloud/aarch64/debian.pkr.hcl new file mode 100644 index 0000000..c7d1517 --- /dev/null +++ b/debian/cloud/aarch64/debian.pkr.hcl @@ -0,0 +1,117 @@ +packer { + required_plugins { + qemu = { + version = "~> 1" + source = "github.com/hashicorp/qemu" + } + } +} + +variable "efi_boot" { + type = bool + default = false +} + +variable "efi_firmware_code" { + type = string + default = null +} + +variable "efi_firmware_vars" { + type = string + default = null +} + +variable "ssh_username" { + type = string + default = "packer" +} + +variable "ssh_password" { + type = string + default = "packer" +} + +variable "vm_name" { + type = string + default = "debian-12-aarch64" +} + +source "file" "user_data" { + content = < like the following: + /etc/cloud/clean.d/99-live-installer +``` + +``` +# ls /etc/cloud/cloud.cfg.d +01_debian_cloud.cfg 05_logging.cfg README + +# cat /etc/cloud/cloud.cfg.d/README +# All files with the '.cfg' extension in this directory will be read by +# cloud-init. They are read in lexical order. Later files overwrite values in +# earlier files. + +# cat /etc/cloud/cloud.cfg.d/README +# All files with the '.cfg' extension in this directory will be read by +# cloud-init. They are read in lexical order. Later files overwrite values in +# earlier files. +root@agx01:/# cat /etc/cloud/cloud.cfg.d/01_debian_cloud.cfg +apt: + generate_mirrorlists: true + +system_info: + default_user: + name: debian + sudo: ALL=(ALL) NOPASSWD:ALL + shell: /bin/bash + lock_passwd: True + gecos: Debian + groups: [adm, audio, cdrom, dialout, dip, floppy, plugdev, sudo, video] + sudo: ["ALL=(ALL) NOPASSWD:ALL"] + shell: /bin/bash + +# cat /etc/cloud/cloud.cfg.d/05_logging.cfg +## This yaml formated config file handles setting +## logger information. The values that are necessary to be set +## are seen at the bottom. The top '_log' are only used to remove +## redundency in a syslog and fallback-to-file case. +## +## The 'log_cfgs' entry defines a list of logger configs +## Each entry in the list is tried, and the first one that +## works is used. If a log_cfg list entry is an array, it will +## be joined with '\n'. +_log: + - &log_base | + [loggers] + keys=root,cloudinit + + [handlers] + keys=consoleHandler,cloudLogHandler + + [formatters] + keys=simpleFormatter,arg0Formatter + + [logger_root] + level=DEBUG + handlers=consoleHandler,cloudLogHandler + + [logger_cloudinit] + level=DEBUG + qualname=cloudinit + handlers= + propagate=1 + + [handler_consoleHandler] + class=StreamHandler + level=WARNING + formatter=arg0Formatter + args=(sys.stderr,) + + [formatter_arg0Formatter] + format=%(asctime)s - %(filename)s[%(levelname)s]: %(message)s + + [formatter_simpleFormatter] + format=[CLOUDINIT] %(filename)s[%(levelname)s]: %(message)s + - &log_file | + [handler_cloudLogHandler] + class=FileHandler + level=DEBUG + formatter=arg0Formatter + args=('/var/log/cloud-init.log', 'a', 'UTF-8') + - &log_syslog | + [handler_cloudLogHandler] + class=handlers.SysLogHandler + level=DEBUG + formatter=simpleFormatter + args=("/dev/log", handlers.SysLogHandler.LOG_USER) + +log_cfgs: +# Array entries in this list will be joined into a string +# that defines the configuration. +# +# If you want logs to go to syslog, uncomment the following line. +# - [ *log_base, *log_syslog ] +# +# The default behavior is to just log to a file. +# This mechanism that does not depend on a system service to operate. + - [ *log_base, *log_file ] +# A file path can also be used. +# - /etc/log.conf + +# This tells cloud-init to redirect its stdout and stderr to +# 'tee -a /var/log/cloud-init-output.log' so the user can see output +# there without needing to look on the console. +output: {all: '| tee -a /var/log/cloud-init-output.log'} +``` + +``` +# ls /etc/cloud/templates/ +chef_client.rb.tmpl host.mariner.tmpl ntp.conf.freebsd.tmpl +chrony.conf.alpine.tmpl hosts.alpine.tmpl ntp.conf.opensuse.tmpl +chrony.conf.centos.tmpl hosts.arch.tmpl ntp.conf.photon.tmpl +chrony.conf.cos.tmpl hosts.debian.tmpl ntp.conf.rhel.tmpl +chrony.conf.debian.tmpl hosts.freebsd.tmpl ntp.conf.sles.tmpl +chrony.conf.fedora.tmpl hosts.gentoo.tmpl ntp.conf.ubuntu.tmpl +chrony.conf.freebsd.tmpl hosts.photon.tmpl ntpd.conf.openbsd.tmpl +chrony.conf.opensuse.tmpl hosts.redhat.tmpl resolv.conf.tmpl +chrony.conf.photon.tmpl hosts.suse.tmpl sources.list.debian.tmpl +chrony.conf.rhel.tmpl ntp.conf.alpine.tmpl sources.list.ubuntu.tmpl +chrony.conf.sles.tmpl ntp.conf.debian.tmpl systemd.resolved.conf.tmpl +chrony.conf.ubuntu.tmpl ntp.conf.fedora.tmpl timesyncd.conf.tmpl ``` diff --git a/debian/cloud/docs/MOUNT_CLOUD_IMAGE_X86_64.md b/debian/cloud/docs/MOUNT_CLOUD_IMAGE_X86_64.md index c5a65d2..820ca51 100644 --- a/debian/cloud/docs/MOUNT_CLOUD_IMAGE_X86_64.md +++ b/debian/cloud/docs/MOUNT_CLOUD_IMAGE_X86_64.md @@ -115,7 +115,7 @@ exit $ sudo umount /mnt/debian-12 $ sudo qemu-nbd --disconnect /dev/nbd0 $ sudo rmdir /mnt/debian-12 -$ rmmod nbd +$ sudo rmmod nbd ``` ## Mount cloud image with guestfish diff --git a/debian/cloud/docs/QEMU_NVIDIA_JETSON_ARM64_DEBIAN_CLOUD_IMAGE_MANUAL.md b/debian/cloud/docs/QEMU_NVIDIA_JETSON_ARM64_DEBIAN_CLOUD_IMAGE_MANUAL.md new file mode 100644 index 0000000..0018846 --- /dev/null +++ b/debian/cloud/docs/QEMU_NVIDIA_JETSON_ARM64_DEBIAN_CLOUD_IMAGE_MANUAL.md @@ -0,0 +1,122 @@ +# QEMU Nvidia Jetson ARM64 Debian Cloud Images + +Download the Debian cloud image + +``` +$ curl -LO https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-arm64.qcow2 + +$ qemu-img info debian-12-generic-arm64.qcow2 +image: debian-12-generic-arm64.qcow2 +file format: qcow2 +virtual size: 2 GiB (2147483648 bytes) +disk size: 394 MiB +cluster_size: 65536 +Format specific information: + compat: 1.1 + lazy refcounts: false + refcount bits: 16 + corrupt: false + +$ qemu-img convert \ + -O qcow2 \ + debian-12-generic-arm64.qcow2 \ + debian-12.qcow2 + +# Resize the image +$ qemu-img resize \ + -f qcow2 \ + debian-12.qcow2 32G +``` + +Create a cloud-init configuration + +``` +touch network-config + +cat >meta-data < user-data +#cloud-config +password: superseekret +chpasswd: + expire: False +ssh_pwauth: True +EOF +``` + +Create the cloud-init ISO + +``` +sudo apt-get update +sudo apt-get install genisoimage +genisoimage \ + -input-charset utf-8 \ + -output cloud-init.iso \ + -volid cidata -rational-rock -joliet \ + user-data meta-data network-config +``` + +Create a firmware image + +``` +# Qemu expects aarch firmware images to be 64M so the firmware +# images can't be used as is, some padding is needed to +# create an image for pflash +dd if=/dev/zero of=flash0.img bs=1M count=64 +dd if=/usr/share/AAVMF/AAVMF_CODE.fd of=flash0.img conv=notrunc +dd if=/dev/zero of=flash1.img bs=1M count=64 +``` + +Run the VM with QEMU + +``` +# login: debian +qemu-system-aarch64 \ + -name debian-12 \ + -machine virt,accel=kvm,gic-version=3,kernel-irqchip=on \ + -cpu host \ + -smp 2 \ + -m 2G \ + -device virtio-keyboard \ + -device virtio-mouse \ + -device virtio-gpu-pci \ + -nographic \ + -device virtio-net-pci,netdev=net0 \ + -netdev user,id=net0,hostfwd=tcp::2222-:22 \ + -drive file=debian-12.qcow2,if=virtio,format=qcow2 \ + -cdrom cloud-init.iso \ + -drive if=pflash,format=raw,readonly=on,unit=0,file=flash0.img \ + -drive if=pflash,format=raw,unit=1,file=flash1.img + +Ctrl-a h: Show help (displays all available commands). +Ctrl-a x: Exit QEMU. +Ctrl-a c: Switch between the monitor and the console. +Ctrl-a s: Send a break signal. + +qemu-system-x86_64 \ + -name debian-12 \ + -machine virt,accel=kvm,type=q35 \ + -cpu host \ + -smp 2 \ + -m 2G \ + -device virtio-keyboard \ + -device virtio-mouse \ + -device virtio-net-pci,netdev=net0 \ + -netdev user,id=net0,hostfwd=tcp::2222-:22 \ + -drive file=debian-12.qcow2,if=virtio,format=qcow2 \ + -cdrom cloud-init.iso \ + -drive if=pflash,format=raw,readonly=on,unit=0,file=/usr/share/OVMF/OVMF_CODE_ +4M.fd \ + -drive if=pflash,format=raw,readonly=on,unit=1,file=/usr/share/OVMF/OVMF_VARS_ +4M.fd +``` + +Login to the image + +``` +# debian / superseekret +ssh cloud-user@localhost -p 2222 +```