{"record":{"id":"8bff7c1cd4b631f6","repo":"hashicorp/nomad","slug":"cannot-create-data-directory-s","errorCode":null,"errorMessage":"cannot create data directory - %s","messagePattern":"cannot create data directory - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/windows_service_install.go","lineNumber":270,"sourceCode":"\tif opts.dataDir == \"\" {\n\t\topts.dataDir = filepath.Join(winsvc.WINDOWS_INSTALL_APPDATA_DIRECTORY, \"data\")\n\t}\n\n\tvar err error\n\tif opts.configDir, err = c.winPaths.Expand(opts.configDir); err != nil {\n\t\treturn fmt.Errorf(\"cannot generate configuration path - %s\", err)\n\t}\n\tif opts.dataDir, err = c.winPaths.Expand(opts.dataDir); err != nil {\n\t\treturn fmt.Errorf(\"cannot generate data path - %s\", err)\n\t}\n\n\t// Ensure directories exist\n\tif err = c.winPaths.CreateDirectory(opts.configDir, true); err != nil {\n\t\treturn fmt.Errorf(\"cannot create configuration directory - %s\", err)\n\t}\n\n\tif err = c.winPaths.CreateDirectory(opts.dataDir, true); err != nil {\n\t\treturn fmt.Errorf(\"cannot create data directory - %s\", err)\n\t}\n\n\t// Check if any configuration files exist\n\tmatches, _ := filepath.Glob(filepath.Join(opts.configDir, \"*\"))\n\tif len(matches) < 1 {\n\t\tf, err := os.Create(filepath.Join(opts.configDir, \"config.hcl\"))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not create default configuration file - %s\", err)\n\t\t}\n\t\tfmt.Fprintf(f, strings.TrimSpace(`\n# Full configuration options can be found at https://developer.hashicorp.com/nomad/docs/configuration\n\ndata_dir  = \"%s\"\nbind_addr = \"0.0.0.0\"\n\nserver {\n  # license_path is required for Nomad Enterprise as of Nomad v1.1.1+\n  #license_path = \"%s\\license.hclic\"","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/windows_service_install.go#L252-L288","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run the installer from an elevated (Administrator) shell","Pick a writable -data-dir such as C:\\ProgramData\\nomad\\data","Check for a conflicting file at the data-dir path and remove it","Verify free disk space and that the volume is writable"],"exampleFix":"// before\nnomad windows service install -data-dir \"C:\\nomad\\data\" // parent not writable\n// after\nnomad windows service install -data-dir \"C:\\ProgramData\\nomad\\data\"","handlingStrategy":"validation","validationCode":"// Pre-check the data dir location before install\nif fi, err := os.Stat(dataDir); err == nil && !fi.IsDir() {\n    return fmt.Errorf(\"%s exists and is not a directory\", dataDir)\n}\nprobe := filepath.Join(filepath.Dir(dataDir), \".nomad_write_probe\")\nif err := os.WriteFile(probe, nil, 0o600); err != nil {\n    return fmt.Errorf(\"data-dir parent not writable: %w\", err)\n}\nos.Remove(probe)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Choose writable data dirs (ProgramData, not system dirs)","Install from an elevated prompt","Check disk space and path length (<260 chars) beforehand","Remove files conflicting with the data-dir name"],"tags":["windows","data-dir","permissions"],"backgroundTag":"directory-creation-permission-denied","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}