{"record":{"id":"45465af1700d3c66","repo":"hashicorp/nomad","slug":"failed-to-create-share-cgroup-w","errorCode":null,"errorMessage":"failed to create share cgroup: %w","messagePattern":"failed to create share cgroup: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/lib/cgroupslib/init.go","lineNumber":168,"sourceCode":"\t\t\treturn fmt.Errorf(\"failed to create nomad cgroup: %w\", err)\n\t\t}\n\n\t\tif err := writeCG(activation, NomadCgroupParent, subtreeFile); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to set subtree control on nomad cgroup: %w\", err)\n\t\t}\n\n\t\tif err := writeCG(cores, NomadCgroupParent, cpusetFile); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to write root partition cpuset: %w\", err)\n\t\t}\n\n\t\tlog.Debug(\"top level partition root nomad.slice cgroup initialized\")\n\n\t\t//\n\t\t// configuring nomad.slice/share (member)\n\t\t//\n\n\t\tif err := mkCG(NomadCgroupParent, SharePartition()); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create share cgroup: %w\", err)\n\t\t}\n\n\t\tif err := writeCG(activation, NomadCgroupParent, SharePartition(), subtreeFile); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to set subtree control on cpuset share partition: %w\", err)\n\t\t}\n\n\t\tlog.Debug(\"partition member nomad.slice/share cgroup initialized\")\n\n\t\t//\n\t\t// configuring nomad.slice/reserve (member)\n\t\t//\n\n\t\tif err := mkCG(NomadCgroupParent, ReservePartition()); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create share cgroup: %w\", err)\n\t\t}\n\n\t\tif err := writeCG(activation, NomadCgroupParent, ReservePartition(), subtreeFile); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to set subtree control on cpuset reserve partition: %w\", err)","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/lib/cgroupslib/init.go#L150-L186","documentation":"Init() creates the nomad.slice/share child cgroup used for all non-reserved tasks on cgroups v2. This error wraps a failure of os.MkdirAll creating that directory, meaning the share partition cannot be set up and task placement will fail.","triggerScenarios":"mkCG(NomadCgroupParent, SharePartition()) fails with EACCES (no permission to create directories under /sys/fs/cgroup/nomad.slice), EEXIST is treated as ok so usually EACCES/EINVAL, or the parent nomad.slice does not exist because an earlier Init step failed.","commonSituations":"Agent runs in a container without cgroup namespace write access; systemd delegation path mismatch so writes go to a read-only area; filesystem cgroup mounted read-only; leftover broken state where nomad.slice is missing but config assumes it.","solutions":["Ensure the agent can write under /sys/fs/cgroup/nomad.slice (run as root or configure systemd Delegate=yes).","Fix any earlier 'failed to create nomad cgroup' error so nomad.slice exists before share creation.","Confirm /sys/fs/cgroup is not mounted read-only; remount rw.","If running inside a container, run with privileged/host cgroup access (e.g. cgroupns=host)."],"exampleFix":"// before (docker run without cgroup access)\ndocker run hashicorp/nomad agent\n// after\ndocker run --privileged -v /sys/fs/cgroup:/sys/fs/cgroup hashicorp/nomad agent","handlingStrategy":"validation","validationCode":"if err := syscall.Access(\"/sys/fs/cgroup\", os.W_OK); err != nil {\n  return fmt.Errorf(\"no write access to cgroup root: %w\", err)\n}\nif _, err := os.Stat(\"/sys/fs/cgroup\"); err != nil {\n  return err\n}","typeGuard":"func cgroupTreeWritable(root string) bool {\n  return syscall.Access(root, syscall.W_OK) == nil\n}","tryCatchPattern":"if err := cgroupslib.Init(logger, cores); err != nil {\n  if strings.Contains(err.Error(), \"failed to create share cgroup\") {\n    logger.Error(\"verify cgroup write privileges and that nomad.slice was created\")\n  }\n  return err\n}","preventionTips":["Run the agent with cgroup write privileges (root, CAP_SYS_ADMIN, or systemd delegation).","Avoid running the client in restricted containers unless cgroupns=host/privileged.","Ensure earlier Init steps (nomad.slice creation) succeed before share creation.","Keep /sys/fs/cgroup mounted rw."],"tags":["linux","cgroups","cgroupv2","mkdir"],"backgroundTag":"cgroup-create-permission-denied","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"}