Skip to content

VM Quick install

Debian 13, Ubuntu 24.04 LTS

Packages

debian 13 need to boot from UEFI so you need to install ovfm package on your hypervisor.

sudo apt install ovfm

Rapid deployment with cloud-img

1️⃣ Download a Cloud Image

cloud-init is already installed on those generic images (not on nocloud images).

Get a debian cloud image:

wget https://cloud.debian.org/images/cloud/trixie/latest/debian-13-generic-amd64.qcow2

Then copy image to /var/lib/libvirt/images:

sudo cp debian-13-generic-amd64.qcow2 /var/lib/libvirt/images/debian-13-generic-amd64.qcow2

2️⃣ Create user-data and meta-data

This user-data file creates a user named locadmin:

hostname: testvm
manage_etc_hosts: true
disable_root: false
chpasswd:
  list: |
    root:password
  expire: False

users:
  - name: ansible
    gecos: Ansible User
    groups: sudo
    shell: /bin/bash
    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    ssh_authorized_keys:
      - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGboh8qF6vDcZMLoU+54r+RvZv6smo6rH7N4LnaL0ULZ benoit@ymir

package_update: true
package_upgrade: true
packages:
  - python3
  - python3-apt
  - qemu-guest-agent
  - git

ssh_deletekeys: true
ssh_genkeytypes: ['rsa', 'ecdsa', 'ed25519']


runcmd:
  - systemctl enable --now qemu-guest-agent

timezone: Europe/Paris

Create meta-data:

instance-id: testvm01
local-hostname: testvm

3️⃣ Create the Cloud-Init ISO

Combine both into an ISO image for the VM:

genisoimage -output seed.iso -volid cidata -joliet -rock user-data meta-data

(cloud-localds from cloud-utils can also do this, but genisoimage works everywhere - so ok on the hypervisor.)

Then move this seed.iso image to /var/lib/libvirt/images/:

sudo mv seed.iso /var/lib/libvirt/images/seed.iso

4️⃣ Create the VM with virt-install

Here’s a working example using virt-install:

sudo virt-install \
  --name testvm \
  --memory 2048 \
  --vcpus 2 \
  --disk path=/var/lib/libvirt/images/testvm01-debian13.qcow2,backing_store=/var/lib/libvirt/images/debian-13-generic-amd64.qcow2,size=10 \
  --disk path=/var/lib/libvirt/images/seed.iso,device=cdrom \
  --os-variant debian13 \
  --import \
  --network network=nat,model=virtio \
  --network network=br0,model=virtio \
  --virt-type kvm \
  --graphics none \
  --boot uefi  \
  --noautoconsole

Notes:

  • --import skips installation since the image already has an OS.
  • The backing_store pattern creates a copy-on-write (COW) layer so you don’t modify the base image.
  • The seed.iso injects your cloud-init config, so can be kept among all VMs created.
  • The qemu-guest-agent helps with IP reporting, shutdowns, etc.

Remove VM

To Remove VM, use:

1
2
3
sudo virsh destroy testvm
sudo virsh undefine testvm --nvram
sudo rm /var/lib/libvirt/images/testvm01-debian13.qcow2