VM 启动至 UEFI Interactive Shell,但文件系统丢失。 (自定义 virt-install 启动参数)

VM 启动至 UEFI Interactive Shell,但文件系统丢失。 (自定义 virt-install 启动参数)

我的设置

主持人

OS: Manjaro XFCE x86_64 
Apps: packer (plugins: qemu), 
      virt-manager, virt-install 
      virt-viewer 

客人

OS:                Arch Linux  
Hypervisor:        QEMU KVM  
Architecture:      x64
Machine Type:      q35
EFI Firmware Code: /usr/share/edk2/x64/OVMF_CODE.4m.fd
EFI Firmware Vars: /usr/share/edk2/x64/OVMF_VARS.4m.fd

packer build我使用并记录了我的启动选项在我的主机上创建了一个自定义的 Arch Linux 映像。

...
"==> bootloader.sh: Show boot options.."

BootCurrent: 0001
    Timeout: 0 seconds
    BootOrder: 0007,0000,0001,0002,0003,0004,0005,0006
    Boot0000* UiApp    FvVol(7cb8bdc9-f8eb-4f34-aaea-3ee4af6516a1)/FvFile(462caa21-7614-4503-836e-8ab6f4662331)
    Boot0001* UEFI QEMU DVD-ROM QM00001     PciRoot(0x0)/Pci(0x1f,0x2)/Sata(0,65535,0){auto_created_boot_option}
    Boot0002* UEFI QEMU DVD-ROM QM00005     PciRoot(0x0)/Pci(0x1f,0x2)/Sata(2,65535,0){auto_created_boot_option}
    Boot0003* UEFI Misc Device    PciRoot(0x0)/Pci(0x3,0x0){auto_created_boot_option}
    Boot0004* UEFI PXEv4 (MAC:525400123456)    PciRoot(0x0)/Pci(0x2,0x0)/MAC(525400123456,1)/IPv4(0.0.0.00.0.0.0,0,0){auto_created_boot_option}
    Boot0005* UEFI PXEv6 (MAC:525400123456)    PciRoot(0x0)/Pci(0x2,0x0)/MAC(525400123456,1)/IPv6([::]:<->[::]:,0,0){auto_created_boot_option}
    Boot0006* EFI Internal Shell    FvVol(7cb8bdc9-f8eb-4f34-aaea-3ee4af6516a1)/FvFile(7c04a583-9e3e-4f1c-ad65-e05268d0b4d1)
    Boot0007* GRUB    HD(1,GPT,2034b5d2-828a-4491-8d23-fe9439932a12,0x800,0x7d000)/File(\EFI\GRUB\grubx64.efi)
...

所以我认为这应该没问题,但是当我运行这个时:

sudo virt-install \
--name bastille-installer \
--vcpu 2 \
--machine q35 \
--memory 1024 \
--osinfo archlinux \
--debug \
--disk /var/lib/libvirt/images/bastille-installer_qemu_archlinux-2023-05.qcow2,format=qcow2 \
--import \
--boot loader=/usr/share/edk2/x64/OVMF_CODE.4m.fd,loader_ro=yes,loader_type=pflash,nvram_template=/usr/share/edk2/x64/OVMF_VARS.4m.fd,loader_secure=no

在此输入图像描述

映射表中的FS0:完全丢失。退出查看启动管理器后,我发现也缺少几个启动选项。

在此输入图像描述

如果相关的话,virt-install 的详细输出如下所示:

https://gist.github.com/Folaht/d8d4366b79434069ff6e8a7b51abbd25

我究竟做错了什么?

[编辑]

$ sudo qemu-img info ./bastille-installer_qemu_archlinux-2023-05.qcow2
image: ./bastille-installer_qemu_archlinux-2023-05.qcow2
file format: raw
virtual size: 1.42 GiB (1522309120 bytes)
disk size: 1.42 GiB
Child node '/file':
    filename: ./bastille-installer_qemu_archlinux-2023-05.qcow2
    protocol type: file
    file length: 1.42 GiB (1522309120 bytes)
    disk size: 1.42 GiB

看起来我有一个原始文件问题。
一定有什么原因导致加壳器忽略将盒子构建为 qcow2 文件,尽管如此配置。

巴士底盒-安装程序-box.pkr.hcl

...
source "qemu" "archlinux" {
  accelerator             = "kvm"
  boot_command            = local.boot_command_qemu
  boot_wait               = "1s"
  cpus                    = local.cpus
  disk_interface          = "virtio"
  disk_size               = local.disk_size
  efi_boot                = true
  efi_firmware_code       = local.efi_firmware_code
  efi_firmware_vars       = local.efi_firmware_vars
  format                  = "qcow2"
  headless                = local.headless
  http_directory          = local.http_directory
  iso_url                 = local.iso_url
  iso_checksum            = local.iso_checksum
  machine_type            = local.machine_type
  memory                  = local.memory
  net_device              = "virtio-net" 
  shutdown_command        = "sudo systemctl start poweroff.timer"
  ssh_handshake_attempts  = 500
  ssh_port                = 22
  ssh_private_key_file    = var.ssh_private_key_file
  ssh_timeout             = var.ssh_timeout
  ssh_username            = var.ssh_username
  ssh_wait_timeout        = var.ssh_timeout
  vm_name                 = "${local.vm_name}.qcow2"
}
...  

答案1

您的磁盘配置错误。您正在使用 qcow2 磁盘映像,但您没有告诉virt-install这一点,因此您的虚拟机配置如下所示:

    <disk type="file" device="disk">
      <driver name="qemu" type="raw"/>
      <source file="/var/lib/libvirt/images/bastille-installer_qemu_archlinux-2023-05.qcow2"/>
      <target dev="vda" bus="virtio"/>
    </disk>

它尝试将磁盘映像作为raw映像进行访问,因此找不到预期的数据。确保您设置的格式正确:

virt-install \
  --disk /var/lib/libvirt/images/bastille-installer_qemu_archlinux-2023-04.qcow2,format=qcow2 \
  ...

相关内容