¿Cómo inicio la imagen de Debian 10 con qemu/kvm?

¿Cómo inicio la imagen de Debian 10 con qemu/kvm?

Estoy intentando iniciar la imagen de openstack de Debian 10 usando qemu y encuentro un error al detectar el disco duro; se muestra el final de la secuencia de inicio:

[    0.989085] Run /init as init process
Loading, please wait...
Starting version 241
[    1.068365] SCSI subsystem initialized
[    1.073933] cryptd: max_cpu_qlen set to 1000
[    1.085586] AVX2 version of gcm_enc/dec engaged.
[    1.085699] PCI Interrupt Link [LNKA] enabled at IRQ 10
[    1.086342] AES CTR mode by8 optimization enabled
[    1.094169] scsi host0: ata_piix
[    1.095524] scsi host1: ata_piix
[    1.096120] ata1: PATA max MWDMA2 cmd 0x1f0 ctl 0x3f6 bmdma 0xc2c0 irq 14
[    1.097198] ata2: PATA max MWDMA2 cmd 0x170 ctl 0x376 bmdma 0xc2c8 irq 15
[    1.108170] PCI Interrupt Link [LNKB] enabled at IRQ 11
[    1.120402] virtio_blk virtio0: [vda] 736 512-byte logical blocks (377 kB/368 KiB)
Begin: Loading essential drivers ... done.
Begin: Running /scripts/init-premount ... done.
Begin: Mounting root file system ... Begin: Running /scripts/local-top ... done.
Begin: Running /scripts/local-premount ... done.
Begin: Waiting for root file system ... Begin: Running /scripts/local-block ... done.
Begin: Running /scripts/local-block ... done.
Begin: Running /scripts/local-block ... done.
... line repeats ...
Begin: Running /scripts/local-block ... done.
Begin: Running /scripts/local-block ... done.
done.
Gave up waiting for root file system device.  Common problems:
 - Boot args (cat /proc/cmdline)
   - Check rootdelay= (did the system wait long enough?)
 - Missing modules (cat /proc/modules; ls /dev)
ALERT!  UUID=77e3f255-2ef2-47bc-ad89-7cdbd65f5fbc does not exist.  Dropping to a shell!


BusyBox v1.30.1 (Debian 1:1.30.1-4) built-in shell (ash)
Enter 'help' for a list of built-in commands.

Desde el indicador de initramfs, puedo ver lo siguiente:

(initramfs) cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-4.19.0-5-cloud-amd64 root=UUID=77e3f255-2ef2-47bc-ad89-7cdbd65f5fbc ro biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200 earlyprintk=ttyS0,115200 consoleblank=0 systemd.show_status=true

(initramfs) cat /proc/modules
ata_generic 16384 0 - Live 0xffffffffc00ba000
crc32c_intel 24576 0 - Live 0xffffffffc00b3000
virtio_blk 20480 0 - Live 0xffffffffc00ad000
aesni_intel 200704 0 - Live 0xffffffffc0156000
ata_piix 36864 0 - Live 0xffffffffc0147000
aes_x86_64 20480 1 aesni_intel, Live 0xffffffffc0135000
crypto_simd 16384 1 aesni_intel, Live 0xffffffffc0130000
libata 245760 2 ata_generic,ata_piix, Live 0xffffffffc00da000
cryptd 28672 2 aesni_intel,crypto_simd, Live 0xffffffffc00d2000
glue_helper 16384 1 aesni_intel, Live 0xffffffffc00cb000
scsi_mod 237568 1 libata, Live 0xffffffffc0072000
virtio_pci 28672 0 - Live 0xffffffffc0066000
virtio_ring 28672 2 virtio_blk,virtio_pci, Live 0xffffffffc005b000
virtio 16384 2 virtio_blk,virtio_pci, Live 0xffffffffc0053000

(initramfs) ls /dev
block               tty18               tty5
char                tty19               tty50
console             tty2                tty51
core                tty20               tty52
cpu_dma_latency     tty21               tty53
disk                tty22               tty54
fd                  tty23               tty55
full                tty24               tty56
hpet                tty25               tty57
input               tty26               tty58
kmsg                tty27               tty59
mem                 tty28               tty6
memory_bandwidth    tty29               tty60
network_latency     tty3                tty61
network_throughput  tty30               tty62
null                tty31               tty63
psaux               tty32               tty7
ptmx                tty33               tty8
pts                 tty34               tty9
random              tty35               ttyS0
snapshot            tty36               ttyS1
stderr              tty37               ttyS2
stdin               tty38               ttyS3
stdout              tty39               urandom
tty                 tty4                vcs
tty0                tty40               vcs1
tty1                tty41               vcsa
tty10               tty42               vcsa1
tty11               tty43               vcsu
tty12               tty44               vcsu1
tty13               tty45               vda
tty14               tty46               vga_arbiter
tty15               tty47               zero
tty16               tty48
tty17               tty49

(initramfs) ls /dev/disk/by-label/
cidata

(initramfs) ls -al /dev/disk/by-uuid/
total 0
drwxr-xr-x    2 0        0               60 Jul 22 00:07 .
drwxr-xr-x    5 0        0              100 Jul 22 00:07 ..
lrwxrwxrwx    1 0        0                9 Jul 22 00:07 2019-07-21-20-02-09-00 -> ../../vda

Para recrear esta VM, primero configuro la imagen qcow2 a partir de la imagen base descargada (descargada desdeel sitio de imágenes de openstack):

~/vm/deb10-test$ sha256sum ../base-debian-10/base.qcow2
d4c2966d996a3e08c198be41640d54b5d0c038cfc21b4d05e4b769824974daaf  ../base-debian-10/base.qcow2

