From 943945d4c4d59c53077b4db895e1b986bf53a8a2 Mon Sep 17 00:00:00 2001 From: Mike Ripley Date: Wed, 2 Jun 2021 17:42:38 -0400 Subject: [PATCH 1/5] Add support for AARCH64 builds via QEMU --- .github/workflows/lint.yml | 1 + packer/ubuntu-kvm.json | 90 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 packer/ubuntu-kvm.json diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ad6fa188..d50174c2 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -52,6 +52,7 @@ jobs: packer validate -var-file=mint-beta.pkrvars.hcl . || true # This runs last to ensure it's exit status is captured packer validate . + packer validate ubuntu-kvm.json working-directory: packer - name: Check Packer HCL formatting run: | diff --git a/packer/ubuntu-kvm.json b/packer/ubuntu-kvm.json new file mode 100644 index 00000000..ed0ac417 --- /dev/null +++ b/packer/ubuntu-kvm.json @@ -0,0 +1,90 @@ +{ + "min_packer_version": "1.6.0", + "variables": { + "vm_name": "JMU Ubuntu", + "semester": "Fa22", + + "build_id": "{{isotime \"2006-01-02\"}}", + + "git_repo": "https://github.com/jmunixusers/cs-vm-build", + "git_branch": "main", + + "headless": "false", + + "output_dir": "{{pwd}}/{{user `vm_name`}} {{user `semester`}}.utm/Images", + "mirror_url": "http://cdimage.ubuntu.com/jammy/daily-live/current", + "iso_file": "jammy-desktop-arm64.iso", + + "ssh_user": "oem", + "ssh_pass": "oem" + }, + "builders": [ + { + "type": "qemu", + "headless": "{{user `headless`}}", + "cpus": 2, + "accelerator": "kvm", + "memory": 4096, + "machine_type": "virt", + "qemu_binary": "qemu-system-aarch64", + "qemuargs": [ + [ "-bios", "/usr/share/qemu-efi-aarch64/QEMU_EFI.fd" ], + [ "-boot", "strict=off" ], + [ "-cpu", "host" ], + [ "-display", "gtk" ], + [ "-device", "virtio-rng-pci" ], + [ "-device", "virtio-gpu" ], + [ "-device", "nec-usb-xhci,id=xhci" ], + [ "-device", "usb-kbd,bus=xhci.0" ], + [ "-device", "usb-tablet,bus=xhci.0" ] + ], + "iso_url": "{{user `mirror_url`}}/{{user `iso_file`}}", + "iso_checksum": "file:{{user `mirror_url`}}/SHA256SUMS", + "output_directory": "{{user `output_dir`}}", + "shutdown_command": "echo -e \"{{user `ssh_pass`}}\\n\" | sudo -S poweroff", + "disk_cache": "unsafe", + "disk_compression": "true", + "disk_detect_zeroes": "unmap", + "disk_discard": "unmap", + "disk_size": "20G", + "format": "qcow2", + "qemu_img_args": { + "create": ["-o", "preallocation=falloc"], + "convert": ["-o", "compression_type=zstd"] + }, + "http_directory": "http", + "ssh_username": "{{user `ssh_user`}}", + "ssh_password": "{{user `ssh_pass`}}", + "ssh_timeout": "100m", + "vm_name": "image.qcow2", + "net_device": "virtio-net", + "disk_interface": "virtio", + "boot_wait": "45s", + "boot_command": [ + "c", + "linux /casper/vmlinuz", + " auto url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/oem-preseed.cfg", + " automatic-ubiquity only-ubiquity", + " debug-ubiquity oem-config/enable=true", + " keymap=us fsck.mode=skip", + " noprompt splash --", + "initrd /casper/initrd ", + "boot" + ] + } + ], + "provisioners": [{ + "type": "shell", + "execute_command": "echo 'oem' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'", + "inline": [ + "while(pgrep -a apt-get); do sleep 1; done", + "export DEBIAN_FRONTEND=noninteractive", + "apt-get update", + "apt-get install -y git ansible aptitude", + "git clone -b {{user `git_branch`}} {{user `git_repo`}}", + "cd /home/oem/cs-vm-build/scripts", + "./oem-build", + "/usr/sbin/oem-config-prepare" + ] + }] +} From f0dd2b07c18c75e3064b79cc6c4e4a6a88802c4e Mon Sep 17 00:00:00 2001 From: Kyle Laker Date: Sat, 2 Sep 2023 08:53:05 -0400 Subject: [PATCH 2/5] Convert QEMU build to HCL This is still super early phase but I'd been meaning to get around to this for awhile. I need to actually try to run it; this is purely theoretical at the moment. --- .github/workflows/lint.yml | 1 - README.md | 3 +- packer/main.pkr.hcl | 70 ++++++++++++++++++++++++++++- packer/ubuntu-kvm.json | 90 -------------------------------------- packer/variables.pkr.hcl | 34 ++++++++++++++ 5 files changed, 105 insertions(+), 93 deletions(-) delete mode 100644 packer/ubuntu-kvm.json diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index d50174c2..ad6fa188 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -52,7 +52,6 @@ jobs: packer validate -var-file=mint-beta.pkrvars.hcl . || true # This runs last to ensure it's exit status is captured packer validate . - packer validate ubuntu-kvm.json working-directory: packer - name: Check Packer HCL formatting run: | diff --git a/README.md b/README.md index 746ffca2..f782b3b6 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,8 @@ Linux and Windows hosts, but feedback on other platforms is always welcome. Due to difficulties with Packer packaging, this VM is frequently built with the latest version of Packer available directly from Hashicorp. Check the -`main.pkr.hcl` file for the current minimum version required. +`main.pkr.hcl` file for the current minimum version required. To install the +required plugins, run `packer init .` within the `cs-vm-build/packer` directory. Once the prerequisites are installed, change into the `cs-vm-build/packer` directory and execute `packer build -only "*.mint" .`. This will take a diff --git a/packer/main.pkr.hcl b/packer/main.pkr.hcl index 0c4b2578..01c8d921 100644 --- a/packer/main.pkr.hcl +++ b/packer/main.pkr.hcl @@ -1,6 +1,10 @@ packer { - required_version = ">= 1.7.0" + required_version = ">= 1.9.0" required_plugins { + qemu = { + source = "github.com/hashicorp/qemu" + version = "~> 1" + } virtualbox = { version = "~> 1" source = "github.com/hashicorp/virtualbox" @@ -8,6 +12,62 @@ packer { } } +source "qemu" "kvm" { + cpus = 2 + memory = 4096 + disk_size = 20480 + machine_type = "virt" + accelerator = var.qemu_accelerator + + format = "qcow2" + headless = "${var.headless}" + http_directory = "http" + qemu_binary = "qemu-system-aarch64" + + efi_firmware_code = "${var.qemu_firmware_directory}/QEMU_EFI.fd" + efi_firmware_vars = "${var.qemu_firmware_directory}/QEMU_VARS.fd" + qemuargs = [ + ["-boot", "strict=off"], + ["-cpu", "host"], + ["-display", var.headless ? "none" : "gtk"], + ["-device", "virtio-rng-pci"], + ["-device", "virtio-gpu"], + ["-device", "nec-usb-xhci,id=xhci"], + ["-device", "usb-kbd,bus=xhci.0"], + ["-device", "usb-tablet,bus=xhci.0"] + ] + qemu_img_args { + create = ["-o", "preallocation=falloc"] + convert = ["-o", "compression_type=zstd"] + } + disk_cache = "unsafe" + disk_compression = "true" + disk_detect_zeroes = "unmap" + disk_discard = "unmap" + disk_interface = "virtio" + net_device = "virtio-net" + ssh_username = var.ssh_user + ssh_password = var.ssh_pass + ssh_timeout = "100m" + + boot_wait = var.aarch64_boot_wait + boot_command = [ + # Enter the command line + "c", + # Configure the kernel + "linux /casper/vmlinuz", + " auto url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/oem-preseed.cfg", + " automatic-ubiquity only-ubiquity", + " debug-ubiquity oem-config/enable=true", + " keymap=us fsck.mode=skip", + " noprompt splash --", + # Configure initrd & boot + "initrd /casper/initrd ", + "boot" + ] + shutdown_command = "echo -e \"${var.ssh_pass}\\n\" | sudo -S poweroff" +} + source "virtualbox-iso" "base-build" { cpus = 2 memory = 4096 @@ -113,6 +173,14 @@ build { ] } + source "source.qemu.kvm" { + name = "ubuntu-aarch64" + vm_name = "image.qcow2" + iso_url = "${local.ubuntu_aarch64_info.mirror_url}/${local.ubuntu_aarch64_info.iso_file}" + iso_checksum = "file:${local.ubuntu_aarch64_info.mirror_url}/SHA256SUMS" + output_directory = "${local.artifact_dir_prefix}ubuntu-aarch64" + } + provisioner "shell" { execute_command = "echo 'oem' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'" environment_vars = [ diff --git a/packer/ubuntu-kvm.json b/packer/ubuntu-kvm.json deleted file mode 100644 index ed0ac417..00000000 --- a/packer/ubuntu-kvm.json +++ /dev/null @@ -1,90 +0,0 @@ -{ - "min_packer_version": "1.6.0", - "variables": { - "vm_name": "JMU Ubuntu", - "semester": "Fa22", - - "build_id": "{{isotime \"2006-01-02\"}}", - - "git_repo": "https://github.com/jmunixusers/cs-vm-build", - "git_branch": "main", - - "headless": "false", - - "output_dir": "{{pwd}}/{{user `vm_name`}} {{user `semester`}}.utm/Images", - "mirror_url": "http://cdimage.ubuntu.com/jammy/daily-live/current", - "iso_file": "jammy-desktop-arm64.iso", - - "ssh_user": "oem", - "ssh_pass": "oem" - }, - "builders": [ - { - "type": "qemu", - "headless": "{{user `headless`}}", - "cpus": 2, - "accelerator": "kvm", - "memory": 4096, - "machine_type": "virt", - "qemu_binary": "qemu-system-aarch64", - "qemuargs": [ - [ "-bios", "/usr/share/qemu-efi-aarch64/QEMU_EFI.fd" ], - [ "-boot", "strict=off" ], - [ "-cpu", "host" ], - [ "-display", "gtk" ], - [ "-device", "virtio-rng-pci" ], - [ "-device", "virtio-gpu" ], - [ "-device", "nec-usb-xhci,id=xhci" ], - [ "-device", "usb-kbd,bus=xhci.0" ], - [ "-device", "usb-tablet,bus=xhci.0" ] - ], - "iso_url": "{{user `mirror_url`}}/{{user `iso_file`}}", - "iso_checksum": "file:{{user `mirror_url`}}/SHA256SUMS", - "output_directory": "{{user `output_dir`}}", - "shutdown_command": "echo -e \"{{user `ssh_pass`}}\\n\" | sudo -S poweroff", - "disk_cache": "unsafe", - "disk_compression": "true", - "disk_detect_zeroes": "unmap", - "disk_discard": "unmap", - "disk_size": "20G", - "format": "qcow2", - "qemu_img_args": { - "create": ["-o", "preallocation=falloc"], - "convert": ["-o", "compression_type=zstd"] - }, - "http_directory": "http", - "ssh_username": "{{user `ssh_user`}}", - "ssh_password": "{{user `ssh_pass`}}", - "ssh_timeout": "100m", - "vm_name": "image.qcow2", - "net_device": "virtio-net", - "disk_interface": "virtio", - "boot_wait": "45s", - "boot_command": [ - "c", - "linux /casper/vmlinuz", - " auto url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/oem-preseed.cfg", - " automatic-ubiquity only-ubiquity", - " debug-ubiquity oem-config/enable=true", - " keymap=us fsck.mode=skip", - " noprompt splash --", - "initrd /casper/initrd ", - "boot" - ] - } - ], - "provisioners": [{ - "type": "shell", - "execute_command": "echo 'oem' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'", - "inline": [ - "while(pgrep -a apt-get); do sleep 1; done", - "export DEBIAN_FRONTEND=noninteractive", - "apt-get update", - "apt-get install -y git ansible aptitude", - "git clone -b {{user `git_branch`}} {{user `git_repo`}}", - "cd /home/oem/cs-vm-build/scripts", - "./oem-build", - "/usr/sbin/oem-config-prepare" - ] - }] -} diff --git a/packer/variables.pkr.hcl b/packer/variables.pkr.hcl index 57ee6a38..622b411d 100644 --- a/packer/variables.pkr.hcl +++ b/packer/variables.pkr.hcl @@ -71,6 +71,36 @@ variable "vm_name" { default = "JMU CS" } +variable "aarch64_boot_wait" { + type = string + default = "25s" + description = "The length of time to wait after boot before entering commands" + + validation { + condition = can(regex("\\d+s", var.aarch64_boot_wait)) + error_message = "The value should be a number of seconds followed by 's'." + } +} + +variable "qemu_accelerator" { + type = string + default = "kvm" + description = < Date: Mon, 2 Aug 2021 11:13:13 -0400 Subject: [PATCH 3/5] First attempt at config.plist --- packer/config.plist | 111 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 packer/config.plist diff --git a/packer/config.plist b/packer/config.plist new file mode 100644 index 00000000..a9025471 --- /dev/null +++ b/packer/config.plist @@ -0,0 +1,111 @@ + + + + + ConfigurationVersion + 2 + Debug + + DebugLog + + + Display + + ConsoleFont + Menlo + ConsoleFontSize + 12 + ConsoleTheme + Default + DisplayCard + virtio-ramfb-gl + DisplayDownscaler + linear + DisplayFitScreen + + DisplayRetina + + DisplayUpscaler + linear + + Drives + + + DriveName + drive0 + ImagePath + image.qcow2 + ImageType + disk + InterfaceType + virtio + + + Info + + Icon + ubuntu + IconCustom + + Notes + + + Input + + InputLegacy + + + Networking + + NetworkCard + virtio-net-pci + NetworkMode + emulated + + Printing + + Sharing + + ClipboardSharing + + DirectoryName + + DirectorySharing + + Usb3Support + + UsbRedirectMax + 3 + + Sound + + SoundCard + intel-hda + SoundEnabled + + + System + + Architecture + aarch64 + BootDevice + + CPU + cortex-a72 + CPUCount + 0 + ForceMulticore + + JITCacheSize + 0 + MachineProperties + highmem=off + Memory + 4096 + SystemUUID + 1A9B879C-CDA8-4728-AA9A-4717B646E9AC + Target + virt + + + From 0bd76e147b2bd5ad3736f9a93736faf5d874cd52 Mon Sep 17 00:00:00 2001 From: Mike Ripley Date: Sun, 15 Aug 2021 10:09:36 -0400 Subject: [PATCH 4/5] Refuse to remove empty string snaps --- roles/oem/tasks/ubuntu_only.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/roles/oem/tasks/ubuntu_only.yml b/roles/oem/tasks/ubuntu_only.yml index 23af26b9..a38613f5 100644 --- a/roles/oem/tasks/ubuntu_only.yml +++ b/roles/oem/tasks/ubuntu_only.yml @@ -13,9 +13,11 @@ errors=0 changed="" while read snapname revision; do - snap remove "$snapname" --revision="$revision" + if [[ -n "$snapname" ]] && [[ -n "$revision" ]]; then + snap remove "$snapname" --revision="$revision" + changed="Snap removed" + fi errors=$((errors + $?)) - changed="Snap removed" done <<< "$(snap list --all | awk '/disabled/{print $1, $3}')" echo $changed exit $errors From e8c7f2ce1e4c8ce4187adce0318e0e189e1151de Mon Sep 17 00:00:00 2001 From: Mike Ripley Date: Wed, 7 Feb 2024 16:14:32 -0500 Subject: [PATCH 5/5] aarch64 cleanups --- packer/http/oem-preseed.cfg | 1 + packer/main.pkr.hcl | 4 ++-- packer/variables.pkr.hcl | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packer/http/oem-preseed.cfg b/packer/http/oem-preseed.cfg index c2f7392d..04d4261d 100644 --- a/packer/http/oem-preseed.cfg +++ b/packer/http/oem-preseed.cfg @@ -66,6 +66,7 @@ ubiquity ubiquity/success_command string svcfile="/target/etc/systemd/system/ssh echo "ExecStart=/usr/bin/apt-get -y install openssh-server" >> "$svcfile"; \ echo "ExecStartPost=/bin/systemctl disable ssh-install.service" >> "$svcfile"; \ echo "ExecStartPost=/bin/rm /etc/systemd/system/ssh-install.service" >> "$svcfile"; \ + echo "TimeoutSec=300" >> "$svcfile"; \ echo "[Install]" >> "$svcfile"; \ echo "WantedBy=multi-user.target" >> "$svcfile"; \ in-target systemctl enable ssh-install.service diff --git a/packer/main.pkr.hcl b/packer/main.pkr.hcl index 01c8d921..43ccb9c8 100644 --- a/packer/main.pkr.hcl +++ b/packer/main.pkr.hcl @@ -24,8 +24,8 @@ source "qemu" "kvm" { http_directory = "http" qemu_binary = "qemu-system-aarch64" - efi_firmware_code = "${var.qemu_firmware_directory}/QEMU_EFI.fd" - efi_firmware_vars = "${var.qemu_firmware_directory}/QEMU_VARS.fd" + efi_firmware_code = "${var.qemu_firmware_directory}/AAVMF_CODE.fd" + efi_firmware_vars = "${var.qemu_firmware_directory}/AAVMF_VARS.fd" qemuargs = [ ["-boot", "strict=off"], ["-cpu", "host"], diff --git a/packer/variables.pkr.hcl b/packer/variables.pkr.hcl index 622b411d..aeafc913 100644 --- a/packer/variables.pkr.hcl +++ b/packer/variables.pkr.hcl @@ -93,7 +93,7 @@ variable "qemu_accelerator" { variable "qemu_firmware_directory" { type = string - default = "/usr/share/edk2/aarch64" + default = "/usr/share/AAVMF/" description = <