hashicorp/nomad · error

cannot create copy - %s

Error message

cannot create copy - %s

What it means

binaryInstall wraps the error from os.CreateTemp, which creates the temporary copy of the nomad binary used for the Windows service installation. It indicates the temp file could not be created, typically due to filesystem or permission problems in the system temp directory. The wrapped OS error carries the concrete cause.

Source

Thrown at command/windows_service_install.go:345

	opts.binaryPath = filepath.Join(opts.installDir, "nomad.exe")

	// Ensure the install directory exists
	if err = c.winPaths.CreateDirectory(opts.installDir, false); err != nil {
		return fmt.Errorf("could not create binary install directory - %s", err)
	}

	// Create a new copy of the current binary to install
	exeFile, err := os.Open(exePath)
	if err != nil {
		return fmt.Errorf("cannot open current nomad path for install - %s", err)
	}
	defer exeFile.Close()

	// Copy into a temporary file which can then be moved
	// into the correct location.
	dstFile, err := os.CreateTemp(os.TempDir(), "nomad*")
	if err != nil {
		return fmt.Errorf("cannot create copy - %s", err)
	}
	defer dstFile.Close()

	if _, err = io.Copy(dstFile, exeFile); err != nil {
		return fmt.Errorf("cannot write nomad binary for install - %s", err)
	}
	dstFile.Close()

	// With a copy ready to be moved into place, ensure that
	// the path is clear then move the file.
	if err = os.RemoveAll(opts.binaryPath); err != nil {
		return fmt.Errorf("cannot remove existing nomad binary install - %s", err)
	}

	if err = os.Rename(dstFile.Name(), opts.binaryPath); err != nil {
		return fmt.Errorf("cannot install new nomad binary - %s", err)
	}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Check the OS error wrapped in the message for the concrete cause (permission denied, no space left, etc.)
  2. Verify TMP/TEMP point to an existing writable directory, or run as an account with write access to it
  3. Free disk space on the drive holding the temp directory
  4. Exclude the installer from antivirus/EDR that blocks temp file creation

Example fix

// before (reading TMP from a stale env var)
set TMP=C:\nonexistent
// after
set TMP=C:\Windows\Temp
Defensive patterns

Strategy: validation

Validate before calling

if fi, err := os.Stat(os.TempDir()); err != nil || fi.Mode()&0200 == 0 {
    return fmt.Errorf("temp dir %s not writable: %v", os.TempDir(), err)
}

Try / catch

if err := cmd.Run(); err != nil {
    if strings.Contains(err.Error(), "cannot create copy") {
        // check TMP writability / disk space before retrying
    }
}

Prevention

When it happens

Trigger: os.TempDir() is unwritable, the disk holding the temp dir is full, antivirus/permissions block temp file creation, or TMP/TEMP env vars point to a nonexistent path while performInstall installs the Windows service.

Common situations: Running the installer under a service account with no write access to %TEMP%; full system drive; restricted environments where the temp dir is mounted noexec or read-only.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/fc1e9166a86b3b4a. Report an issue: GitHub.