From 12756a89c2089f696c9e05bf8c95a093e25521a4 Mon Sep 17 00:00:00 2001 From: heqnx Date: Fri, 27 Jun 2025 10:46:00 +0300 Subject: added small readme, renamed json template --- packer/README.md | 55 +++++++++++++++++++ packer/ubuntu-24.04-server.json | 87 ------------------------------ packer/ubuntu-24.04-server_vm-builder.json | 87 ++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 87 deletions(-) create mode 100644 packer/README.md delete mode 100644 packer/ubuntu-24.04-server.json create mode 100644 packer/ubuntu-24.04-server_vm-builder.json (limited to 'packer') diff --git a/packer/README.md b/packer/README.md new file mode 100644 index 0000000..e688802 --- /dev/null +++ b/packer/README.md @@ -0,0 +1,55 @@ +# Packer Template for QEMU VM with Nested Virtualization + +This Packer template creates a QEMU-based virtual machine (VM) that can be used in Proxmox with nested virtualization enabled. It is designed for building other VMs inside this VM. + +## Requirements + +- Packer +- QEMU/KVM +- Ubuntu 24.04 Server ISO +- (Optional) Proxmox to run the image + +## Usage + +### Install Prerequisites + +- You can use the provided script to install all necessary tools on your host system or inside an existing VM: + +``` +./scripts/install-prerequisites.sh +``` + +- This sets up tools like Packer, QEMU, and Docker. + +### Build the image + +- Run the following command from the project root to build the image: + +``` +packer build ubuntu-qemu-template.json +``` + +- The resulting .qcow2 image will be saved in the `output/` directory. + +### Post-Processing + +- After the build, the following script generates checksum files with the `scripts/create-checksums.sh` script. It produces .sums files with MD5 and SHA512 checksums. + +### Using the VM + +- Import the image into Proxmox and enable nested virtualization. +- You can then run this image as a VM capable of building other VMs using tools like Packer or Docker-in-Docker. + +## Notes + +- The image uses Ubuntu 24.04 Live Server. +- `scripts/sysprep.sh` prepares the image for reuse (e.g., clears logs, resets machine ID, etc.). +- The template sets defaults like 2 CPUs, 2 cores, 2 GB RAM. +- You can customize variables in the Packer template. + +## File Structure + +- `ubuntu-24.04-server_vm-builder.json` – Main Packer configuration. +- `scripts/install-prerequisites.sh` – Installs dependencies. +- `scripts/sysprep.sh` – Cleans and prepares the image. +- `scripts/create-checksums.sh` – Generates MD5/SHA512 checksums. diff --git a/packer/ubuntu-24.04-server.json b/packer/ubuntu-24.04-server.json deleted file mode 100644 index 397bdba..0000000 --- a/packer/ubuntu-24.04-server.json +++ /dev/null @@ -1,87 +0,0 @@ -{ - "variables": { - "iso_name": "ubuntu-24.04-live-server-amd64.iso", - "iso_url": "https://old-releases.ubuntu.com/releases/24.04/ubuntu-24.04-live-server-amd64.iso", - "iso_path": "{{pwd}}/iso/{{user `iso_name`}}", - "iso_sha256": "sha256:8762f7e74e4d64d72fceb5f70682e6b069932deedb4949c6975d0f0fe0a91be3", - "timestamp": "{{isotime `2006-01-02`}}", - "headless": "false", - "boot_wait": "5s", - - "name": "ubuntu-24.04-server_vm-builder", - "cpu": "2", - "cores": "2", - "ram": "2048", - "communicator_username": "root", - "communicator_password": "root" - }, - - "builders": [ - { - "type": "qemu", - "format": "qcow2", - "accelerator": "kvm", - "net_device": "virtio-net", - "disk_interface": "virtio", - "headless": "{{user `headless`}}", - "name": "qemu", - "vm_name": "qemu-{{user `name`}}_{{user `timestamp`}}", - "disk_size": "{{user `disk_size`}}", - "disk_cache": "none", - "disk_discard": "unmap", - "disk_compression": true, - "communicator": "ssh", - "ssh_username": "{{user `communicator_username`}}", - "ssh_password": "{{user `communicator_password`}}", - "ssh_pty": true, - "ssh_timeout": "60m", - "ssh_handshake_attempts": "1337", - "shutdown_command": "shutdown -P now", - "boot_wait": "{{user `boot_wait`}}", - "boot_command": [ - "c", - "set gfxpayload=keep", - "linux /casper/vmlinuz --- quiet splash autoinstall ds='nocloud-net;seedfrom=http://{{.HTTPIP}}:{{.HTTPPort}}/'", - "initrd /casper/initrd", - "boot" - ], - "iso_urls": [ - "{{user `iso_path`}}", - "{{user `iso_url`}}" - ], - "iso_checksum": "{{user `iso_sha256`}}", - "iso_target_path": "{{user `iso_path`}}", - "http_directory": "answer_files", - "output_directory": "qemu_{{user `name`}}", - "qemuargs": [ - ["-m", "{{user `ram`}}M"], - ["-cpu", "host"], - ["-smp", "cpus={{user `cpu`}}"] - ] - } - ], - - "provisioners": [ - { - "type": "shell", - "script": "scripts/install-prerequisites.sh" - }, - { - "type": "shell", - "script": "scripts/sysprep.sh" - } - ], - - "post-processors": [ - { - "type": "shell-local", - "only_on": ["linux"], - "environment_vars": [ - "NAME={{user `name`}}", - "TIMESTAMP={{user `timestamp`}}", - "OUTPUT={{user `output`}}" - ], - "script": "scripts/create-checksums.sh" - } - ] -} diff --git a/packer/ubuntu-24.04-server_vm-builder.json b/packer/ubuntu-24.04-server_vm-builder.json new file mode 100644 index 0000000..397bdba --- /dev/null +++ b/packer/ubuntu-24.04-server_vm-builder.json @@ -0,0 +1,87 @@ +{ + "variables": { + "iso_name": "ubuntu-24.04-live-server-amd64.iso", + "iso_url": "https://old-releases.ubuntu.com/releases/24.04/ubuntu-24.04-live-server-amd64.iso", + "iso_path": "{{pwd}}/iso/{{user `iso_name`}}", + "iso_sha256": "sha256:8762f7e74e4d64d72fceb5f70682e6b069932deedb4949c6975d0f0fe0a91be3", + "timestamp": "{{isotime `2006-01-02`}}", + "headless": "false", + "boot_wait": "5s", + + "name": "ubuntu-24.04-server_vm-builder", + "cpu": "2", + "cores": "2", + "ram": "2048", + "communicator_username": "root", + "communicator_password": "root" + }, + + "builders": [ + { + "type": "qemu", + "format": "qcow2", + "accelerator": "kvm", + "net_device": "virtio-net", + "disk_interface": "virtio", + "headless": "{{user `headless`}}", + "name": "qemu", + "vm_name": "qemu-{{user `name`}}_{{user `timestamp`}}", + "disk_size": "{{user `disk_size`}}", + "disk_cache": "none", + "disk_discard": "unmap", + "disk_compression": true, + "communicator": "ssh", + "ssh_username": "{{user `communicator_username`}}", + "ssh_password": "{{user `communicator_password`}}", + "ssh_pty": true, + "ssh_timeout": "60m", + "ssh_handshake_attempts": "1337", + "shutdown_command": "shutdown -P now", + "boot_wait": "{{user `boot_wait`}}", + "boot_command": [ + "c", + "set gfxpayload=keep", + "linux /casper/vmlinuz --- quiet splash autoinstall ds='nocloud-net;seedfrom=http://{{.HTTPIP}}:{{.HTTPPort}}/'", + "initrd /casper/initrd", + "boot" + ], + "iso_urls": [ + "{{user `iso_path`}}", + "{{user `iso_url`}}" + ], + "iso_checksum": "{{user `iso_sha256`}}", + "iso_target_path": "{{user `iso_path`}}", + "http_directory": "answer_files", + "output_directory": "qemu_{{user `name`}}", + "qemuargs": [ + ["-m", "{{user `ram`}}M"], + ["-cpu", "host"], + ["-smp", "cpus={{user `cpu`}}"] + ] + } + ], + + "provisioners": [ + { + "type": "shell", + "script": "scripts/install-prerequisites.sh" + }, + { + "type": "shell", + "script": "scripts/sysprep.sh" + } + ], + + "post-processors": [ + { + "type": "shell-local", + "only_on": ["linux"], + "environment_vars": [ + "NAME={{user `name`}}", + "TIMESTAMP={{user `timestamp`}}", + "OUTPUT={{user `output`}}" + ], + "script": "scripts/create-checksums.sh" + } + ] +} -- cgit v1.2.3