hashicorp/nomad · error
Failed to make the alloc directory %v: %w
Error message
Failed to make the alloc directory %v: %w
What it means
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.
Source
Thrown at client/allocdir/alloc_dir.go:359
func (a *AllocDir) UnmountAll() error {
a.mu.RLock()
defer a.mu.RUnlock()
mErr := new(multierror.Error)
for _, dir := range a.TaskDirs {
if err := dir.Unmount(); err != nil {
mErr = multierror.Append(mErr, err)
}
}
return mErr.ErrorOrNil()
}
// Build the directory tree for an allocation.
func (a *AllocDir) Build() error {
// Make the alloc directory, owned by the nomad process.
if err := os.MkdirAll(a.AllocDir, fileMode755); err != nil {
return fmt.Errorf("Failed to make the alloc directory %v: %w", a.AllocDir, err)
}
// Make the shared directory and make it available to all user/groups.
if err := allocMkdirAll(a.SharedDir, fileMode755); err != nil {
return err
}
// Create shared subdirs
for _, dir := range SharedAllocDirs {
p := filepath.Join(a.SharedDir, dir)
if err := allocMkdirAll(p, fileMode777); err != nil {
return err
}
}
// Mark as built
a.mu.Lock()
a.built = trueView on GitHub (pinned to 482b49bf1a)
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
Example fix
// before
client {
data_dir = "/ro-mount/nomad"
}
// after
client {
data_dir = "/var/lib/nomad"
} Defensive patterns
Strategy: validation
Validate before calling
if fi, err := os.Stat(allocDir.AllocDir); err == nil && !fi.IsDir() {
os.Remove(allocDir.AllocDir) // clear non-directory blocking MkdirAll
}
if err := os.MkdirAll(allocDir.AllocDir, 0o755); err != nil {
return err
} Try / catch
if err := allocDir.Build(); err != nil {
if errors.Is(err, fs.ErrPermission) || errors.Is(err, syscall.EROFS) {
return fmt.Errorf("check data_dir writability: %w", err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to remove alloc dir %q: %w
- Failed to lookup nobody user: %v
- Failed to create task mount directory: %v
- Failed to mount task dir: %v
- Failed to mount alloc dir: %v
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/c0c3159b050f11c9.
Report an issue: GitHub.