From 0a38d6866fcbb628a6a0469f4a7e0f5657a1aee4 Mon Sep 17 00:00:00 2001 From: Stephen Andary Date: Mon, 16 Oct 2023 10:54:17 -0400 Subject: [PATCH 1/8] initial checkin to begin conversation about bet way to create vagrant box for local use before pushing to maas --- ubuntu/ubuntu-lvm.pkr.hcl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ubuntu/ubuntu-lvm.pkr.hcl b/ubuntu/ubuntu-lvm.pkr.hcl index 5819c989..dd019bc4 100644 --- a/ubuntu/ubuntu-lvm.pkr.hcl +++ b/ubuntu/ubuntu-lvm.pkr.hcl @@ -47,4 +47,8 @@ build { post-processor "compress" { output = "custom-ubuntu-lvm.dd.gz" } + + post-processor "vagrant" { + output = "custom-ubuntu-lvm.box" + } } From 36ff9957753c54ec901bee3aa48d6bb032156adf Mon Sep 17 00:00:00 2001 From: Stephen Andary Date: Mon, 16 Oct 2023 15:47:07 -0400 Subject: [PATCH 2/8] create separate file for virtualbox as libvirt did not work --- .gitignore | 1 + ubuntu/Makefile | 10 ++++++-- ubuntu/ubuntu-lvm.pkr.hcl | 4 ---- ubuntu/ubuntu-virtualbox.pkr.hcl | 39 ++++++++++++++++++++++++++++++++ ubuntu/user-data-virtbox | 23 +++++++++++++++++++ 5 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 ubuntu/ubuntu-virtualbox.pkr.hcl create mode 100644 ubuntu/user-data-virtbox diff --git a/.gitignore b/.gitignore index a67c9cec..8e4e01d0 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ packer_cache \#*\# .#* *.*.swp +*.box *.gz *.xz *.iso diff --git a/ubuntu/Makefile b/ubuntu/Makefile index 4a166e56..6a479882 100644 --- a/ubuntu/Makefile +++ b/ubuntu/Makefile @@ -26,6 +26,9 @@ seeds-lvm.iso: user-data-lvm meta-data seeds-flat.iso: user-data-flat meta-data cloud-localds $@ $^ +seeds-virtbox.iso: user-data-virtbox meta-data + cloud-localds $@ $^ + OVMF_VARS.fd: /usr/share/OVMF/OVMF_VARS.fd cp -v $< $@ @@ -39,9 +42,12 @@ custom-ubuntu.tar.gz: check-deps clean seeds-flat.iso OVMF_VARS.fd \ custom-ubuntu-lvm.dd.gz: check-deps clean seeds-lvm.iso OVMF_VARS.fd ${PACKER} init . && ${PACKER} build -only=qemu.lvm . +custom-ubuntu-virtbox.box: check-deps clean seeds-virtbox.iso OVMF_VARS.fd + ${PACKER} init . && ${PACKER} build -only=virtualbox-iso.lvm . + clean: ${RM} -rf output-* custom-*.gz \ - seeds-flat.iso seeds-lvm.iso seeds-cloudimg.iso \ + seeds-flat.iso seeds-lvm.iso seeds-virtbox.iso seeds-cloudimg.iso \ OVMF_VARS.fd CUSTOM_PKGS:=${wildcard packages/*.deb} @@ -54,4 +60,4 @@ else endif .INTERMEDIATE: OVMF_VARS.fd packages/custom-packages.tar.gz \ - seeds-flat.iso seeds-lvm.iso seeds-cloudimg.iso + seeds-flat.iso seeds-lvm.iso seeds-virtbox.iso seeds-cloudimg.iso diff --git a/ubuntu/ubuntu-lvm.pkr.hcl b/ubuntu/ubuntu-lvm.pkr.hcl index dd019bc4..5819c989 100644 --- a/ubuntu/ubuntu-lvm.pkr.hcl +++ b/ubuntu/ubuntu-lvm.pkr.hcl @@ -47,8 +47,4 @@ build { post-processor "compress" { output = "custom-ubuntu-lvm.dd.gz" } - - post-processor "vagrant" { - output = "custom-ubuntu-lvm.box" - } } diff --git a/ubuntu/ubuntu-virtualbox.pkr.hcl b/ubuntu/ubuntu-virtualbox.pkr.hcl new file mode 100644 index 00000000..451e16a0 --- /dev/null +++ b/ubuntu/ubuntu-virtualbox.pkr.hcl @@ -0,0 +1,39 @@ +source "virtualbox-iso" "lvm" { + boot_command = ["e", "", "autoinstall ---"] + boot_wait = "2s" + cpus = 2 + disk_size = 8192 + guest_os_type = "Ubuntu_64" + headless = var.headless + http_directory = var.http_directory + iso_checksum = "file:http://releases.ubuntu.com/jammy/SHA256SUMS" + iso_url = "https://releases.ubuntu.com/jammy/ubuntu-22.04.3-live-server-amd64.iso" + memory = 2048 + shutdown_command = "sudo -S shutdown -P now" + ssh_handshake_attempts = 500 + ssh_password = var.ssh_ubuntu_password + ssh_timeout = "45m" + ssh_username = "ubuntu" + ssh_wait_timeout = "45m" + vm_name = "packer-lvm" +} + +build { + sources = ["source.virtualbox-iso.lvm"] + + provisioner "file" { + destination = "/tmp/curtin-hooks" + source = "${path.root}/scripts/curtin-hooks" + } + + provisioner "shell" { + environment_vars = ["HOME_DIR=/home/ubuntu", "http_proxy=${var.http_proxy}", "https_proxy=${var.https_proxy}", "no_proxy=${var.no_proxy}"] + execute_command = "echo 'ubuntu' | {{ .Vars }} sudo -S -E sh -eux '{{ .Path }}'" + expect_disconnect = true + scripts = ["${path.root}/scripts/curtin.sh", "${path.root}/scripts/networking.sh", "${path.root}/scripts/cleanup.sh"] + } + + post-processor "vagrant" { + output = "custom-ubuntu-virtbox.box" + } +} \ No newline at end of file diff --git a/ubuntu/user-data-virtbox b/ubuntu/user-data-virtbox new file mode 100644 index 00000000..d3753623 --- /dev/null +++ b/ubuntu/user-data-virtbox @@ -0,0 +1,23 @@ +#cloud-config +autoinstall: + version: 1 + identity: + hostname: ubuntu + username: ubuntu + password: "$6$canonical.$0zWaW71A9ke9ASsaOcFTdQ2tx1gSmLxMPrsH0rF0Yb.2AEKNPV1lrF94n6YuPJmnUy2K2/JSDtxuiBDey6Lpa/" + keyboard: + layout: us + variant: '' + ssh: + install-server: true + storage: + grub: + update_nvram: true + swap: + size: 0 + layout: + name: lvm + late-commands: + - echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' > /target/etc/sudoers.d/ubuntu + package_update: true + package_upgrade: true From dc7e287e7c8f94eb57281e97265cc6ce21c3a72f Mon Sep 17 00:00:00 2001 From: Stephen Andary Date: Mon, 16 Oct 2023 15:56:23 -0400 Subject: [PATCH 3/8] minor name changes --- ubuntu/Makefile | 10 +++++----- ubuntu/ubuntu-virtualbox.pkr.hcl | 6 +++--- ubuntu/{user-data-virtbox => user-data-box} | 0 3 files changed, 8 insertions(+), 8 deletions(-) rename ubuntu/{user-data-virtbox => user-data-box} (100%) diff --git a/ubuntu/Makefile b/ubuntu/Makefile index 6a479882..dbcceca3 100644 --- a/ubuntu/Makefile +++ b/ubuntu/Makefile @@ -26,7 +26,7 @@ seeds-lvm.iso: user-data-lvm meta-data seeds-flat.iso: user-data-flat meta-data cloud-localds $@ $^ -seeds-virtbox.iso: user-data-virtbox meta-data +seeds-box.iso: user-data-box meta-data cloud-localds $@ $^ OVMF_VARS.fd: /usr/share/OVMF/OVMF_VARS.fd @@ -42,12 +42,12 @@ custom-ubuntu.tar.gz: check-deps clean seeds-flat.iso OVMF_VARS.fd \ custom-ubuntu-lvm.dd.gz: check-deps clean seeds-lvm.iso OVMF_VARS.fd ${PACKER} init . && ${PACKER} build -only=qemu.lvm . -custom-ubuntu-virtbox.box: check-deps clean seeds-virtbox.iso OVMF_VARS.fd - ${PACKER} init . && ${PACKER} build -only=virtualbox-iso.lvm . +custom-ubuntu-box.box: check-deps clean seeds-box.iso OVMF_VARS.fd + ${PACKER} init . && ${PACKER} build -only=virtualbox-iso.box . clean: ${RM} -rf output-* custom-*.gz \ - seeds-flat.iso seeds-lvm.iso seeds-virtbox.iso seeds-cloudimg.iso \ + seeds-flat.iso seeds-lvm.iso seeds-box.iso seeds-cloudimg.iso \ OVMF_VARS.fd CUSTOM_PKGS:=${wildcard packages/*.deb} @@ -60,4 +60,4 @@ else endif .INTERMEDIATE: OVMF_VARS.fd packages/custom-packages.tar.gz \ - seeds-flat.iso seeds-lvm.iso seeds-virtbox.iso seeds-cloudimg.iso + seeds-flat.iso seeds-lvm.iso seeds-box.iso seeds-cloudimg.iso diff --git a/ubuntu/ubuntu-virtualbox.pkr.hcl b/ubuntu/ubuntu-virtualbox.pkr.hcl index 451e16a0..9af0fc34 100644 --- a/ubuntu/ubuntu-virtualbox.pkr.hcl +++ b/ubuntu/ubuntu-virtualbox.pkr.hcl @@ -1,4 +1,4 @@ -source "virtualbox-iso" "lvm" { +source "virtualbox-iso" "box" { boot_command = ["e", "", "autoinstall ---"] boot_wait = "2s" cpus = 2 @@ -15,11 +15,11 @@ source "virtualbox-iso" "lvm" { ssh_timeout = "45m" ssh_username = "ubuntu" ssh_wait_timeout = "45m" - vm_name = "packer-lvm" + vm_name = "packer-box" } build { - sources = ["source.virtualbox-iso.lvm"] + sources = ["source.virtualbox-iso.box"] provisioner "file" { destination = "/tmp/curtin-hooks" diff --git a/ubuntu/user-data-virtbox b/ubuntu/user-data-box similarity index 100% rename from ubuntu/user-data-virtbox rename to ubuntu/user-data-box From 45db8aea3c28abe74c4be1c40ee0b41683fc180b Mon Sep 17 00:00:00 2001 From: Stephen Andary Date: Mon, 16 Oct 2023 16:04:59 -0400 Subject: [PATCH 4/8] minor name changes --- ubuntu/Makefile | 2 +- ubuntu/README.md | 6 ++++++ ubuntu/{ubuntu-virtualbox.pkr.hcl => ubuntu-box.pkr.hcl} | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) rename ubuntu/{ubuntu-virtualbox.pkr.hcl => ubuntu-box.pkr.hcl} (97%) diff --git a/ubuntu/Makefile b/ubuntu/Makefile index dbcceca3..a7716833 100644 --- a/ubuntu/Makefile +++ b/ubuntu/Makefile @@ -42,7 +42,7 @@ custom-ubuntu.tar.gz: check-deps clean seeds-flat.iso OVMF_VARS.fd \ custom-ubuntu-lvm.dd.gz: check-deps clean seeds-lvm.iso OVMF_VARS.fd ${PACKER} init . && ${PACKER} build -only=qemu.lvm . -custom-ubuntu-box.box: check-deps clean seeds-box.iso OVMF_VARS.fd +custom-ubuntu-virtual.box: check-deps clean seeds-box.iso OVMF_VARS.fd ${PACKER} init . && ${PACKER} build -only=virtualbox-iso.box . clean: diff --git a/ubuntu/README.md b/ubuntu/README.md index 292382bb..1bfafcdc 100644 --- a/ubuntu/README.md +++ b/ubuntu/README.md @@ -109,6 +109,12 @@ to build a raw image with LVM, alternatively, you can build a TGZ image make custom-ubuntu.tar.gz ``` +To build a virtualbox image for vagrant using the Makefile: + +```shell +make custom-ubuntu-virtual.box +``` + You can also manually run packer. Your current working directory must be in packer-maas/ubuntu, where this file is located. Once in packer-maas/ubuntu you can generate an image with: diff --git a/ubuntu/ubuntu-virtualbox.pkr.hcl b/ubuntu/ubuntu-box.pkr.hcl similarity index 97% rename from ubuntu/ubuntu-virtualbox.pkr.hcl rename to ubuntu/ubuntu-box.pkr.hcl index 9af0fc34..14308faf 100644 --- a/ubuntu/ubuntu-virtualbox.pkr.hcl +++ b/ubuntu/ubuntu-box.pkr.hcl @@ -34,6 +34,6 @@ build { } post-processor "vagrant" { - output = "custom-ubuntu-virtbox.box" + output = "custom-ubuntu-virtual.box" } } \ No newline at end of file From f8918dbdfd45af15e3bbf024bd043ff0218cc78d Mon Sep 17 00:00:00 2001 From: Stephen Andary Date: Mon, 16 Oct 2023 16:15:40 -0400 Subject: [PATCH 5/8] add plugin blocks into files, as not including them is deprecated --- ubuntu/ubuntu-box.pkr.hcl | 17 +++++++++++++++++ ubuntu/ubuntu-flat.pkr.hcl | 9 +++++++++ ubuntu/ubuntu-lvm.pkr.hcl | 9 +++++++++ 3 files changed, 35 insertions(+) diff --git a/ubuntu/ubuntu-box.pkr.hcl b/ubuntu/ubuntu-box.pkr.hcl index 14308faf..da9ef91b 100644 --- a/ubuntu/ubuntu-box.pkr.hcl +++ b/ubuntu/ubuntu-box.pkr.hcl @@ -1,3 +1,20 @@ +packer { + required_plugins { + qemu = { + source = "github.com/hashicorp/qemu" + version = "~> 1" + } + virtualbox = { + version = "~> 1" + source = "github.com/hashicorp/virtualbox" + } + vagrant = { + source = "github.com/hashicorp/vagrant" + version = "~> 1" + } + } +} + source "virtualbox-iso" "box" { boot_command = ["e", "", "autoinstall ---"] boot_wait = "2s" diff --git a/ubuntu/ubuntu-flat.pkr.hcl b/ubuntu/ubuntu-flat.pkr.hcl index aea17632..4b55b3ea 100644 --- a/ubuntu/ubuntu-flat.pkr.hcl +++ b/ubuntu/ubuntu-flat.pkr.hcl @@ -4,6 +4,15 @@ variable "flat_filename" { description = "The filename of the tarball to produce" } +packer { + required_plugins { + qemu = { + source = "github.com/hashicorp/qemu" + version = "~> 1" + } + } +} + source "qemu" "flat" { boot_command = ["e", "", "autoinstall ---"] boot_wait = "2s" diff --git a/ubuntu/ubuntu-lvm.pkr.hcl b/ubuntu/ubuntu-lvm.pkr.hcl index 5819c989..e23fa8d1 100644 --- a/ubuntu/ubuntu-lvm.pkr.hcl +++ b/ubuntu/ubuntu-lvm.pkr.hcl @@ -1,3 +1,12 @@ +packer { + required_plugins { + qemu = { + source = "github.com/hashicorp/qemu" + version = "~> 1" + } + } +} + source "qemu" "lvm" { boot_command = ["e", "", "autoinstall ---"] boot_wait = "2s" From 3e42bdd328b3e86ce9d3a48e0fa2be9be5085f74 Mon Sep 17 00:00:00 2001 From: Stephen Andary Date: Mon, 16 Oct 2023 16:17:43 -0400 Subject: [PATCH 6/8] missed 1 file for plugins --- ubuntu/ubuntu-cloudimg.pkr.hcl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ubuntu/ubuntu-cloudimg.pkr.hcl b/ubuntu/ubuntu-cloudimg.pkr.hcl index 23f26627..c6137520 100644 --- a/ubuntu/ubuntu-cloudimg.pkr.hcl +++ b/ubuntu/ubuntu-cloudimg.pkr.hcl @@ -23,6 +23,15 @@ locals { ] } +packer { + required_plugins { + qemu = { + source = "github.com/hashicorp/qemu" + version = "~> 1" + } + } +} + source "null" "dependencies" { communicator = "none" } From 2bbf46df662e188fd2de9519a8c4e78be3b34e24 Mon Sep 17 00:00:00 2001 From: Stephen Andary Date: Mon, 16 Oct 2023 16:23:47 -0400 Subject: [PATCH 7/8] revert changes related to adding packer block for qemu plugin. Conflict --- ubuntu/ubuntu-box.pkr.hcl | 4 ---- ubuntu/ubuntu-cloudimg.pkr.hcl | 9 --------- ubuntu/ubuntu-flat.pkr.hcl | 9 --------- ubuntu/ubuntu-lvm.pkr.hcl | 9 --------- 4 files changed, 31 deletions(-) diff --git a/ubuntu/ubuntu-box.pkr.hcl b/ubuntu/ubuntu-box.pkr.hcl index da9ef91b..24bee290 100644 --- a/ubuntu/ubuntu-box.pkr.hcl +++ b/ubuntu/ubuntu-box.pkr.hcl @@ -1,9 +1,5 @@ packer { required_plugins { - qemu = { - source = "github.com/hashicorp/qemu" - version = "~> 1" - } virtualbox = { version = "~> 1" source = "github.com/hashicorp/virtualbox" diff --git a/ubuntu/ubuntu-cloudimg.pkr.hcl b/ubuntu/ubuntu-cloudimg.pkr.hcl index c6137520..23f26627 100644 --- a/ubuntu/ubuntu-cloudimg.pkr.hcl +++ b/ubuntu/ubuntu-cloudimg.pkr.hcl @@ -23,15 +23,6 @@ locals { ] } -packer { - required_plugins { - qemu = { - source = "github.com/hashicorp/qemu" - version = "~> 1" - } - } -} - source "null" "dependencies" { communicator = "none" } diff --git a/ubuntu/ubuntu-flat.pkr.hcl b/ubuntu/ubuntu-flat.pkr.hcl index 4b55b3ea..aea17632 100644 --- a/ubuntu/ubuntu-flat.pkr.hcl +++ b/ubuntu/ubuntu-flat.pkr.hcl @@ -4,15 +4,6 @@ variable "flat_filename" { description = "The filename of the tarball to produce" } -packer { - required_plugins { - qemu = { - source = "github.com/hashicorp/qemu" - version = "~> 1" - } - } -} - source "qemu" "flat" { boot_command = ["e", "", "autoinstall ---"] boot_wait = "2s" diff --git a/ubuntu/ubuntu-lvm.pkr.hcl b/ubuntu/ubuntu-lvm.pkr.hcl index e23fa8d1..5819c989 100644 --- a/ubuntu/ubuntu-lvm.pkr.hcl +++ b/ubuntu/ubuntu-lvm.pkr.hcl @@ -1,12 +1,3 @@ -packer { - required_plugins { - qemu = { - source = "github.com/hashicorp/qemu" - version = "~> 1" - } - } -} - source "qemu" "lvm" { boot_command = ["e", "", "autoinstall ---"] boot_wait = "2s" From a895f38a4ba8e42e0749bce8cf75f33db0d622e5 Mon Sep 17 00:00:00 2001 From: Stephen Andary Date: Mon, 16 Oct 2023 17:06:20 -0400 Subject: [PATCH 8/8] attempt at just converting qemuargs to vbmanage settings --- ubuntu/ubuntu-box.pkr.hcl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ubuntu/ubuntu-box.pkr.hcl b/ubuntu/ubuntu-box.pkr.hcl index 24bee290..17150daf 100644 --- a/ubuntu/ubuntu-box.pkr.hcl +++ b/ubuntu/ubuntu-box.pkr.hcl @@ -12,7 +12,7 @@ packer { } source "virtualbox-iso" "box" { - boot_command = ["e", "", "autoinstall ---"] + boot_command = ["e", "", "autoinstall ---"] boot_wait = "2s" cpus = 2 disk_size = 8192 @@ -20,6 +20,7 @@ source "virtualbox-iso" "box" { headless = var.headless http_directory = var.http_directory iso_checksum = "file:http://releases.ubuntu.com/jammy/SHA256SUMS" + iso_target_path = "packer_cache/ubuntu.iso" iso_url = "https://releases.ubuntu.com/jammy/ubuntu-22.04.3-live-server-amd64.iso" memory = 2048 shutdown_command = "sudo -S shutdown -P now" @@ -28,7 +29,16 @@ source "virtualbox-iso" "box" { ssh_timeout = "45m" ssh_username = "ubuntu" ssh_wait_timeout = "45m" - vm_name = "packer-box" + vboxmanage = [ + ["modifyvm", "{{.Name}}", "--vram", "16"], + ["modifyvm", "{{.Name}}", "--graphicscontroller", "vmsvga"], + ["storagectl", "{{.Name}}", "--name", "IDE Controller", "--add", "ide"], + ["storageattach", "{{.Name}}", "--storagectl", "IDE Controller", "--port", "0", "--device", "0", "--type", "hdd", "--medium", "output-lvm/packer-lvm.vdi"], + ["storageattach", "{{.Name}}", "--storagectl", "IDE Controller", "--port", "1", "--device", "0", "--type", "dvddrive", "--medium", "seeds-lvm.iso"], + ["storageattach", "{{.Name}}", "--storagectl", "IDE Controller", "--port", "2", "--device", "0", "--type", "dvddrive", "--medium", "packer_cache/ubuntu.iso"], + ["modifyvm", "{{.Name}}", "--firmware", "efi"], + ["modifyvm", "{{.Name}}", "--boot1", "disk", "--boot2", "dvd"] + ] } build {