admin管理员组

文章数量:1391787

I am attempting to create a build pipeline which restores a Ghost img (.gho) onto a virtual disk to generate a VM using packer with the vmware-iso plugin. I can start with a custom provisioned windows-pe instance with Ghost64.exe to make the restore.

I need either an ssh or winrm connection so that I can scp the ghost files into the VM among other more fine-grained provisioning. However I can't manage to get ssh to connect through packer or otherwise.

This is my current attempt:

  1. Create custom Windows PE ISO file, via DISM.exe and Window ADK

    -> Drop OpenSSH 9.5 in X:\Program Files\

    -> Drop Ghost64.exe in X:\Windows\Ghost\

  2. Generate my.iso from the previous files

  3. Use packer with vmware-iso plugin -> point to the freshly generated iso -> run boot commands to setup SSH

  4. Run sshd.exe For packer to establish connection and start ghost restore.

No matter what I change, I receive the same error every time. Meanwhile packer is hanging on Waiting for SSH to become available....

It appears to break on the key exchange. I verified that the versions were the same, and their version strings match. That there is at least one shared key exchange algorithm.

I also attempted a login via ssh.exe manually and receive this response:

PS> ssh [email protected]
Connection reset by 192.168.19.128 port 22 

Here is my packer build file:

# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

packer {
  required_plugins {
    vmware = {
      version = ">=1.1.0"
      source  = "github/hashicorp/vmware"
    }
  }
}

source "vmware-iso" "vm-example" {
  vm_name = "my-vm"
  guest_os_type = "windows9-64"

  cpus   = 2
  memory = 8192
  disk_size = 60000
  disk_adapter_type = "nvme"
  #cdrom_adapter_type = "scsi"
  shutdown_command = "shutdown -P now"

  usb = true

  iso_checksum = "<sha to iso>"
  iso_url      = "C:\\Users\\<my user>\\projects\\gho_to_vm\\winpe_test.iso"

  network      = "nat"

  boot_command = [
    "<wait15s>Wpeutil DisableFirewall<enter>",
    "Wpeutil InitializeNetwork<enter>",
    "powershell.exe<enter>", 
    "cd 'X:\\Program Files\\OpenSSH'<enter>",
    "md X:\\ProgramData\\ssh<enter>",
    "Set-ExecutionPolicy Unrestricted <enter>",
    "net user /add Me pass<enter>",
    "net localgroup Users Me /add <enter>",
    "net localgroup 'OpenSSH Users' Me /add <enter>",
    "net localgroup Administrators Me /add <enter>",
    "net user /add sshd pass <enter>",
    "net localgroup Users sshd /add <enter>",
    "net localgroup 'OpenSSH Users' sshd /add <enter>",
    "net localgroup Administrators sshd /add <enter>",
    ".\\install-sshd.ps1<enter>", # This has some errors, but only on Service related tasks. Just running sshd.exe manually so doesn't matter.
    ".\\ssh-keygen -A<enter>",
    ".\\sshd.exe -d -f .\\sshd_config_default<enter>",
  ]
  #cd_files = ["C:\\Users\\<my user>\\projects\\gho_to_vm\\GhostFiles"]
  #cd_label = "ghostdata"

  communicator = "ssh"

  ssh_username  = "Me"
  ssh_password = "pass"

  ssh_handshake_attempts = 10

  vmx_data = {
    "usb_xhci.present" = true
  }
}

build {
  sources = [
    "source.vmware-iso.vm-example"
  ]

  provisioner "powershell" {
    inline = ["dir \\", "echo 'hello world'"]
  }
}

What would be your ways to connect to the VM through packer? Is SSH on windows pe even possible? Should I use a different windows iso for building out my image?

本文标签: sshOpenSSH on VMWare WindowsPE instance through PackerStack Overflow