hashicorp/packer · error
failed to run OS detection command: %s
Error message
failed to run OS detection command: %s
What it means
detectRemoteOS error when comm.Start(ctx, cmd) fails to launch the OS detection command ('uname -s -m' over SSH, 'echo %PROCESSOR_ARCHITECTURE%' over WinRM) on the remote machine. This indicates the communicator could not start the command at all (connection/protocol-level failure), as distinct from the command running and exiting non-zero.
Source
Thrown at provisioner/hcp-sbom/provisioner.go:384
}
// Run detection command based on communicator
var cmd *packersdk.RemoteCmd
if connType == "winrm" {
cmd = &packersdk.RemoteCmd{
Command: "echo %PROCESSOR_ARCHITECTURE%",
}
} else {
cmd = &packersdk.RemoteCmd{
Command: "uname -s -m",
}
}
var stdout bytes.Buffer
cmd.Stdout = &stdout
if err := comm.Start(ctx, cmd); err != nil {
return "", "", fmt.Errorf("failed to run OS detection command: %s", err)
}
cmd.Wait()
if cmd.ExitStatus() != 0 {
return "", "", fmt.Errorf("OS detection command exited with status %d", cmd.ExitStatus())
}
output := strings.TrimSpace(stdout.String())
log.Printf("OS detection output: %s", output)
// Parse output
var osType, osArch string
if connType == "winrm" {
osType = "Windows"
osArch = strings.ToLower(output) // AMD64, ARM64, etc.
} else {
parts := strings.Fields(output)View on GitHub (pinned to eb36e3c3e4)
Solutions
- Check communicator logs immediately before this error for the underlying SSH/WinRM cause.
- Verify SSH/WinRM connectivity (ssh into the guest or test WinRM) with the same credentials the builder uses.
- Increase communicator timeouts / add retry settings if the connection is flaky.
- Note the build itself continues: Provision logs 'Failed to detect remote OS' and skips SBOM generation, so this is non-fatal to the image build.
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check communicator reachability before the provisioner runs
client, err := ssh.Dial("tcp", fmt.Sprintf("%s:%d", host, port), sshConfig)
if err != nil {
return fmt.Errorf("guest not reachable over SSH before OS detection: %w", err)
}
session, err := client.NewSession()
if err != nil {
return fmt.Errorf("cannot open SSH session (command start would fail): %w", err)
}
session.Close() Try / catch
if err := provisioner.Provision(ctx, ui, comm, data); err != nil {
if strings.Contains(err.Error(), "failed to run OS detection command") {
// non-fatal for the build: log, check SSH/WinRM config, optionally retry
ui.Error("OS detection failed; skipping SBOM generation")
return nil
}
return err
} Prevention
- Validate SSH/WinRM credentials, port, and host key settings in the builder config
- Increase communicator timeouts on slow-booting guests
- Verify the guest shell exists and is permitted for the login user
- Remember Provision treats this as non-fatal (build continues without SBOM) — fix connectivity to restore SBOM generation
When it happens
Trigger: comm.Start returns an error in detectRemoteOS, reached from Provision when generatedData lacks usable OSType/OSArch — e.g. SSH session cannot allocate/start the remote command, WinRM command dispatch fails, or the connection dropped.
Common situations: SSH connection dropped or not fully established when the provisioner runs; WinRM endpoint misconfigured (port/auth/HTTPS); guest shell unavailable or restricted; firewall/timeout killing the session mid-build.
Related errors
- OS detection command exited with status %d
- failed to start scanner: %s
- Error uploading script: %s
- Error chmodding script file to 0755 in remote machine: %s
- Error removing temporary script at %s: %s
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/c95474d4fb27e0ce.
Report an issue: GitHub.