lima-vm/lima · error

failed to create disk attachment for extra disk %#q: %w

Error message

failed to create disk attachment for extra disk %#q: %w

What it means

After conversion, Lima creates a VZ disk attachment with vz.NewDiskImageStorageDeviceAttachmentWithCacheAndSync (read-only=false, fsync sync mode); if the Virtualization framework rejects the attachment (unusable image, unsupported caching mode, path problems), the error is wrapped here.

Source

Thrown at pkg/driver/vz/vm_darwin.go:604

		disk, err := store.InspectDisk(diskName, d.FSType)
		if err != nil {
			return fmt.Errorf("failed to run load disk %#q: %w", diskName, err)
		}

		logrus.Infof("Mounting disk %#q on %#q", diskName, disk.MountPoint)
		if err = disk.LockForInstance(inst.Dir); err != nil {
			return fmt.Errorf("failed to attach disk %#q: %w", diskName, err)
		}
		extraDiskPath := filepath.Join(disk.Dir, filenames.DataDisk)
		// ConvertToRaw is a NOP if no conversion is needed
		logrus.Debugf("Converting extra disk %#q to a raw disk (if it is not a raw)", extraDiskPath)

		if err = diskUtil.Convert(ctx, raw.Type, extraDiskPath, extraDiskPath, nil, true); err != nil {
			return fmt.Errorf("failed to convert extra disk %#q to a raw disk: %w", extraDiskPath, err)
		}
		extraDiskPathAttachment, err := vz.NewDiskImageStorageDeviceAttachmentWithCacheAndSync(extraDiskPath, false, diskImageCachingMode, vz.DiskImageSynchronizationModeFsync)
		if err != nil {
			return fmt.Errorf("failed to create disk attachment for extra disk %#q: %w", extraDiskPath, err)
		}
		extraDisk, err := vz.NewVirtioBlockDeviceConfiguration(extraDiskPathAttachment)
		if err != nil {
			return fmt.Errorf("failed to create new virtio block device config for extra disk %#q: %w", extraDiskPath, err)
		}
		configurations = append(configurations, extraDisk)
	}

	if err := validateDiskFormat(ciDataPath); err != nil {
		return err
	}
	ciDataAttachment, err := vz.NewDiskImageStorageDeviceAttachment(ciDataPath, true)
	if err != nil {
		return err
	}
	ciData, err := vz.NewVirtioBlockDeviceConfiguration(ciDataAttachment)
	if err != nil {
		return err

View on GitHub (pinned to dd909d0973)

Solutions

  1. Verify the raw image is valid and readable (`file`, `qemu-img check`), and resize if 0 bytes
  2. Update macOS/Lima so the disk image caching mode is supported; avoid custom cache-mode overrides
  3. Recreate the disk and reattach
Defensive patterns

Strategy: try-catch

Validate before calling

st, err := os.Stat(extraDiskPath)
if err != nil || st.Size() == 0 {
    return fmt.Errorf("extra disk %s is missing or empty", extraDiskPath)
}

Try / catch

if err := startInstance(cfg); err != nil {
    if strings.Contains(err.Error(), "failed to create disk attachment") {
        // validate image, update macOS, or recreate the disk
    }
}

Prevention

When it happens

Trigger: vz.NewDiskImageStorageDeviceAttachmentWithCacheAndSync(extraDiskPath, false, diskImageCachingMode, DiskImageSynchronizationModeFsync) fails — e.g. the raw image has a size/alignment the framework rejects, the file is unreadable, or the caching mode is invalid on this macOS version.

Common situations: Running on a macOS version where the chosen diskImageCachingMode is unsupported; disk file permissions block the VM process; zero-size or sparse-weird raw image.

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/68f7776cc6ca1e7b. Report an issue: GitHub.