{"record":{"id":"f5506de34661deba","repo":"lima-vm/lima","slug":"read-apfs-superblock-at-offset-d-w","errorCode":null,"errorMessage":"read APFS superblock at offset %d: %w","messagePattern":"read APFS superblock at offset (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apfs/chown.go","lineNumber":91,"sourceCode":"\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\n}\n\n// GPT constants.\nconst (\n\tgptHeaderSignature = \"EFI PART\"","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/apfs/chown.go#L73-L109","documentation":"Thrown by openContainer after findAPFSPartitionGPT succeeds: the ReadAt of the NX superblock at the discovered APFS partition byte offset failed. The underlying error (short read near end of file, I/O error) is wrapped with the offset. This indicates the located APFS partition region is unreadable or the image is truncated partway into the partition.","triggerScenarios":"apfs.Chown on a GPT image where the APFS partition entry's first LBA points beyond the end of the file (truncated image) or to an unreadable region of a device; storage I/O errors at that offset.","commonSituations":"A partially copied/cloned disk image where the partition table survived but the partition data did not; a sparse image with an unmaterialized region; resizing an image smaller than the partition layout expects; faulty disk or flaky USB-attached target.","solutions":["Verify the image file size covers the partition's first LBA (firstLBA*512 + 4096 bytes); re-copy the full image if truncated.","Regenerate or re-export the disk image from a healthy source.","Check the underlying storage/disk for I/O errors (smartctl, dmesg).","If the image was shrunk, restore its original size so partition offsets are in range."],"exampleFix":"// before\ntruncate -s 1G macos.img   // smaller than APFS partition start -> read fails\n// after\ncp --sparse=always full-macos.img macos.img   # copy the complete image","handlingStrategy":"validation","validationCode":"fi, err := os.Stat(diskPath)\n// ensure the file is large enough for a plausible partition start + superblock\nif err == nil && fi.Size() < 1024*1024 {\n    return fmt.Errorf(\"image %q suspiciously small; likely truncated\", diskPath)\n}","typeGuard":null,"tryCatchPattern":"if err := apfs.Chown(diskPath, role, uid, gid, paths...); err != nil {\n    if strings.Contains(err.Error(), \"read APFS superblock at offset\") {\n        // partition region unreadable/truncated: restore full image\n    }\n    return err\n}","preventionTips":["Copy disk images completely; never resize below the partition table's end LBA.","Use checksums to confirm image completeness after transfer.","Check storage health when I/O errors occur at partition offsets."],"tags":["apfs","gpt","io","truncated-image"],"backgroundTag":"io-read-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}