~/vm/deb10-test$ qemu-img create -f qcow2 -o "backing_file=../base-debian-10/base.qcow2" image.qcow2 20G
Formatting 'image.qcow2', fmt=qcow2 size=21474836480 backing_file=../base-debian-10/base.qcow2 encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16

A continuación, configuro un seed.imgCloud-init usando cloud-localds:

~/vm/deb10-test$ cat meta-data
instance-id: iid-deb10-test-20190721-193118
hostname: deb10-test
local-hostname: deb10-test

~/vm/deb10-test$ cat network-config
---
version: 1
config:
- type: physical
  name: eth0
  subnets:
  - type: static
    address: 192.168.237.42
    netmask: 255.255.255.0
    routes:
    - network: 0.0.0.0
      netmask: 0.0.0.0
      gateway: 192.168.237.1
- type: nameserver
  address: [192.168.234.10, 192.168.234.254, 8.8.8.8]
  search: []

~/vm/deb10-test$ cat user-data
#cloud-config
users:
  - default
chpasswd:
  list: |
    debian:passw0rd
  expire: False
ssh_pwauth: True
package_update: true
packages:
- python
bootcmd:
# disable automatic dhcp
- sed -e '/^#/! {/eth0/ s/^/# /}' -i /etc/network/interfaces

~/vm/deb10-test$ cloud-localds -v ./seed.img --network-config network-config user-data meta-data
wrote ./seed.img with filesystem=iso9660 and diskformat=raw                                     

Y por último ejecuté virt-install con lo siguiente:

~/vm/deb10-test$ virt-install \
  --os-variant auto --virt-type kvm \
  --name deb10-test --graphics none --import \
  --disk path="./image.qcow2",format=qcow2,bus=scsi \
  --disk path="./seed.img",bus=virtio \
  --cpu host --vcpus 2 --memory 2048 \
  --network network=routed                                              

Un procedimiento similar funciona para imágenes de Debian 9 y el cambio bus=virtiofunciona para muchas otras imágenes de Linux (CentOS y Ubuntu). No sé por qué el dispositivo de disco duro no se muestra mientras el resto de initramfs parece estar funcionando. ¿Hay diferentes opciones que debo pasar para trabajar con Debian 10?


Editar: Intentar lo siguiente no resolvió el problema:

  • --machine q35: no hay diferencia visible; según la documentación, esto no parece ser necesario con KVM.
  • --disk path=./seed.img,device=cdrom,bus=sata: sin diferencia visible
  • --controller scsi,model=virtio-scsi: esto en realidad rompió aún más el arranque, simplemente se quedó colgado en una consola en blanco, sin grub, arranque del kernel ni indicador de initramfs. Usando model=autovolvió al indicador de initramfs.

Respuesta1

  1. Descarga estonetboot/initrd.gz

  2. Descarga estoarranque de red/vmlinuz

  3. Cree una imagen de disco vacía con:

    qemu-img crear -f qcow2 hda.qcow2 10G

  4. Ejecute debian-installeren QEMU con:

    sistema-qemu-??????? -M virt -m 1024 -kernel vmlinuz -initrd initrd.gz -drive if=none,file=hda.qcow2,format=qcow2,id=hd -device virtio-blk-device,drive=hd -netdev usuario,id= mynet -device virtio-net-device,netdev=mynet -nographic -no-reboot

Se debian-installerejecutará, le hará algunas preguntas básicas con algunos menús de texto, detectará dispositivos virtuales, hará su trabajo e instalará con éxito un sistema operativo Debian10 completamente funcional en la hda.qcow2imagen del disco. Ignora sus gritos sobre el gestor de arranque perdido...

  1. Ahora, para ejecutar esta imagen, debe copiar 2 archivos de la hda.qcow2imagen al sistema de archivos de su sistema operativo host (por ejemplo, a su directorio QEMU), a saber: vmlinuz-4.19.????????y initrd.img-4.19.?????...usandolibguestfsherramienta en Linux o guisantezipen Windows

  2. Finalmente ejecute la Máquina Virtual recién instalada con:

    sistema-qemu-??????? -M virt -m 1024 -kernel vmlinuz-4.19.??????? -initrd initrd.img-4.19.??????? -append root=/dev/vda2 -drive if=none,file=hda.qcow2,format=qcow2,id=hd -device virtio-blk-device,drive=hd -netdev user,id=mynet,restrict=off, net=192.168.0.0/24,hostfwd=tcp:127.0.0.1:10022-192.168.0.15:22 -device virtio-net-device,netdev=mynet -nographic -no-reboot

Asegúrese de cambiar ??????los nombres de archivo específicos en su sistema y cámbielos -append root=/dev/vda2a algún otro dispositivo si elige no formatear todo el disco virtual para la partición de Linux, durante la instalación de Debian.

  1. Finalmente, inicie la VM e inicie sesión desde la consola.

Para iniciar sesión en esta máquina virtual a roottravés de SSH en 127.0.0.1:10022, debe editar el /etc/ssh/sshd_configarchivo y agregar la línea: PermitRootLogin yes.

Quizás también quieras echar un vistazo aesta respuestamío si el servidor SSH se porta mal.

Respuesta2

Hay un par de cosas que cambiaría según tu virt-installcomando:

Primero, agregaría --machine q35en lugar de permitir el tipo de máquina predeterminado, que emula el hardware de una PC muy antigua (era de Windows 95). Tenga en cuenta que también necesita agregar un controlador virtio-scsi, con --controller scsi,model=virtio-scsi.

En segundo lugar, configuraría el tipo de disco de su imagen ISO en CDROM (y también debería conectarse a través de SATA). Entonces--disk path=./seed.img,device=cdrom,bus=sata

información relacionada