I am performing these steps on Ubuntu 22.04 host:
Download the cloud image
qemu-img create -b ../jammy-server-cloudimg-amd64.img -f qcow2 -F qcow2 myubuntu2204test01-base.img 10G
Create the file meta-data in the directory myubuntu2204test01:
instance-id: myubuntu2204test01
local-hostname: myubuntu2204test01.example.com
network:
version: 2
ethernets:
enp1s0:
dhcp4: no
addresses: [192.168.122.146/24]
nameservers:
addresses: [192.168.122.1]
routes:
- to: 0.0.0.0/0
via: 192.168.122.1
Create the file user-data in the directory myubuntu2204test01:
#cloud-config
users:
- name: someuser
ssh_authorized_keys:
- ssh-ed25519 somekey comment
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
groups: sudo
shell: /bin/bash
Generate the ISO image for ci
data
genisoimage -output cidata.iso -V cidata -r -J user-data meta-data
Create The VM myubuntu2204test01
virt-install \
--name=testvmubuntu2204 \
--ram=512 --vcpus=1 \
--import \
--disk path=myubuntu2204test01-base.img,format=qcow2 \
--disk path=cidata.iso,device=cdrom \
--os-variant=ubuntu22.04 \
--network bridge=virbr0,model=virtio \
--graphics vnc,listen=0.0.0.0 --noautoconsole
The VM is created. But the VM does not have static IP networking as defined in meta-data. The VM has a default DHCP network configuration.
What is missing or incorrect in this process to create static IP for the guest VM?
I have tried defining the networking in both user-data and meta-data files, both of them fails to create static networking for the guest VM.
According to the cloud-init documentation:
It looks ike you're trying to use a version 2 network configuration; that means you're providing it in the wrong file. You need to add
network-config
rather thanmeta-data
.As I mentioned in the comment, you also need to correct the format of the network config file:
You can simplify your life by using the
--cloud-init
option tovirt-install
rather than building the config disk yourself:(This presumes you have files locally named
user-dat.ayaml
andnetwork-config.yaml
; adjust as appropriate.)