ray5273 / packer-qemu-template

Packer Qemu Template
0 stars 0 forks source link

Packer QEMU Template

Packer QEMU Template for Ubuntu 22.04.02 live server

Prerequisite

Packer install

wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install packer

Packer plugin install

packer plugins install github.com/hashicorp/qemu
packer plugins install github.com/hashicorp/ansible

TODO list

Install QEMU

How To Build QEMU image with Packer

Build QEMU image by running following command

PACKER_LOG=1 packer build --force template.pkr.hcl

or more specific command

PACKER_LOG=1 packer build -only=qemu.template --force .

Expected build result in case of success

2023/09/24 23:37:03 [INFO] (telemetry) ending qemu.template
==> Wait completed after 13 minutes 55 seconds
Build 'qemu.template' finished after 13 minutes 55 seconds.
==> Builds finished. The artifacts of successful builds are:

2023/09/24 23:37:03 machine readable: qemu.template,artifact-count []string{"1"}
==> Wait completed after 13 minutes 55 seconds

in case of building image without KVM accelerate, it can take more time than 1 Hour (Takes 1 Hour 16 minutes with following options : without accelerate, cpu=3, memory=4096 option).

How To Run QEMU image built by Packer


# Custom Configuration

## Password Generation in http/user-data

`openssl passwd -6 -salt xyz`

result of following command should be added in user-data

cloud-config

user-data: users:


## How to set vnc server in QEMU running server
- vnc_bind_address set "0.0.0.0" in template.pkr.hcl
- open inbound ports if you use cloud services (Azure, AWS, GCP)
- open firewall like following commands

open 5900~6000 port

sudo ufw allow 5900:6000/tcdp sudo ufw allow 5900:6000/udp

restart firewall setting

sudo ufw disable sudo ufw enable

sudo ufw status


# Upload template file to Canonical MAAS

## How to upload template file

- Refer following link (https://maas.io/docs/how-to-customise-images#heading--how-to-upload-packer-images-to-maas)
- Need packer packages for generating Ubuntu template.

sudo apt install packer sudo apt install qemu-utils sudo apt install qemu-system sudo apt install ovmf sudo apt install cloud-image-utils


- Upload packer image to MAAS

$ maas admin boot-resources create \ name='custom/ubuntu-raw' \ title='Ubuntu Custom RAW' \ architecture='amd64/generic' \ filetype='ddgz' \ content@=ubuntu-2204-server.dd.gz