lima-vm/lima · error
failed to detect the format of %#q: %w
Error message
failed to detect the format of %#q: %w
What it means
validateDiskFormat opens the disk image and asks qcow2reader to detect its format; if the file is unreadable as a known image format (or I/O fails), Lima wraps the underlying error. This means the additional disk / cidata file passed to the vz driver is not a recognizable disk image.
Source
Thrown at pkg/driver/vz/vm_darwin.go:537
if err != nil {
return err
}
configurations = append(configurations, networkConfig)
}
}
vmConfig.SetNetworkDevicesVirtualMachineConfiguration(configurations)
return nil
}
func validateDiskFormat(diskPath string) error {
f, err := os.Open(diskPath)
if err != nil {
return err
}
defer f.Close()
img, err := qcow2reader.Open(f)
if err != nil {
return fmt.Errorf("failed to detect the format of %#q: %w", diskPath, err)
}
supportedDiskTypes := []image.Type{raw.Type, asif.Type}
if t := img.Type(); !slices.Contains(supportedDiskTypes, t) {
return fmt.Errorf("expected the format of %#q to be one of %v, got %#q", diskPath, supportedDiskTypes, t)
}
// TODO: ensure that the disk is formatted with GPT or ISO9660
return nil
}
func attachDisks(ctx context.Context, inst *limatype.Instance, vmConfig *vz.VirtualMachineConfiguration) error {
diskPath := filepath.Join(inst.Dir, filenames.Disk)
isoPath := filepath.Join(inst.Dir, filenames.ISO)
ciDataPath := filepath.Join(inst.Dir, filenames.CIDataISO)
var configurations []vz.StorageDeviceConfiguration
if osutil.FileExists(diskPath) {
if err := validateDiskFormat(diskPath); err != nil {
return errView on GitHub (pinned to dd909d0973)
Solutions
- Inspect the file (`file <path>`, `qemu-img info`) and re-create or re-download the disk image in a supported format
- Ensure the path passed as additional disk actually points to the data disk (datadisk file) and is non-empty
- Delete the instance/disk store entry and let Lima recreate the disk
Defensive patterns
Strategy: validation
Validate before calling
f, err := os.Open(diskPath)
if err != nil { return err }
magic := make([]byte, 8)
f.Read(magic)
// verify magic matches a known image type or run `file diskPath` before attach Try / catch
if err := limactlStart(cfg); err != nil {
if strings.Contains(err.Error(), "failed to detect the format") {
// re-download / recreate the disk image
}
} Prevention
- Verify disk images with `file`/`qemu-img info` before attaching
- Check download checksums so truncated images are caught early
- Never point additionalDisks at manually created placeholder files
When it happens
Trigger: attachDisks -> validateDiskFormat on a disk path whose file is corrupted, empty, truncated, or in an unsupported format that qcow2reader.Open cannot sniff.
Common situations: Interrupted download/copy of a disk image; a placeholder or text file at the disk path; disk created by another tool in a format qcow2reader does not detect; permission/IO error during open that surfaces after Open.
Related errors
- expected the format of %#q to be one of %v, got %#q
- resolving filesystem root tree OID %d: %w
- resolving path %#q: %w
- chown inode %d (%#q): %w
- read block 0: %w
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/d73ecb25608c5dbc.
Report an issue: GitHub.