lima-vm/lima · error
failed to run attach disk %#q, in use by instance %#q
Error message
failed to run attach disk %#q, in use by instance %#q
What it means
Cmdline checks each additional disk's `disk.Instance` field; if it is non-empty the disk is already attached to another running Lima instance, so krunkit refuses to attach it a second time and returns `failed to run attach disk %#q, in use by instance <name>`. Lima disks are single-attach: locking to more than one instance would corrupt data.
Source
Thrown at pkg/driver/krunkit/krunkit_darwin_arm64.go:69
"--device", fmt.Sprintf("virtio-vsock,port=%d,socketURL=%s,connect", vSockPort, filepath.Join(inst.Dir, filenames.GuestAgentSock)),
}
if inst.Config.SSH.OverVsock != nil && *inst.Config.SSH.OverVsock {
sshVsockPath := filepath.Join(inst.Dir, sshVsockSock)
args = append(args, "--device", fmt.Sprintf("virtio-vsock,port=22,socketURL=%s,connect", sshVsockPath))
}
// Add additional disks
if len(inst.Config.AdditionalDisks) > 0 {
ctx := context.Background()
diskUtil := proxyimgutil.NewDiskUtil(ctx)
for _, d := range inst.Config.AdditionalDisks {
disk, derr := store.InspectDisk(d.Name, d.FSType)
if derr != nil {
return nil, fmt.Errorf("failed to load disk %#q: %w", d.Name, derr)
}
if disk.Instance != "" {
return nil, fmt.Errorf("failed to run attach disk %#q, in use by instance %#q", disk.Name, disk.Instance)
}
if lerr := disk.Lock(inst.Dir); lerr != nil {
return nil, fmt.Errorf("failed to lock disk %#q: %w", d.Name, lerr)
}
extraDiskPath := filepath.Join(disk.Dir, filenames.DataDisk)
logrus.Infof("Mounting disk %#q on %#q", disk.Name, disk.MountPoint)
if cerr := diskUtil.Convert(ctx, raw.Type, extraDiskPath, extraDiskPath, nil, true); cerr != nil {
return nil, fmt.Errorf("failed to convert extra disk %#q to raw: %w", extraDiskPath, cerr)
}
args = append(args, "--device", fmt.Sprintf("virtio-blk,path=%s,format=raw", extraDiskPath))
}
}
// Network commands
networkArgs, err := buildNetworkArgs(inst)
if err != nil {
return nil, fmt.Errorf("failed to build network arguments: %w", err)
}View on GitHub (pinned to dd909d0973)
Solutions
- Stop/ungister the instance currently holding the disk (`limactl stop <other-instance>`), then start yours.
- If the holder instance is stale/gone, remove the stale reference: `limactl disk undeploy <disk>` (or delete disk metadata) so it can be re-attached.
- Give each instance its own disk: create a new disk with `limactl disk create` and update `additionalDisks`.
- Run `limactl disk list` to see which instance occupies the disk before starting.
Example fix
# before (second instance lima.yaml) additionalDisks: - name: shared-data # attached to instance "dev" # after additionalDisks: - name: shared-data-2 # limactl disk create shared-data-2 --size 50G
Defensive patterns
Strategy: validation
Validate before calling
// Go: check the disk is free before start
if diskJSON, err := exec.Command("limactl", "disk", "list", diskName).Output(); err == nil {
if bytes.Contains(diskJSON, []byte("instance:")) && !bytes.Contains(diskJSON, []byte("instance: \"\"")) {
return fmt.Errorf("disk %q in use; stop the holder instance first", diskName)
}
} Try / catch
if err := startInstance(ctx, name); err != nil {
if strings.Contains(err.Error(), "in use by instance") {
holder := extractInstanceName(err.Error())
_ = exec.Command("limactl", "stop", holder).Run()
return startInstance(ctx, name) // retry once
}
return err
} Prevention
- Never share additionalDisks between concurrently running instances
- Run `limactl disk list` to inspect attachment before start
- After crashes, run `limactl disk undeploy <disk>` to clear stale attachment
- Give each parallel instance its own disk
When it happens
Trigger: Starting an instance whose `additionalDisks` includes a disk whose metadata records it as in use by a different (usually still registered as running) instance; happens when a previous instance crashed without releasing the disk or two instances reference the same disk.
Common situations: Cloning an instance config that shares `additionalDisks` between instances; a previous VM crashed leaving the disk lock/instance field stale; trying to boot the same disk in a second instance for parallel workloads.
Related errors
- failed to lock disk %#q: %w
- failed to load disk %#q: %w
- failed to convert extra disk %#q to raw: %w
- unimplemented by the krunkit driver
- failed to build network arguments: %w
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/cc4def4bc9cb9c59.
Report an issue: GitHub.