设置
主持人
操作系统
Manjaro XFCE x86_64
应用
打包器(插件:qemu)
virt-install
virt-viewer
virt-manager
客人
OS: Arch Linux
Hypervisor: QEMU KVM
Architecture: x64
Machine Type: qc35
EFI Firmware Code: /usr/share/edk2-ovmf/x64/OVMF_CODE.fd
EFI Firmware Vars: /usr/share/edk2-ovmf/x64/OVMF_VARS.fd
packer build
因此,我使用并记录我的启动选项创建了一个自定义的 Arch Linux 映像。
echo ">>>> ${NAME_SH}: 显示启动选项.." 的输出
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)
所以我认为这应该没问题,但是当我运行这个时:
virt安装命令
sudo virt-install \
--name bastille-installer \
--vcpu 2 \
--memory 1024 \
--osinfo archlinux \
--disk /var/lib/libvirt/images/bastille-installer_qemu_archlinux-2023-04.qcow2 \
--import \
--boot uefi
我看到这个:
映射表中的FS0:完全丢失。退出查看启动管理器后,我发现也缺少几个启动选项。
这些是我的打包器配置加载的脚本:
巴士底狱安装程序.pkr.hcl
...
provisioner "shell" {
only = ["qemu.archlinux"]
execute_command = "{{ .Vars }} sudo -E -S bash '{{ .Path }}'"
expect_disconnect = true
scripts = [
"scripts/configure-qemu.sh",
"scripts/configure-shared.sh",
"scripts/partition-table-gpt.sh",
"scripts/partition-ext4-efi.sh",
"scripts/setup.sh"
]
}
...
这是创建引导加载程序的脚本。
分区-ext4-efi.sh
#!/usr/bin/env bash
. /tmp/files/vars.sh
NAME_SH=partition-ext4-efi.sh
# stop on errors
set -eu
echo ">>>> ${NAME_SH}: Writing Filesystem types.."
mkfs.ext4 -L BOHKS_BAZ ${ROOT_PARTITION}
mkfs.fat -F32 ${BOOT_PARTITION}
echo ">>>> ${NAME_SH}: Mounting partitions.."
/usr/bin/mount ${ROOT_PARTITION} ${ROOT_DIR}
/usr/bin/mkdir -p ${BOOT_DIR}
/usr/bin/mount ${BOOT_PARTITION} ${BOOT_DIR}
echo ">>>> ${NAME_SH}: Bootstrapping the base installation.."
/usr/bin/pacstrap ${ROOT_DIR} base `pacman -Qq linux`
echo ">>>> ${NAME_SH}: Updating pacman mirrors base installation.."
/usr/bin/arch-chroot ${ROOT_DIR} pacman -S --noconfirm reflector
/usr/bin/arch-chroot ${ROOT_DIR} reflector --latest 5 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
tee /etc/xdg/reflector/reflector.conf &>/dev/null <<EOF
--latest 5
--protocol https
--sort rate
--save /etc/pacman.d/mirrorlist
EOF
/usr/bin/arch-chroot ${ROOT_DIR} systemctl enable reflector.timer
echo ">>>> ${NAME_SH}: Installing databases.."
/usr/bin/arch-chroot ${ROOT_DIR} pacman -Sy
echo ">>>> ${NAME_SH}: Installing basic packages.."
/usr/bin/arch-chroot ${ROOT_DIR} pacman -S --noconfirm sudo gptfdisk openssh grub efibootmgr dhcpcd netctl
echo ">>>> ${NAME_SH}: Generating the filesystem table.."
/usr/bin/genfstab -U ${ROOT_DIR} | tee -a "${ROOT_DIR}/etc/fstab" >/dev/null
echo ">>>> ${NAME_SH}: Installing grub.."
/usr/bin/arch-chroot ${ROOT_DIR} grub-install --target=x86_64-efi --efi-directory=${ESP_DIR} --bootloader-id=GRUB >/dev/null
/usr/bin/arch-chroot ${ROOT_DIR} grub-mkconfig -o /boot/grub/grub.cfg
echo ">>>> ${NAME_SH}: Show boot option.."
/usr/bin/arch-chroot ${ROOT_DIR} efibootmgr
echo ">>>> ${NAME_SH}: Generating the system configuration script.."
/usr/bin/install --mode=0755 /dev/null "${ROOT_DIR}${CONFIG_SCRIPT}"
如果相关的话,这就是我创建分区表的方式。
分区表-gpt.sh
#!/usr/bin/env bash
. /tmp/files/vars.sh
# stop on errors
set -eu
NAME_SH=partition-table-gpt.sh
echo ">>>> ${NAME_SH}: Formatting disk.."
sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | gdisk ${DISK}
o
y
n
1
+250M
ef02
n
2
8304
p
w
y
q
EOF
相关变量文件:
vars.sh
...
HOME_DIR=/home/${USER}
SSH_DIR=/home/${USER}/.ssh
ROOT_DIR='/mnt'
BOOT_DIR='/mnt/boot/efi'
FILES_DIR='/tmp/files'
ESP_DIR='/boot/efi'
...
BOOT_PARTITION="${DISK}1"
ROOT_PARTITION="${DISK}2"
...
我不知道为什么我没有获得 UEFI 启动选项
以及为什么映射表中缺少文件系统。
答案1
virt-install
创建一个全新的 VM,该 VM 不知道现有 VM 的 UEFI 配置。
问题似乎是--boot uefi
。你需要
--boot loader=/.../OVMF_CODE.fd,loader.readonly=yes,loader.type=pflash,nvram.template=/.../OVMF_VARS.fd,loader_secure=no
相反(指向其他虚拟机文件的副本)以获得 UEFI 配置。