我正在尝试创建一个流程,通过该流程我可以使用 qemu 构建器在本地开发打包器配置,然后使用它来创建亚马逊 ebs 图像。我从 windows .iso 创建了一个 qcow2 映像,如下所示
qemu-img create -f qcow2 Windows-Server-2022-Core.qcow2 16G
qemu-system-x86_64 -m 4096 -M q35 -smp cores=2,threads=1,sockets=2 -enable-kvm -cpu host -cdrom isos/Windows-Server-2022-Core.iso -boot d -monitor stdio Windows-Server-2022-Core.qcow2
映像启动后,我为管理员设置密码,然后将其关闭。我可以从我的 qcow2 映像启动 qemu 虚拟机,如下所示
qemu-system-x86_64 -m 4096 -M q35 -smp cores=2,threads=1,sockets=2 -enable-kvm -cpu host -boot d -monitor stdio Windows-Server-2022-Core.qcow2
但是如果我尝试运行 Packer,它会启动一个 qemu 虚拟机,并且 Windows 会尝试启动,但随后会出现 inaccessible_boot_device 错误。下面是我的打包器源配置
source "qemu" "windows" {
accelerator = "kvm"
boot_command = []
disk_compression = true
disk_interface = "virtio"
boot_wait = "2s"
communicator = "winrm"
disk_size = "12G"
headless = false
disk_image = true
iso_checksum = "none"
iso_url = "/home/tormod/isos/Windows-Server-2022-Core.qcow2"
use_backing_file = true
qemuargs = [
["-m", "4096"],
["-M", "q35"],
["-smp", "cores=2"],
["-enable-kvm"],
["-cpu", "host"],
["-boot", "d"],
["-monitor", "stdio"],
]
shutdown_command = "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\""
vm_name = "windows2022"
winrm_password = "*********"
winrm_timeout = "10000s"
winrm_username = "Administrator"
}
我不确定我在创建 qcow2 映像时是否错过了某个步骤,或者我在打包器配置中犯了错误。我已经粘贴了打包程序的调试输出,以防有用
qemu.windows: output will be in this color.
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 Qemu path: /usr/bin/qemu-system-x86_64, Qemu Image path: /usr/bin/qemu-img
==> qemu.windows: Retrieving ISO
==> qemu.windows: Trying /home/tormod/isos/Windows-Server-2022-Core.qcow2
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 Acquiring lock for: /home/tormod/isos/Windows-Server-2022-Core.qcow2 (/home/tormod/.cache/packer/49322eb2ce27f20cfc8da41e0dc70e61493570cb.iso.lock)
==> qemu.windows: Trying /home/tormod/isos/Windows-Server-2022-Core.qcow2
==> qemu.windows: /home/tormod/isos/Windows-Server-2022-Core.qcow2 => /home/tormod/isos/Windows-Server-2022-Core.qcow2
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 Leaving retrieve loop for ISO
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 No floppy files specified. Floppy disk will not be made.
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 No CD files specified. CD disk will not be made.
==> qemu.windows: Creating required virtual machine disks
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 [INFO] Creating disk with Path: output-windows/windows2022 and Size: 12G
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 Executing qemu-img: []string{"create", "-f", "qcow2", "-b", "/home/tormod/isos/Windows-Server-2022-Core.qcow2", "-F", "qcow2", "output-windows/windows2022", "12G"}
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 stdout: Formatting 'output-windows/windows2022', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=12884901888 backing_file=/home/tormod/isos/Windows-Server-2022-Core.qcow2 backing_fmt=qcow2 lazy_refcounts=off refcount_bits=16
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 stderr:
==> qemu.windows: Resizing hard drive...
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 Executing qemu-img: []string{"resize", "-f", "qcow2", "output-windows/windows2022", "12G"}
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 stdout: Image resized.
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 stderr:
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 Looking for available communicator (SSH, WinRM, etc) port between 2222 and 4444
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 Found available port: 2509 on IP: 127.0.0.1
==> qemu.windows: Found port for communicator (SSH, WinRM, etc): 2509.
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 Looking for available port between 5900 and 6000 on 127.0.0.1
==> qemu.windows: Looking for available port between 5900 and 6000 on 127.0.0.1
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 Found available port: 5916 on IP: 127.0.0.1
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 Found available VNC port: 5916 on IP: 127.0.0.1
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 Qemu --version output: QEMU emulator version 7.2.6 (qemu-7.2.6-1.fc38)
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 Qemu version: 7.2.6
==> qemu.windows: Starting VM, booting disk image
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 Qemu Builder has no floppy files, not attaching a floppy.
==> qemu.windows: Overriding default Qemu arguments with qemuargs template option...
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 Executing /usr/bin/qemu-system-x86_64: []string{"-m", "4096", "-M", "q35", "-monitor", "stdio", "-vnc", "127.0.0.1:16", "-netdev", "user,id=user.0,hostfwd=tcp::2509-:5985", "-smp", "cores=2", "-enable-kvm", "-name", "windows2022", "-device", "virtio-net,netdev=user.0", "-boot", "d", "-machine", "type=pc,accel=kvm", "-drive", "file=output-windows/windows2022,if=virtio,cache=writeback,discard=ignore,format=qcow2", "-cpu", "host", "-display", "gtk"}
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 Started Qemu. Pid: 30481
2023/12/15 17:12:48 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:48 Qemu stdout: QEMU 7.2.6 monitor - type 'help' for more information
==> qemu.windows: Waiting 2s for boot...
==> qemu.windows: Connecting to VM via VNC (127.0.0.1:5916)
2023/12/15 17:12:52 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:52 Connected to VNC desktop: QEMU (windows2022)
==> qemu.windows: Typing the boot commands over VNC...
qemu.windows: Not using a NetBridge -- skipping StepWaitGuestAddress
==> qemu.windows: Using WinRM communicator to connect: 127.0.0.1
2023/12/15 17:12:52 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:52 Waiting for WinRM, up to timeout: 2h46m40s
==> qemu.windows: Waiting for WinRM to become available...
2023/12/15 17:12:52 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:52 [INFO] Attempting WinRM connection...
2023/12/15 17:12:52 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:12:52 [DEBUG] connecting to remote shell using WinRM
2023/12/15 17:14:07 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:14:07 [ERROR] connection error: unknown error Post "http://127.0.0.1:2509/wsman": read tcp 127.0.0.1:36912->127.0.0.1:2509: read: connection reset by peer
2023/12/15 17:14:07 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:14:07 [ERROR] WinRM connection err: unknown error Post "http://127.0.0.1:2509/wsman": read tcp 127.0.0.1:36912->127.0.0.1:2509: read: connection reset by peer
2023/12/15 17:14:12 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:14:12 [INFO] Attempting WinRM connection...
2023/12/15 17:14:12 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2023/12/15 17:14:12 [DEBUG] connecting to remote shell using WinRM
我对 qemu 或 windows 不太了解,所以我将不胜感激任何帮助或建议
我发现问题出在磁盘类型上。我只是更新我的打包源如下
disk_interface = "ide"