Installing the Virtualization Stack and Preparing Cloud-init Configuration
This guide explains how to install the virtualization stack and prepare an Ubuntu cloud image and cloud-init configuration for a virtual machine.
Prerequisites
Complete Enabling SR-IOV Virtual Functions before continuing. You need a user account with sudo privileges and network access to download packages and the Ubuntu cloud image.
Installing and preparing the virtualization environment
Update the system and install QEMU/KVM, libvirt, and supporting tools.
sudo apt update && sudo apt upgrade -y sudo apt autoremove sudo apt install qemu-kvm bridge-utils virt-manager \ libvirt-daemon-system libvirt-clients -y
Enable and start the libvirt service.
sudo systemctl enable libvirtd sudo systemctl start libvirtd sudo systemctl status libvirtd
Add your user account to the
libvirtandkvmgroups. Log out and back in, or start a new login session, for the new group memberships to take effect.sudo usermod -aG libvirt,kvm $USER
Install
genisoimage, which you will use to create the cloud-init seed ISO for the virtual machine.sudo apt install genisoimage
Download the Ubuntu 24.04 cloud image to the libvirt images directory. The cloud image is a preinstalled disk image that is configured on first boot by cloud-init, so no interactive installation is needed.
sudo wget https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img \ -P /var/lib/libvirt/images/
Create the virtual machine disk from the cloud image. The disk uses the cloud image as a read-only backing file, so the same image can be reused for multiple virtual machines. The disk is grown to the requested size automatically on first boot.
sudo qemu-img create -f qcow2 -F qcow2 \ -b /var/lib/libvirt/images/noble-server-cloudimg-amd64.img \ /var/lib/libvirt/images/ubuntu-vm1.qcow2 100G
Generate an SSH key pair so you can log in to the virtual machine without a password.
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ""
Display the public key and copy it for use in the
user-datafile in step 10.cat ~/.ssh/id_ed25519.pubCreate a working directory.
mkdir -p ~/vm-init && cd ~/vm-init
Create
user-data, replacingYOUR_PUBLIC_KEYwith the public key you copied earlier. This configuration creates thevmadminuser with passwordless sudo privileges and membership in therenderandvideogroups for GPU access.cat > user-data <<'EOF' #cloud-config users: - name: vmadmin sudo: ALL=(ALL) NOPASSWD:ALL groups: sudo,video,render shell: /bin/bash ssh_authorized_keys: - YOUR_PUBLIC_KEY ssh_pwauth: false EOF
If the host accesses the internet through a proxy, add the proxy settings to
user-dataso the virtual machine can install packages. For example:apt: http_proxy: http://<PROXY_HOST>:<PORT> https_proxy: http://<PROXY_HOST>:<PORT>
Create
meta-data.cat > meta-data <<'EOF' instance-id: vm1 local-hostname: ubuntu-vm1 EOF
Package
user-dataandmeta-datainto a cloud-init seed ISO that the virtual machine reads on first boot.sudo genisoimage -output /var/lib/libvirt/images/vm1-seed.iso \ -volid cidata -joliet -rock user-data meta-data