构建 Win 2012 Server + Virtualbox 时,Packer 构建在 SSH 上挂起

构建 Win 2012 Server + Virtualbox 时,Packer 构建在 SSH 上挂起

我正在尝试使用 virtualbox+packer+vagrant 来自动配置虚拟机。

我已经设置了 json 模板来显示 VM UI(因此 headless=false),并使用我的 ISO 密钥和要首先安装的 OpenSSH 服务器选项配置了 autounattend.xml。

问题是虚拟机创建卡在“等待 SSH”日志条目上,我可以看到虚拟机正在运行并且提示输入 Windows 密钥,但没有其他事情发生。

任何帮助表示感谢

这是打包程序构建到此为止的输出,此时我已中止安装

PS C:\Users\xxxxxxx\Documents\DevVM> packer build .\windows_2012_r2.json 
virtualbox-iso output will be in this color.
==> virtualbox-iso: Downloading or copying Guest additions
    virtualbox-iso: Downloading or copying: file:///C:/Program%20Files/Oracle/VirtualBox/VBoxGuestAdditions.iso
==> virtualbox-iso: Downloading or copying ISO
    virtualbox-iso: Downloading or copying: file:///C:/Users/xxxxxxx/Documents/Work/VMs/ISOs/en_windows_server_2012_r2_x64_dvd_2707946.iso
==> virtualbox-iso: Creating floppy disk...
    virtualbox-iso: Copying: C:/Users/xxxxxxx/Documents/DevVM/Autounattend.xml
    virtualbox-iso: Copying: C:/Users/xxxxxxx/Documents/DevVM/GitHub/packer-windows/scripts/microsoft-updates.bat
    virtualbox-iso: Copying: C:/Users/xxxxxxx/Documents/DevVM/GitHub/packer-windows/scripts/win-updates.ps1
    virtualbox-iso: Copying: C:/Users/xxxxxxx/Documents/DevVM/GitHub/packer-windows/scripts/openssh.ps1
    virtualbox-iso: Copying: C:/Users/xxxxxxx/Documents/DevVM/GitHub/packer-windows/scripts/oracle-cert.cer
==> virtualbox-iso: Creating virtual machine...
==> virtualbox-iso: Creating hard drive...
==> virtualbox-iso: Attaching floppy disk...
==> virtualbox-iso: Creating forwarded port mapping for SSH (host port 4430)
==> virtualbox-iso: Executing custom VBoxManage commands...
    virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1443107958 --memory 2048
    virtualbox-iso: Executing: modifyvm packer-virtualbox-iso-1443107958 --cpus 2
==> virtualbox-iso: Starting the virtual machine...
==> virtualbox-iso: Waiting 2m0s for boot...
==> virtualbox-iso: Typing the boot command...
==> virtualbox-iso: Waiting for SSH to become available...
==> virtualbox-iso: Unregistering and deleting virtual machine...
==> virtualbox-iso: Deleting output directory...
Build 'virtualbox-iso' errored: Build was cancelled.
Cleanly cancelled builds after being interrupted.

这是带有 openssh 条目的 autounattend.xml 部分

 <FirstLogonCommands>
            <SynchronousCommand wcm:action="add">
                <CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\openssh.ps1 -AutoStart</CommandLine>
                <Description>Install OpenSSH</Description>
                <Order>1</Order>
                <RequiresUserInput>true</RequiresUserInput>
            </SynchronousCommand>                

我也尝试将上面的顺序改为最后一个命令(order=23),但没有效果。

这是 json 模板的一部分

      "type": "virtualbox-iso",
  "iso_url": "C:/Users/xxxxxx/Documents/Work/VMs/ISOs/en_windows_server_2012_r2_x64_dvd_2707946.iso",
  "iso_checksum_type": "md5",
  "iso_checksum": "0e7c09aab20dec3cd7eab236dab90e78",
  "headless": false,
  "boot_wait": "2m",
  "ssh_username": "vagrant",
  "ssh_password": "vagrant",
  "ssh_wait_timeout": "10m",
  "shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
  "guest_os_type": "Windows2012_64",
  "disk_size": 61440,
  "floppy_files": [
    "C:/Users/xxxxxx/Documents/DevVM/Autounattend.xml",
    "C:/Users/xxxxxx/Documents/DevVM/GitHub/packer-windows/scripts/microsoft-updates.bat",
    "C:/Users/xxxxxx/Documents/DevVM/GitHub/packer-windows/scripts/win-updates.ps1",
    "C:/Users/xxxxxx/Documents/DevVM/GitHub/packer-windows/scripts/openssh.ps1",
    "C:/Users/xxxxxx/Documents/DevVM/GitHub/packer-windows/scripts/oracle-cert.cer"
  ],

答案1

尝试增加ssh_wait_timeout10m2hjson template

这个问题似乎是因为系统没有足够的时间启动并准备好 SSH 配置。将此时间设置为更合理的时间应该可以解决问题。

相关内容