hashicorp / packer-plugin-qemu

Packer plugin for QEMU Builder
https://www.packer.io/docs/builders/qemu
Mozilla Public License 2.0
64 stars 44 forks source link

QEMU packer build is unable to start the windows OS ISO #168

Open SDP1423 opened 8 months ago

SDP1423 commented 8 months ago

Overview of the Issue

When trying to run the qemu packer build to build windows 2022 image, it is not recognizing the iso and it is struck at the BIOS only.

Plugin and Packer version

Packer v1.10.1

Simplified Packer Buildfile

source "qemu" "windows_server_2022" {  
  iso_url          =  "/home/buildaccount/sai/win2k22/capi/Lowes_win2022.iso"
  iso_checksum     = "none"
  output_directory = "/home/buildaccount/sai/win2k22/capi/image" # location in the local where the image is build. 
  shutdown_command = "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\""  
  qemuargs = [
        [ "-m", "4096M" ],
        ["-smp", "2"],
        ["-display", "none"],
       # ["firmware", "../edk2/ovmf:w:/OVMF.fd"]
      ]
  disk_size        = "81920M"
  format           = "qcow2"         
  accelerator      = "kvm"
  communicator     = "winrm"          
  winrm_insecure   = "true"          
  winrm_username   = "****" 
  winrm_password   = "****" #Please give the default password in the quotes   
  vm_name          = "sai-test" #change to any name
  net_device       = "virtio-net"    
  disk_interface   = "virtio"
  headless         = "false"
  floppy_files     = ["/home/buildaccount/sai/win2k22/capi/answer_files/2022/autounattend.xml",
                      "/home/buildaccount/sai/win2k22/capi/scripts/boxstarter.ps1",
                      "/home/buildaccount/sai/win2k22/capi/scripts/package.ps1", 
                      "/home/buildaccount/sai/win2k22/capi/scripts/Test-Command.ps1"]
  cd_label         = "iso-boot"
  boot_wait        = "5s"
  boot_command     = ["<enter>"]
  display          = "vnc"  
  vnc_bind_address = "0.0.0.0"
  vnc_port_min = "5902"
  vnc_port_max = "5903"
}
build { 
    sources = ["source.qemu.windows_server_2022"]
    provisioner "powershell" {
      elevated_user     = "****"
      elevated_password = "****"#Please give the default password in the quotes 
      script            = "/home/buildaccount/sai/win2k22/capi/scripts/SetUserPSNeverExpire.ps1"
  }
    provisioner "powershell" {
      elevated_user     = "****"
      elevated_password = "****"#Please give the default password in the quotes 
      script            = "/home/buildaccount/sai/win2k22/capi/scripts/provision.ps1"
  }
    provisioner "powershell" {
      inline = ["bcdedit /timeout 30"]
  }
    provisioner "file" {
      source = "/home/buildaccount/sai/win2k22/capi"
      destination = "C:/win2k22"
    }
}

Operating system and Environment details

I am running this packer build in rocky 8 OS system

Log Fragments and crash.log files

==> qemu.windows_server_2022: Starting VM, booting from CD-ROM
==> qemu.windows_server_2022: Overriding default Qemu arguments with qemuargs template option...
2024/03/19 13:37:10 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2024/03/19 13:37:10 Executing /usr/libexec/qemu-system-x86_64: []string{"-vnc", "0.0.0.0:2", "-boot", "once=d", "-smp", "2", "-machine", "type=pc,accel=kvm", "-drive", "file=/home/buildaccount/sai/win2k22/capi/image/sai-test,if=ide,cache=writeback,discard=ignore,format=qcow2", "-drive", "file=/home/buildaccount/sai/win2k22/capi/Lowes_win2022.iso,media=cdrom", "-name", "sai-test", "-netdev", "user,id=user.0,hostfwd=tcp::4425-:5985", "-fda", "/tmp/packer3627102676", "-device", "virtio-net,netdev=user.0", "-m", "4096M", "-display", "none"}
2024/03/19 13:37:10 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2024/03/19 13:37:10 Started Qemu. Pid: 95136
2024/03/19 13:37:10 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2024/03/19 13:37:10 Qemu stderr: WARNING: Image format was not specified for '/tmp/packer3627102676' and probing guessed raw.
2024/03/19 13:37:10 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2024/03/19 13:37:10 Qemu stderr:          Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
2024/03/19 13:37:10 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2024/03/19 13:37:10 Qemu stderr:          Specify the 'raw' format explicitly to remove the restrictions.
==> qemu.windows_server_2022: Waiting 5s for boot...
==> qemu.windows_server_2022: Connecting to VM via VNC (0.0.0.0:5902)
2024/03/19 13:37:17 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2024/03/19 13:37:17 Connected to VNC desktop: QEMU (sai-test)
==> qemu.windows_server_2022: Typing the boot commands over VNC...
2024/03/19 13:37:17 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2024/03/19 13:37:17 Special code '<enter>' found, replacing with: 0xFF0D
    qemu.windows_server_2022: Not using a NetBridge -- skipping StepWaitGuestAddress
==> qemu.windows_server_2022: Using WinRM communicator to connect: 127.0.0.1
2024/03/19 13:37:17 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2024/03/19 13:37:17 Waiting for WinRM, up to timeout: 30m0s
==> qemu.windows_server_2022: Waiting for WinRM to become available...
2024/03/19 13:37:17 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2024/03/19 13:37:17 [INFO] Attempting WinRM connection...
2024/03/19 13:37:17 packer-plugin-qemu_v1.0.10_x5.0_linux_amd64 plugin: 2024/03/19 13:37:17 [DEBUG] connecting to remote shell using WinRM

When i access the console of the vm being created for image, i see the following error

Booting from Hard Disk . . .
Boot failed: not a bootable disk

Booting from Floppy . . .
lbajolet-hashicorp commented 7 months ago

Hi @SDP1423,

From the logs and the template it's hard to say if that's a plugin/Packer bug at this point. When you say the "VM created for image" do you mean the build VM? The hard drive won't be bootable at this point since it's an empty disk, but the iso should however be, it seems your BIOS/EFI firmware might be unable to boot from that source for some reason. Have you tried running the build with headless=false so you can troubleshoot the boot process?