← retour aux snippets

virt-install: VM Debian avec cloud-init NoCloud

Créer une VM KVM en important une image cloud et en injectant cloud-init nocloud.

objectif

Démarrer rapidement une VM prête avec user/password et clé SSH.

code minimal

# cloud image
IMG=debian-12-genericcloud-amd64.qcow2
qemu-img resize $IMG +10G

# seed nocloud
mkdir -p seed && cat > seed/user-data <<'YAML'
#cloud-config
users:
  - name: admin
    sudo: ALL=(ALL) NOPASSWD:ALL
    ssh_authorized_keys:
      - ssh-ed25519 AAAA...
chpasswd: { list: | admin:changeme, expire: False }
YAML
echo 'instance-id: iid-local01
local-hostname: debian-guest' > seed/meta-data
cloud-localds seed.iso seed/user-data seed/meta-data

# virt-install
virt-install --name debian-guest --memory 2048 --vcpus 2 --disk path=$IMG,format=qcow2 --disk path=seed.iso,device=cdrom --import --os-variant debian12 --network network=default --graphics none

utilisation

# se connecter
virsh console debian-guest

variante(s) utile(s)

# IP bridge
virt-install ... --network bridge=br0

notes

  • nécessite libvirt & cloud-localds.
  • retirez le seed ISO après premier boot si souhaité.