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..a7716833 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-box.iso: user-data-box 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-virtual.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-cloudimg.iso \ + seeds-flat.iso seeds-lvm.iso seeds-box.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-box.iso seeds-cloudimg.iso 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-box.pkr.hcl b/ubuntu/ubuntu-box.pkr.hcl new file mode 100644 index 00000000..17150daf --- /dev/null +++ b/ubuntu/ubuntu-box.pkr.hcl @@ -0,0 +1,62 @@ +packer { + required_plugins { + 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" + 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_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" + ssh_handshake_attempts = 500 + ssh_password = var.ssh_ubuntu_password + ssh_timeout = "45m" + ssh_username = "ubuntu" + ssh_wait_timeout = "45m" + 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 { + sources = ["source.virtualbox-iso.box"] + + 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-virtual.box" + } +} \ No newline at end of file diff --git a/ubuntu/user-data-box b/ubuntu/user-data-box new file mode 100644 index 00000000..d3753623 --- /dev/null +++ b/ubuntu/user-data-box @@ -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