hashicorp/nomad · error

cannot create data directory - %s

Error message

cannot create data directory - %s

What it means

configInstall creates both config and data directories; this error wraps failure of winPaths.CreateDirectory(opts.dataDir, true) for the data directory. Nomad cannot provision its state directory, so installation aborts before writing the default config.

Source

Thrown at command/windows_service_install.go:270

	if opts.dataDir == "" {
		opts.dataDir = filepath.Join(winsvc.WINDOWS_INSTALL_APPDATA_DIRECTORY, "data")
	}

	var err error
	if opts.configDir, err = c.winPaths.Expand(opts.configDir); err != nil {
		return fmt.Errorf("cannot generate configuration path - %s", err)
	}
	if opts.dataDir, err = c.winPaths.Expand(opts.dataDir); err != nil {
		return fmt.Errorf("cannot generate data path - %s", err)
	}

	// Ensure directories exist
	if err = c.winPaths.CreateDirectory(opts.configDir, true); err != nil {
		return fmt.Errorf("cannot create configuration directory - %s", err)
	}

	if err = c.winPaths.CreateDirectory(opts.dataDir, true); err != nil {
		return fmt.Errorf("cannot create data directory - %s", err)
	}

	// Check if any configuration files exist
	matches, _ := filepath.Glob(filepath.Join(opts.configDir, "*"))
	if len(matches) < 1 {
		f, err := os.Create(filepath.Join(opts.configDir, "config.hcl"))
		if err != nil {
			return fmt.Errorf("could not create default configuration file - %s", err)
		}
		fmt.Fprintf(f, strings.TrimSpace(`
# Full configuration options can be found at https://developer.hashicorp.com/nomad/docs/configuration

data_dir  = "%s"
bind_addr = "0.0.0.0"

server {
  # license_path is required for Nomad Enterprise as of Nomad v1.1.1+
  #license_path = "%s\license.hclic"

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Run the installer from an elevated (Administrator) shell
  2. Pick a writable -data-dir such as C:\ProgramData\nomad\data
  3. Check for a conflicting file at the data-dir path and remove it
  4. Verify free disk space and that the volume is writable

Example fix

// before
nomad windows service install -data-dir "C:\nomad\data" // parent not writable
// after
nomad windows service install -data-dir "C:\ProgramData\nomad\data"
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check the data dir location before install
if fi, err := os.Stat(dataDir); err == nil && !fi.IsDir() {
    return fmt.Errorf("%s exists and is not a directory", dataDir)
}
probe := filepath.Join(filepath.Dir(dataDir), ".nomad_write_probe")
if err := os.WriteFile(probe, nil, 0o600); err != nil {
    return fmt.Errorf("data-dir parent not writable: %w", err)
}
os.Remove(probe)

Prevention

When it happens

Trigger: Running 'nomad windows service install' when the expanded dataDir cannot be created: insufficient privileges, an existing file blocking the directory path, invalid characters, or unavailable disk/drive.

Common situations: Custom -data-dir under a protected path without elevation; a file named 'data' already exists in the config root; disk full or read-only volume; path exceeding Windows MAX_PATH limits.

Related errors


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