{"record":{"id":"dbc8597facd629f1","repo":"containerd/containerd","slug":"failed-to-create-file-q-w","errorCode":null,"errorMessage":"failed to create file %q: %w","messagePattern":"failed to create file %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/mount/manager/mkfs.go","lineNumber":121,"sourceCode":"\t\t// Check fs\n\t\tswitch fs {\n\t\tcase \"ext2\", \"ext3\", \"ext4\":\n\t\t\tbinary = fmt.Sprintf(\"mkfs.%s\", fs)\n\t\t\tif id != \"\" {\n\t\t\t\tcreateArgs = append(createArgs, []string{\"-U\", id}...)\n\t\t\t}\n\t\tcase \"xfs\":\n\t\t\tbinary = \"mkfs.xfs\"\n\t\t\tif id != \"\" {\n\t\t\t\tcreateArgs = append(createArgs, []string{\"-m\", fmt.Sprintf(\"uuid=%s\", id)}...)\n\t\t\t}\n\t\tdefault:\n\t\t\treturn mount.Mount{}, fmt.Errorf(\"unsupported filesystem %q: %w\", fs, errdefs.ErrInvalidArgument)\n\t\t}\n\n\t\tf, err := r.OpenFile(subpath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0640)\n\t\tif err != nil {\n\t\t\treturn mount.Mount{}, fmt.Errorf(\"failed to create file %q: %w\", m.Source, err)\n\t\t}\n\n\t\tcreateArgs = append(createArgs, f.Name())\n\n\t\terr = f.Truncate(size)\n\t\tf.Close()\n\t\tif err != nil {\n\t\t\treturn mount.Mount{}, fmt.Errorf(\"failed to truncate file %q: %w\", m.Source, err)\n\t\t}\n\n\t\tif err := createWritableImage(ctx, binary, createArgs...); err != nil {\n\t\t\treturn mount.Mount{}, fmt.Errorf(\"failed format %q: %w\", m.Source, err)\n\t\t}\n\t} else {\n\t\treturn mount.Mount{}, fmt.Errorf(\"failed to stat %q: %w\", m.Source, err)\n\t}\n\n\treturn m, nil","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/containerd/containerd/blob/4246446a2bf7d03837b0244118d858799393bd80/core/mount/manager/mkfs.go#L103-L139","documentation":"The mkfs transform opens (and creates) the backing file with r.OpenFile(path, O_RDWR|O_CREATE|O_TRUNC, 0640) before running the mkfs binary; if that open fails, the underlying error is wrapped with the file path. This is a filesystem-level create/open failure, not a formatting failure.","triggerScenarios":"Transform reaches the OpenFile call (valid root matched, options parsed) and OpenFile returns an error: parent dir missing, permission denied, read-only filesystem, ENOSPC, or the root backend rejecting O_TRUNC on existing files.","commonSituations":"Root filesystem full or read-only; subpath's parent directories don't exist under the root; process lacks write permission to the root directory; SELinux/AppArmor denying file creation in the configured root path.","solutions":["Check the wrapped cause (errors.Is fs.ErrPermission/fs.ErrNotExist) and fix permissions or create missing parent directories","Ensure the configured root path is writable and has free space (df, mount -o rw)","Verify the source path resolves inside the root and its parent exists","Check for MAC policies (SELinux/AppArmor) blocking file creation and adjust labels/profiles"],"exampleFix":"// before\nroot: \"/mnt/ro-loopbacks\" // mounted read-only -> OpenFile fails\n// after\nmount -o remount,rw /mnt/ro-loopbacks // or configure root on a writable volume","handlingStrategy":"validation","validationCode":"target := filepath.Join(root, subpath)\nif err := os.MkdirAll(filepath.Dir(target), 0755); err != nil {\n\treturn err\n}\nf, err := os.OpenFile(target, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0640)\nif err != nil {\n\treturn fmt.Errorf(\"cannot create backing file %s: %w\", target, err)\n}\nf.Close()","typeGuard":null,"tryCatchPattern":"m, err := manager.Transform(ctx, mount)\nif err != nil && strings.Contains(err.Error(), \"failed to create file\") {\n\tif errors.Is(err, fs.ErrPermission) || errors.Is(err, fs.ErrNotExist) {\n\t\t// fix root writability / parent dirs before retrying\n\t}\n}","preventionTips":["Keep configured root writable with free disk space","Create parent directories of the backing file in advance","Check SELinux/AppArmor policies on the root path","Unwrap errors.Is to target the exact open failure"],"tags":["mount","mkfs","filesystem","openfile"],"backgroundTag":"file-create-failed","analyzedSha":"4246446a2bf7d03837b0244118d858799393bd80","analyzedAt":"2026-09-02T00:14:43.053Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}