tech:server:linux:virtualization:kvm-qemu:launch-virtual-machine-by-cloud-init-and-virt-install:launch-virtual-machine-by-cloud-init-and-virt-install

Launch QEMU/KVM+Libvirt Virtual Machine by virt-install+cloud-init with Ubuntu Cloud Ready Images

Save your time.

More details available following.

pg1x-ubuntu-network/create-image.sh · main · CML 2.0 / pg1x-cml2-custom-images · GitLab

mkpasswd --method=SHA-512
cp -a /var/lib/libvirt/images/media/focal-server-cloudimg-amd64.img /var/lib/libvirt/images/instance.example.com.qcow2
qemu-img resize /var/lib/libvirt/images/instance.example.com.qcow2 20G
mkdir instance.example.com
cd instance.example.com
cloud-localds --network-config /var/lib/libvirt/images/ds/instance.example.com/network-config.yaml /var/lib/libvirt/images/ds/instance.example.com/user-data.img /var/lib/libvirt/images/ds/instance.example.com/user-data
sudo virt-install \
    --name instance.example.com \
    --ram 2048 \
    --disk path=/var/lib/libvirt/images/instance.example.com.qcow2 \
    --disk path=/var/lib/libvirt/images/ds/instance.example.com/user-data.img,device=cdrom \
    --vcpus 2 \
    --os-variant ubuntu18.04 \
    --network bridge=br-external \
    --network bridge=br-mgmt \
    --graphics none \
    --console pty,target_type=serial \
    --import

Network configuration is compatible with Netplan networking configuration.

network-config.yaml
version: 2
renderer: networkd
ethernets:
  ens2:
    dhcp4: no
    dhcp6: no
    addresses: [ 203.0.113.165/24 ]
    gateway4: 203.0.113.161
    nameservers:
      addresses: [ 10.0.11.253, 8.8.8.8, 8.8.4.4, 1.1.1.1 ]
  ens3:
    dhcp4: no
    dhcp6: no
    addresses: [ 10.0.9.165/22 ]
    routes:
      - to: 10.0.0.0/8
        via: 10.0.8.1
        metric: 0

References

tech/server/linux/virtualization/kvm-qemu/launch-virtual-machine-by-cloud-init-and-virt-install/launch-virtual-machine-by-cloud-init-and-virt-install.txt · Last modified: 2021/11/06 08:03 by wnoguchi