updated: 2025-10-20 Mon 00:00

cloud-init in Qemu


cloud-init in Qemu

cloud-init pre-configure system during boot process. We can also use cloud image in local qemu.

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

To pre-configure this image in local qemu, create the following files in a directory:

$ cat << EOF > user-data
#cloud-config
password: password
chpasswd:
  expire: False

EOF
$ cat << EOF > meta-data
instance-id: someid/somehostname

EOF
$ touch vendor-data
$ touch network-config

run webserver for cloud-init

$ python3 -m http.server --directory .

run qemu with -smbios option

qemu-system-x86_64                                              \
    -net nic                                                    \
    -net user                                                   \
    -machine accel=kvm:tcg                                      \
    -m 512                                                      \
    -nographic                                                  \
    -hda debian-13-generic-amd64-daily.qcow2                    \
    -smbios type=1,serial=ds='nocloud;s=http://10.0.2.2:8000/'

default username: debian

cloud-init will use the password configured in user-data file.

useful links
https://cloudinit.readthedocs.io/en/latest/tutorial/qemu.html