Environment

 

Setup Instructions

  1. update host
    // update host
    apt-get update -y && apt-get upgrade -y && apt autoremove -y
    apt install libguestfs-tools -y
    apt install build-essential -y

    libguestfs-tools allows direct editing of disk images
    It is used when you want to put cloud-init settings into the image. virt-customize, which is used in the third step, is included in the package.

  2. Downloading base image (ubuntu22.04)

    Customize the image

    ssh-keygen -t ecdsa -b 521 -C "{guest name}"
    
    // guest settings
    virt-customize -a jammy-server-cloudimg-amd64.img --run-command 'useradd {guest name}'
    virt-customize -a jammy-server-cloudimg-amd64.img --run-command 'mkdir -p /home/{guest name}/.ssh'
    virt-customize -a jammy-server-cloudimg-amd64.img --ssh-inject {guest name}:file:/home/{guest name}/.ssh/id_ecdsa.pub
    virt-customize -a jammy-server-cloudimg-amd64.img --run-command 'chown -R {guest name}:{guest name} /home/{guest name}'

    Using virt-customize, create a guest user to be used in the VM and set up ssh

  3. Proxmox image configuration
    qm command 

    // Proxmox image settings qm create 100 --name "ubuntu-2204-cloudinit-template" --memory 2048 --cores 2 --net0 virtio,bridge=vmbr0 qm importdisk 100 jammy-server-cloudimg-amd64.img local-lvm qm set 100 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-100-disk-0 qm set 100 --boot c --bootdisk scsi0 qm disk resize 100 scsi0 30G qm set 100 --ide2 local-lvm:cloudinit qm set 100 --serial0 socket --vga serial0 qm set 100 --agent enabled=1

    Specs (core, memory, disk size), ID (100), and disk specification (local-lvm) need to be changed as appropriate.

  4. Proxmox Template image create
    // Proxmox Template image create
    qm clone 100 1000 --name ubuntu2204-build-test --full
    qm set 1000 --sshkeys ~/.ssh/id_ecdsa.pub
    qm set 1000 --ipconfig0 ip=192.168.1.10/24,gw=192.168.1.1
    qm start 1000

Reference