I am trying to write a script to automate deployment of VMs. So I am testing configurations for various platforms.
Problem
Creating virtual machines in KVM/libvirt/QEMU using the cloud images from Ubuntu (or Fedora) fails when secure-boot is enabled.
System Info
- Host: Debian Bookworm
Steps to reproduce
- Create
cloud-init'suser-datafile with the contents below, (uncomment plain text password and lock for testing).
sudo nano /home/VMs/cloud-init/user-data
#cloud-config
hostname: ubuntutest
users:
name: testuser
plain_text_passwd: testpwd
lock-passwd: false
groups: sudo
sudo: "ALL=(ALL) NOPASSWD: ALL"
shell: /bin/bash
ssh_authorized_keys: <REDACTED>
- Download an Ubuntu (or Fedora) cloud image
https://cloud-images.ubuntu.com/<codename>/current/<codename>-server-cloudimg-amd64.img(Tried 24.04, 24.10, and 25.04 so far). - (optional) Make a copy, so one is not downloading the image every time
sudo cp <codename>-server-cloudimg-amd64.img /home/VMs/volumes/test.qcow2
- Install system using
virt-install
virt-install \
--name ubuntutest \
--ram 2048 \
--vcpus 2 \
--disk path=/home/VMs/volumes/test.qcow2 \
--cloud-init user-data=/home/VMs/cloud-init/user-data \
--os-variant ubuntu22.04 \
--network network=default,model=virtio \
--boot uefi,loader_secure=yes \
--tpm emulator \
--machine q35 \
--import
Errors
When I run the command above, I get the output below.
BdsDxe: loading Boot0002 "UEFI Misc Device" from PciRoot(0x0)/Pci(0x2,0x3)/Pci(0x0,0x0)
BdsDxe: starting Boot0002 "UEFI Misc Device" from PciRoot(0x0)/Pci(0x2,0x3)/Pci(0x0,0x0)
Reset System
Domain creation completed.
Then the VM shuts down, really fast!.
I can turn it on afterwards, but it is a VM with all the default configurations. Clearly cloud-init did not run upon creation.
Comments
The 4 steps work perfectly if the only thing you change is:
- Disable secure boot, i.e. delete the line
--boot uefi,loader_secure=yes.
Or
- Download Debian instead of Ubuntu. (Tried Debian 12 and 13).
Questions
how to make secure boot work with cloud images? Why is Debian working with no problems but other distributions like Ubuntu and Fedora don't seem to work here?
Any help is appreciated. Happy to provide more context if needed.