{"record":{"id":"4fc6e58d5f904eae","repo":"hashicorp/nomad","slug":"failed-to-mount-alloc-dir-v","errorCode":null,"errorMessage":"Failed to mount alloc dir: %v","messagePattern":"Failed to mount alloc dir: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocdir/task_dir.go","lineNumber":205,"sourceCode":"\t\t}\n\n\t\t// create the task unique directory under the client mounts path\n\t\tparent := filepath.Dir(t.MountsAllocDir)\n\t\tif err = os.MkdirAll(parent, fileMode710); err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to create task mount directory: %v\", err)\n\t\t}\n\t\tif err = os.Chown(parent, uid, gid); err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to chown task mount directory: %v\", err)\n\t\t}\n\n\t\t// create the taskdir mount point\n\t\tif err = mountDir(t.Dir, t.MountsTaskDir, uid, gid, fileMode710); err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to mount task dir: %v\", err)\n\t\t}\n\n\t\t// create the allocdir mount point (owned by nobody)\n\t\tif err = mountDir(filepath.Join(t.AllocDir, \"/alloc\"), t.MountsAllocDir, nobodyUID, nobodyGID, fileMode777); err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to mount alloc dir: %v\", err)\n\t\t}\n\n\t\t// create the secretsdir mount point\n\t\tif err = mountDir(t.SecretsDir, t.MountsSecretsDir, uid, gid, fileMode710); err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to mount secrets dir: %v\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// buildChroot takes a mapping of absolute directory or file paths on the host\n// to their intended, relative location within the task directory. This\n// attempts hardlink and then defaults to copying. If the path exists on the\n// host and can't be embedded an error is returned.\nfunc (t *TaskDir) buildChroot(entries map[string]string) error {\n\treturn t.embedDirs(entries)\n}","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocdir/task_dir.go#L187-L223","documentation":"TaskDir.Build (Unveil mode) bind-mounts the shared alloc directory (`<alloc_dir>/alloc`) into the task's mounts path, owned by nobody:nobody with mode 0777. This error wraps mountDir failure for that shared alloc mount. It is the same mount mechanism as the task dir mount but for the alloc-shared tree.","triggerScenarios":"mountDir(filepath.Join(t.AllocDir, \"/alloc\"), t.MountsAllocDir, nobodyUID, nobodyGID, 0777) fails: missing source `<alloc>/alloc` dir, chown to nobody denied, or mount(2) refused.","commonSituations":"Unprivileged client without CAP_SYS_ADMIN; host lacks the 'nobody' user so the chown target is invalid (see the nobody-lookup error upstream); stale mount at MountsAllocDir from a crashed alloc; alloc dir pruned concurrently while building.","solutions":["Grant the client root/CAP_SYS_ADMIN or run it directly on the host","Ensure the 'nobody' user exists and is resolvable (chown target)","Clear stale mounts: `umount <data_dir>/client/mounts/<task>/alloc` then restart the client","Check the source `<alloc_dir>/alloc` exists and the alloc wasn't garbage-collected mid-run; restart the affected alloc"],"exampleFix":"# before\nFailed to mount alloc dir: no such file or directory\n# after\n$ ls /var/nomad/alloc/<id>/alloc  # verify source exists\n$ nomad alloc stop <alloc>       # rebuild alloc cleanly","handlingStrategy":"try-catch","validationCode":"// ensure 'nobody' exists (chown target) and source alloc dir exists before Build\nif _, err := user.Lookup(\"nobody\"); err != nil {\n    log.Fatal(\"Unveil alloc mount chowns to 'nobody'; user missing on host\")\n}\nif _, err := os.Stat(filepath.Join(allocDir, \"alloc\")); err != nil {\n    log.Fatalf(\"shared alloc dir missing: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := taskDir.Build(fsi, chroot, username); err != nil {\n    if strings.Contains(err.Error(), \"Failed to mount alloc dir\") {\n        exec.Command(\"umount\", mountsAllocDir).Run() // clear stale mount\n        return retryBuild()\n    }\n    return err\n}","preventionTips":["Guarantee the nobody user exists on all client nodes","Grant the client CAP_SYS_ADMIN / run as root","Don't GC allocs concurrently while a client is building them (watch for aggressive min_heartbeat/purge settings)","Clean stale mounts before restarting the client"],"tags":["filesystem","mount","nomad-client"],"backgroundTag":"mount-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"}