{"record":{"id":"8d4e915afcda82d6","repo":"lima-vm/lima","slug":"finding-apfs-partition-w","errorCode":null,"errorMessage":"finding APFS partition: %w","messagePattern":"finding APFS partition: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apfs/chown.go","lineNumber":86,"sourceCode":"\t\treturn nil, fmt.Errorf(\"open disk: %w\", err)\n\t}\n\tc := &container{f: f}\n\n\thdr := make([]byte, 4096) // minimum APFS block size\n\tif _, err := f.ReadAt(hdr, 0); err != nil {\n\t\tf.Close()\n\t\treturn nil, fmt.Errorf(\"read block 0: %w\", err)\n\t}\n\n\tif le.Uint32(hdr[nxMagicOff:]) == nxMagic {\n\t\t// Raw APFS container (no partition table).\n\t\tc.blockSize = le.Uint32(hdr[nxBlockSizeOff:])\n\t} else {\n\t\t// Look for a GPT partition table and find the APFS partition.\n\t\toffset, err := findAPFSPartitionGPT(f)\n\t\tif err != nil {\n\t\t\tf.Close()\n\t\t\treturn nil, fmt.Errorf(\"finding APFS partition: %w\", err)\n\t\t}\n\t\tc.baseOffset = offset\n\t\tif _, err := f.ReadAt(hdr, offset); err != nil {\n\t\t\tf.Close()\n\t\t\treturn nil, fmt.Errorf(\"read APFS superblock at offset %d: %w\", offset, err)\n\t\t}\n\t\tif le.Uint32(hdr[nxMagicOff:]) != nxMagic {\n\t\t\tf.Close()\n\t\t\treturn nil, fmt.Errorf(\"APFS partition at offset %d has bad magic\", offset)\n\t\t}\n\t\tc.blockSize = le.Uint32(hdr[nxBlockSizeOff:])\n\t}\n\n\tif c.blockSize < 4096 {\n\t\tf.Close()\n\t\treturn nil, fmt.Errorf(\"invalid block size %d\", c.blockSize)\n\t}\n\treturn c, nil","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/apfs/chown.go#L68-L104","documentation":"Thrown by openContainer when block 0 lacks the APFS NX magic and the fallback GPT scan (findAPFSPartitionGPT) fails. findAPFSPartitionGPT returns an error when the GPT header at LBA 1 is missing (\"no GPT header found\"), a partition entry cannot be read, or no APFS Container partition GUID is present in the table. The disk is therefore neither a raw APFS container nor a GPT-partitioned disk with an APFS partition.","triggerScenarios":"apfs.Chown called on a disk formatted with MBR instead of GPT, a non-APFS disk (ext4, NTFS, HFS+), a GPT disk whose APFS partition was deleted, or an arbitrary/corrupt file whose first block doesn't match nxMagic.","commonSituations":"Passing a Linux-format data disk image to an APFS-specific tool; an image converted between formats losing the partition table; targeting the wrong slice of a disk (e.g. a non-APFS partition device) rather than the whole disk.","solutions":["Confirm the image is macOS APFS — raw container or GPT with an APFS Container partition (GUID 7C3457EF-...-00306543ECAC).","If the disk uses MBR, re-format/partition as GPT with an APFS partition, or use the raw container image directly.","Pass the whole-disk image, not an individual non-APFS partition image.","Hex-inspect LBA 0/1 (`xxd -l 1024`) to confirm what partition scheme the file actually has."],"exampleFix":"// before\napfs.Chown(\"data-ext4.img\", ...) // finding APFS partition: no GPT header found\n// after\napfs.Chown(\"macos-apfs.dmg\", ...) // a GPT-partitioned APFS (or raw APFS) image","handlingStrategy":"validation","validationCode":"// check LBA1 for GPT signature before calling Chown on non-raw images\nf, _ := os.Open(diskPath)\nhdr := make([]byte, 8)\nf.ReadAt(hdr, 512)\nf.Close()\nif string(hdr) != \"EFI PART\" {\n    // also not raw APFS? then it is not an APFS disk at all\n}","typeGuard":null,"tryCatchPattern":"if err := apfs.Chown(diskPath, role, uid, gid, paths...); err != nil {\n    if strings.Contains(err.Error(), \"finding APFS partition\") {\n        // wrong filesystem type: re-create image as APFS or use correct image\n    }\n    return err\n}","preventionTips":["Label and track which images are APFS vs other filesystems.","Pass whole-disk GPT/APFS images, not individual non-APFS partition images.","Re-partition with GPT + APFS if the disk was formatted MBR or with another filesystem."],"tags":["apfs","gpt","disk-image","partition-table"],"backgroundTag":"no-apfs-partition-found","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}