{"record":{"id":"992267de70ec4e43","repo":"hashicorp/nomad","slug":"failed-to-mount-shared-directory-for-task-w","errorCode":null,"errorMessage":"Failed to mount shared directory for task: %w","messagePattern":"Failed to mount shared directory for task: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/allocdir/task_dir.go","lineNumber":157,"sourceCode":"\t// Create the directories that should be in every task.\n\tfor dir, perms := range TaskDirs {\n\t\tabsdir := filepath.Join(t.Dir, dir)\n\n\t\tif err := allocMkdirAll(absdir, perms); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\t// Only link alloc dir into task dir for chroot fs isolation.\n\t// Image based isolation will bind the shared alloc dir in the driver.\n\t// If there's no isolation the task will use the host path to the\n\t// shared alloc dir.\n\tif fsi == fsisolation.Chroot {\n\t\t// If the path doesn't exist OR it exists and is empty, link it\n\t\tempty, _ := pathEmpty(t.SharedTaskDir)\n\t\tif !pathExists(t.SharedTaskDir) || empty {\n\t\t\tif err := linkDir(t.SharedAllocDir, t.SharedTaskDir, false); err != nil {\n\t\t\t\treturn fmt.Errorf(\"Failed to mount shared directory for task: %w\", err)\n\t\t\t}\n\t\t\tif err := linkDir(t.LogDir, filepath.Join(t.SharedTaskDir, \"logs\"), true); err != nil {\n\t\t\t\treturn fmt.Errorf(\"Failed to mount shared directory for task: %w\", err)\n\t\t\t}\n\n\t\t}\n\t}\n\n\tif err := t.MakeSecretsDirs(); err != nil {\n\t\treturn err\n\t}\n\n\t// Build chroot if chroot filesystem isolation is going to be used\n\tif fsi == fsisolation.Chroot {\n\t\tif err := t.buildChroot(chroot); err != nil {\n\t\t\treturn err\n\t\t}\n\t}","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/allocdir/task_dir.go#L139-L175","documentation":"During TaskDir.Build, when filesystem isolation is chroot and the task's shared directory is missing or empty, Nomad hard-links the alloc-level shared directory (SharedAllocDir) into the task's SharedTaskDir via linkDir. This error means that link operation failed, so the task would have no access to the shared allocation directory; Build aborts with this wrapped message.","triggerScenarios":"fsi == fsisolation.Chroot, pathEmpty(pathExists check) showed the task SharedTaskDir absent or empty, and linkDir(t.SharedAllocDir, t.SharedTaskDir, false) returned an error (mkdir/link failure).","commonSituations":"Alloc directory removed or recreated externally while the allocation runs; permission problems after client user changes; filesystems (cross-device) where hard linking fails and copy fallback also fails; stale state from unclean shutdowns.","solutions":["Check the wrapped linkDir error: fix the underlying mkdir/link failure (permissions, missing parent dir, cross-device link).","Ensure the client data_dir is on a single filesystem so hard links work.","Stop the allocation, clean the stale task directory under client data_dir, and reschedule.","Verify the client process owns and can write to data_dir/alloc."],"exampleFix":"// before: data_dir spanning two mounts -> hard link fails across devices\n# /etc/fstab\n/dev/sdb1 /var/lib/nomad/alloc ... \n/dev/sdc1 /var/lib/nomad/alloc/1234 ... \n// after: single filesystem for data_dir\n/dev/sdb1 /var/lib/nomad ... ","handlingStrategy":"try-catch","validationCode":"// client-side preflight\nif st, err := os.Stat(sharedAllocDir); err != nil {\n    return fmt.Errorf(\"shared alloc dir missing: %w\", err)\n} else if !st.IsDir() {\n    return fmt.Errorf(\"%s is not a directory\", sharedAllocDir)\n}\n// same-device check so hard links are possible\nif !sameDevice(sharedAllocDir, sharedTaskDirParent) {\n    return errors.New(\"alloc dir split across devices; hard links unavailable\")\n}","typeGuard":null,"tryCatchPattern":"if err := td.Build(); err != nil {\n    if strings.Contains(err.Error(), \"Failed to mount shared directory\") {\n        log.Printf(\"task dir rebuild needed; consider stopping alloc and cleaning data_dir/alloc: %v\", err)\n    }\n    return err\n}","preventionTips":["Keep the whole data_dir on one local filesystem.","Do not manually delete or recreate directories under data_dir/alloc while allocations run.","Run `nomad system gc` rather than rm -rf for cleanup.","Ensure the client user owns data_dir after any user migration."],"tags":["filesystem","mount","chroot","nomad"],"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"}