[FIX] script qemu: make Debian VMs usable (virtio seed + sudo group)

Debian VMs came up with no configured user, no hostname and no SSH key,
so neither the console (erplibre/erplibre) nor SSH worked. Two causes,
found via the guest cloud-init.log:

1. The NoCloud seed was attached as a CD-ROM. Debian's initramfs does
   not load the CD driver (sr_mod) at the init-local stage, so the
   "cidata" volume was invisible and cloud-init fell back to an empty
   DMI seed (Ubuntu tolerates the CD). Attach the seed as a read-only
   virtio disk instead: virtio-blk is in the initramfs, the label is
   seen immediately, and the user-data is applied. Works for Ubuntu too.
2. The user was added to group "admin", which does not exist on Debian
   (it does on Ubuntu) -> useradd failed and the user was never created.
   Use "sudo" (present on both) instead.

Validated end to end: Debian 12 and Ubuntu 24.04 both get the erplibre
user (in sudo), the hostname, console login erplibre/erplibre and SSH by
key.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Mathieu Benoit 2026-07-19 09:33:33 +00:00
parent 21810a31a1
commit dc9dfa5779

View file

@ -740,7 +740,10 @@ def build_cloud_config(
"users:",
f" - name: {args.user}",
" sudo: ALL=(ALL) NOPASSWD:ALL",
" groups: users, admin",
# « sudo » existe sur Debian ET Ubuntu ; « admin » n'existe PAS sur
# Debian -> useradd -G ...,admin échoue et l'utilisateur n'est jamais
# créé (login/clé SSH KO). C'était la cause du « Debian ne marche pas ».
" groups: users, sudo",
" shell: /bin/bash",
" lock_passwd: false" if pw_hash else " lock_passwd: true",
]
@ -945,8 +948,13 @@ def virt_install(
"--import",
"--disk",
f"path={disk},format=qcow2,bus=virtio",
# Seed cloud-init attaché comme DISQUE virtio en lecture seule (et non
# en CD-ROM) : le pilote virtio-blk est dans l'initramfs, donc le
# volume « cidata » est visible dès init-local et cloud-init le lit.
# En CD-ROM, l'initramfs Debian ne charge pas sr_mod à temps -> le
# seed n'est pas vu et rien ne s'applique (Ubuntu, lui, tolère le CD).
"--disk",
f"path={seed},device=cdrom",
f"path={seed},readonly=on,bus=virtio",
"--osinfo",
osinfo,
"--network",