hashicorp/nomad · error

Failed to mount alloc dir: %v

Error message

Failed to mount alloc dir: %v

What it means

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.

Source

Thrown at client/allocdir/task_dir.go:205

		}

		// create the task unique directory under the client mounts path
		parent := filepath.Dir(t.MountsAllocDir)
		if err = os.MkdirAll(parent, fileMode710); err != nil {
			return fmt.Errorf("Failed to create task mount directory: %v", err)
		}
		if err = os.Chown(parent, uid, gid); err != nil {
			return fmt.Errorf("Failed to chown task mount directory: %v", err)
		}

		// create the taskdir mount point
		if err = mountDir(t.Dir, t.MountsTaskDir, uid, gid, fileMode710); err != nil {
			return fmt.Errorf("Failed to mount task dir: %v", err)
		}

		// create the allocdir mount point (owned by nobody)
		if err = mountDir(filepath.Join(t.AllocDir, "/alloc"), t.MountsAllocDir, nobodyUID, nobodyGID, fileMode777); err != nil {
			return fmt.Errorf("Failed to mount alloc dir: %v", err)
		}

		// create the secretsdir mount point
		if err = mountDir(t.SecretsDir, t.MountsSecretsDir, uid, gid, fileMode710); err != nil {
			return fmt.Errorf("Failed to mount secrets dir: %v", err)
		}
	}

	return nil
}

// buildChroot takes a mapping of absolute directory or file paths on the host
// to their intended, relative location within the task directory. This
// attempts hardlink and then defaults to copying. If the path exists on the
// host and can't be embedded an error is returned.
func (t *TaskDir) buildChroot(entries map[string]string) error {
	return t.embedDirs(entries)
}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Grant the client root/CAP_SYS_ADMIN or run it directly on the host
  2. Ensure the 'nobody' user exists and is resolvable (chown target)
  3. Clear stale mounts: `umount <data_dir>/client/mounts/<task>/alloc` then restart the client
  4. Check the source `<alloc_dir>/alloc` exists and the alloc wasn't garbage-collected mid-run; restart the affected alloc

Example fix

# before
Failed to mount alloc dir: no such file or directory
# after
$ ls /var/nomad/alloc/<id>/alloc  # verify source exists
$ nomad alloc stop <alloc>       # rebuild alloc cleanly
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure 'nobody' exists (chown target) and source alloc dir exists before Build
if _, err := user.Lookup("nobody"); err != nil {
    log.Fatal("Unveil alloc mount chowns to 'nobody'; user missing on host")
}
if _, err := os.Stat(filepath.Join(allocDir, "alloc")); err != nil {
    log.Fatalf("shared alloc dir missing: %v", err)
}

Try / catch

if err := taskDir.Build(fsi, chroot, username); err != nil {
    if strings.Contains(err.Error(), "Failed to mount alloc dir") {
        exec.Command("umount", mountsAllocDir).Run() // clear stale mount
        return retryBuild()
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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