Libvirt conf - cdrom 启动问题

Libvirt conf - cdrom 启动问题

我在使用 libvirtd 时启动 debian 或 ubuntu netinstall 映像时遇到问题,我得到了菜单,但是在选择菜单选项安装时只得到了这个:

加载/install.amd/vmlinuz 失败:没有此文件或目录

我已经安装了 iso 并验证 debian netinstall iso 在 install.amd 目录中有 vmlinuz 文件等。

这是发生故障时我正在使用的域的 libvirtd xml:


<domain type='kvm'>
  <name>myserver</name>
  <uuid>d85a11d4-78d8-2425-527b-2adef6c952a9</uuid>
  <memory unit='KiB'>18192</memory>
  <currentMemory unit='KiB'>18192</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-5.2'>hvm</type>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <cpu mode='custom' match='exact' check='none'>
    <model fallback='forbid'>qemu64</model>
  </cpu>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
  <emulator>/usr/bin/qemu-system-x86_64</emulator>
  <disk type='file' device='cdrom'>
    <driver name='qemu' type='raw'/>
    <source file="/var/lib/libvirt/boot/debian-11.3.0-amd64-netinst.iso"/>
     <target dev='hda' bus='ide'/>
     <readonly/>
    <boot order='2'/>
  </disk>

  <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/opt/storage/VMs/myserver.qcow2'/>
      <target dev='vdb' bus='virtio'/>
      <boot order='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>
    <controller type='usb' index='0' model='piix3-uhci'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <controller type='scsi' index='0' model='lsilogic'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </controller>
    <interface type='network'>
      <mac address='52:54:00:4c:d1:73'/>
      <source network='net-simplebridge'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target type='isa-serial' port='0'>
        <model name='isa-serial'/>
      </target>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <input type='keyboard' bus='usb'>
      <address type='usb' bus='0' port='1'/>
    </input>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
      <listen type='address' address='127.0.0.1'/>
    </graphics>
    <video>
      <model type='vga' vram='8192' heads='1' primary='yes'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </memballoon>
    <rng model='virtio'>
      <backend model='random'>/dev/random</backend>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </rng>
  </devices>
</domain>

上面的 xml 最终会变成这样:

/usr/bin/qemu-system-x86_64 -name guest=myserver,debug-threads=on -S -object secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-1-myserver/master-key.aes -machine pc-i440fx-5.2,accel=kvm,usb=off,dump-guest-core=off,memory-backend=pc.ram -cpu qemu64 -m 18 -object memory-backend-ram,id=pc.ram,size=18874368 -overcommit mem-lock=off -smp 1,sockets=1,cores=1,threads=1 -uuid d85a11d4-78d8-2425-527b-2adef6c952a9 -no-user-config -nodefaults -chardev套接字,id = charmonitor,fd = 34,服务器,nowait -mon chardev = charmonitor,id = monitor,模式 = control -rtc base = utc -no-shutdown -boot strict = on -device piix3-usb-uhci,id = usb,总线 = pci.0,地址 = 0x1.0x2 -device lsi,id = scsi0,总线 = pci.0,地址 = 0x4 -blockdev {“driver”:“file”,“filename”:“/var/lib/libvirt/boot/debian-11.3.0-amd64-netinst.iso”,“node-name”:“libvirt-2-storage”,“auto-read-only”:true,“discard”:“unmap”} -blockdev {“node-name”:“libvirt-2-format”,“read-only”:true,“driver”:“raw”,“file”:“libvirt-2-storage”} -device ide-cd,总线=ide.0,单元=0,驱动器=libvirt-2-format,id=ide0-0-0,bootindex=2 -blockdev {“driver”:“file”,“filename”:“/opt/storage/VMs/myserver.qcow2”,“node-name”:“libvirt-1-storage”,“cache”:{“direct”:true,“no-flush”:false},“auto-read-only”:true,“discard”:“unmap”} -blockdev {“node-name”:“libvirt-1-format”,“read-only”:false,“cache”:{“direct”:true,“no-flush”:false},“driver”:“qcow2”,“file”:“libvirt-1-storage”,“backing”:null} -device virtio-blk-pci,总线=pci.0,addr=0x5,驱动器=libvirt-1-format,id=virtio-disk1,bootindex=1,write-cache=on -netdev tap,fd=36,id=hostnet0,vhost=on,vhostfd=37 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:4c:d1:73,总线=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -device usb-kbd,id=input0,总线=usb.0,端口=1 -vnc 127.0.0.1:0 -device VGA,id=video0,vgamem_mb=8,总线=pci.0,addr=0x2 -device virtio-ba

当手动执行此操作时,它可以在同一台机器上运行良好,并让我顺利进入安装过程:

qemu-system-x86_64 -vnc :0 -enable-kvm -serial stdio -curses -hda /opt/storage/VMs/myserver.qcow2 -m 2G -boot d -cdrom /var/lib/libvirt/boot/debian-11.3.0-amd64-netinst.iso

是否可以通过 libvirtd xml 配置获取“-cdrom”标志?或者还有其他建议?

答案1

<memory unit='KiB'>18192</memory>

这里您只为虚拟机分配了 18 MB 内存,而使用 QEMU 直接启动虚拟机时则有 2 GB 内存。我估计内存不足以加载 initrd。

<cpu mode='custom' match='exact' check='none'><model fallback='forbid'>qemu64</model></cpu>

与您的问题无关,但仍然值得更改,因为qemu64会导致糟糕的性能。 选择一个与您的主机操作系统相似的现代模型名称,或将其更改为使用mode='host-passthroughmode=host-model

相关内容