{"record":{"id":"c0c3159b050f11c9","repo":"hashicorp/nomad","slug":"failed-to-make-the-alloc-directory-v-w","errorCode":null,"errorMessage":"Failed to make the alloc directory %v: %w","messagePattern":"Failed to make the alloc directory (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocdir/alloc_dir.go","lineNumber":359,"sourceCode":"func (a *AllocDir) UnmountAll() error {\n\ta.mu.RLock()\n\tdefer a.mu.RUnlock()\n\n\tmErr := new(multierror.Error)\n\tfor _, dir := range a.TaskDirs {\n\t\tif err := dir.Unmount(); err != nil {\n\t\t\tmErr = multierror.Append(mErr, err)\n\t\t}\n\t}\n\n\treturn mErr.ErrorOrNil()\n}\n\n// Build the directory tree for an allocation.\nfunc (a *AllocDir) Build() error {\n\t// Make the alloc directory, owned by the nomad process.\n\tif err := os.MkdirAll(a.AllocDir, fileMode755); err != nil {\n\t\treturn fmt.Errorf(\"Failed to make the alloc directory %v: %w\", a.AllocDir, err)\n\t}\n\n\t// Make the shared directory and make it available to all user/groups.\n\tif err := allocMkdirAll(a.SharedDir, fileMode755); err != nil {\n\t\treturn err\n\t}\n\n\t// Create shared subdirs\n\tfor _, dir := range SharedAllocDirs {\n\t\tp := filepath.Join(a.SharedDir, dir)\n\t\tif err := allocMkdirAll(p, fileMode777); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\t// Mark as built\n\ta.mu.Lock()\n\ta.built = true","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocdir/alloc_dir.go#L341-L377","documentation":"AllocDir.Build() creates the allocation directory tree; it starts with os.MkdirAll on a.AllocDir with mode 0755. If directory creation fails, the error is wrapped in this message identifying the directory path.","triggerScenarios":"Calling AllocDir.Build() when os.MkdirAll(a.AllocDir) fails: parent path does not exist and cannot be created, permission denied, read-only filesystem, or the path exists as a non-directory file.","commonSituations":"Misconfigured client data_dir / alloc dir on a read-only or full volume; nomad agent lacking permissions under /var; a stale regular file occupying the alloc dir path after a bad restore.","solutions":["Fix os.MkdirAll error cause: check permissions on the alloc dir path and its parents","Ensure the path is not occupied by a regular file; remove or move it","Verify the filesystem is writable and has free space","Correct the client data_dir/alloc_dir configuration to a writable location"],"exampleFix":"// before\nclient {\n  data_dir = \"/ro-mount/nomad\"\n}\n// after\nclient {\n  data_dir = \"/var/lib/nomad\"\n}","handlingStrategy":"validation","validationCode":"if fi, err := os.Stat(allocDir.AllocDir); err == nil && !fi.IsDir() {\n    os.Remove(allocDir.AllocDir) // clear non-directory blocking MkdirAll\n}\nif err := os.MkdirAll(allocDir.AllocDir, 0o755); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":"if err := allocDir.Build(); err != nil {\n    if errors.Is(err, fs.ErrPermission) || errors.Is(err, syscall.EROFS) {\n        return fmt.Errorf(\"check data_dir writability: %w\", err)\n    }\n    return err\n}","preventionTips":["Point data_dir at a writable, non-read-only volume","Never place a regular file at the alloc dir path","Verify disk space before task placement","Keep alloc dir ownership consistent with the nomad user"],"tags":["filesystem","directory-creation","nomad-client"],"backgroundTag":"directory-creation-failed","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"}