lima-vm/lima · error
failed to attach disk %#q: %w
Error message
failed to attach disk %#q: %w
What it means
After locating the disk, attachDisks calls disk.LockForInstance(inst.Dir) to take an exclusive lock binding the disk to this instance; failure (disk already locked/attached to another running instance, stale lock, permission problem) is wrapped here.
Source
Thrown at pkg/driver/vz/vm_darwin.go:593
isoDev, err := vz.NewUSBMassStorageDeviceConfiguration(isoAttachment)
if err != nil {
return err
}
configurations = append(configurations, isoDev)
}
diskUtil := proxyimgutil.NewDiskUtil(ctx)
for _, d := range inst.Config.AdditionalDisks {
diskName := d.Name
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)
}View on GitHub (pinned to dd909d0973)
Solutions
- Stop the other instance currently using the disk (`limactl stop <other-instance>`) or detach the disk from it
- Remove the stale lock file in the disk directory if no instance is running, then retry
- Recreate or rename the disk if the lock state is unrecoverable
Example fix
// before: two lima.yaml files both with additionalDisks: ["shared"] // after $ limactl stop instance-a # release shared disk before starting instance-b
Defensive patterns
Strategy: validation
Validate before calling
running, _ := exec.Command("limactl", "list").Output()
if strings.Contains(string(running), "Running") {
// ensure no other running instance references the same additionalDisks entry
} Try / catch
if err := startInstance(cfg); err != nil {
if strings.Contains(err.Error(), "failed to attach disk") {
// stop the conflicting instance or clear the stale lock
}
} Prevention
- Never share one additionalDisk between simultaneously running instances
- After a crash, clean stale locks before restarting
- Use consistent user/permissions for one LIMA_HOME
When it happens
Trigger: Starting an instance while the same additional disk is already attached to another running instance; leftover lock file in the disk directory from a crash; filesystem permissions preventing lock creation.
Common situations: Running two instances sharing one additionalDisk; an earlier VM crashed leaving a lock; running limactl as different users against the same LIMA_HOME.
Related errors
- failed to run load disk %#q: %w
- failed to convert extra disk %#q to a raw disk: %w
- in use by instance %#q
- failed to unlock for reuse in the same instance: %w
- disk format %#q not supported, use `qcow2` or `raw` instead
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/47af1e4723d6f790.
Report an issue: GitHub.