lima-vm/lima · error
open disk: %w
Error message
open disk: %w
What it means
Thrown by openContainer (invoked at the start of every apfs.Chown call) when os.OpenFile(path, os.O_RDWR, 0) cannot open the disk image. The underlying *os.PathError (ENOENT, EACCES, EISDIR, EMFILE, ...) is wrapped as "open disk". Chown requires read-write access because it patches inode blocks in place.
Source
Thrown at pkg/apfs/chown.go:68
// the APFS container starts (nonzero for GPT-partitioned disks),
// and the APFS block size.
type container struct {
f *os.File
baseOffset int64 // byte offset of APFS container within file
blockSize uint32
}
// volumeInfo holds resolved volume information.
type volumeInfo struct {
omapTreeAddr uint64 // physical address of volume omap B-tree root
rootTreeOID uint64 // virtual OID of filesystem B-tree root
latestXID uint64 // transaction ID of the volume superblock
}
func openContainer(path string) (*container, error) {
f, err := os.OpenFile(path, os.O_RDWR, 0)
if err != nil {
return nil, fmt.Errorf("open disk: %w", err)
}
c := &container{f: f}
hdr := make([]byte, 4096) // minimum APFS block size
if _, err := f.ReadAt(hdr, 0); err != nil {
f.Close()
return nil, fmt.Errorf("read block 0: %w", err)
}
if le.Uint32(hdr[nxMagicOff:]) == nxMagic {
// Raw APFS container (no partition table).
c.blockSize = le.Uint32(hdr[nxBlockSizeOff:])
} else {
// Look for a GPT partition table and find the APFS partition.
offset, err := findAPFSPartitionGPT(f)
if err != nil {
f.Close()
return nil, fmt.Errorf("finding APFS partition: %w", err)View on GitHub (pinned to dd909d0973)
Solutions
- Verify the diskPath exists and is the actual image/device file, not a directory or mount point.
- Run with sufficient privileges (e.g. sudo) if the image is root-owned or is a protected block device.
- Fix file permissions (chmod/chown) so the current user can open the file read-write.
- Check ulimit -n if you suspect file-descriptor exhaustion (EMFILE).
Example fix
// before
c, err := apfs.Chown("/dev/disk3s1", ...) // EACCES as non-root
// after
// sudo limactl ... (or run the caller with privileges to open the device R/W) Defensive patterns
Strategy: validation
Validate before calling
fi, err := os.Stat(diskPath)
if err != nil {
return fmt.Errorf("disk %q not found", diskPath)
}
if fi.IsDir() {
return fmt.Errorf("%q is a directory, expected an image/device", diskPath)
}
if f, err := os.OpenFile(diskPath, os.O_RDWR, 0); err != nil {
return fmt.Errorf("no read-write access to %q: %w", diskPath, err)
} else { f.Close() } Try / catch
if err := apfs.Chown(diskPath, role, uid, gid, paths...); err != nil {
var perr *fs.PathError
if errors.As(err, &perr) && errors.Is(perr, fs.ErrPermission) {
// advise running with elevated privileges
}
return err
} Prevention
- Check existence and writability of the image path before invoking Chown.
- Run with the privileges required to open the image/block device read-write.
- Pass the image/device path, never a directory or mount point.
When it happens
Trigger: apfs.Chown called with a diskPath that does not exist, is a directory, or the process lacks read/write permission; too many open files in the process.
Common situations: Typo in the disk image path; running without sudo on a disk image owned by root (e.g. a macOS system volume); passing a block device that requires elevated privileges; passing the mount point instead of the image/device path.
Understand the failure class
Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.
Related errors
- failed to unprotect instance %#q: %w
- read block 0: %w
- read APFS superblock at offset %d: %w
- looking up %#q in directory (cnid %d): %w
- failed to remove the autostart entry for instance %#q: %w
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/c396874c49991b21.
Report an issue: GitHub.