{"record":{"id":"0538df6ccbd42964","repo":"lima-vm/lima","slug":"failed-to-lock-disk-q-w","errorCode":null,"errorMessage":"failed to lock disk %#q: %w","messagePattern":"failed to lock disk %#q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/driver/krunkit/krunkit_darwin_arm64.go","lineNumber":72,"sourceCode":"\tif inst.Config.SSH.OverVsock != nil && *inst.Config.SSH.OverVsock {\n\t\tsshVsockPath := filepath.Join(inst.Dir, sshVsockSock)\n\t\targs = append(args, \"--device\", fmt.Sprintf(\"virtio-vsock,port=22,socketURL=%s,connect\", sshVsockPath))\n\t}\n\n\t// Add additional disks\n\tif len(inst.Config.AdditionalDisks) > 0 {\n\t\tctx := context.Background()\n\t\tdiskUtil := proxyimgutil.NewDiskUtil(ctx)\n\t\tfor _, d := range inst.Config.AdditionalDisks {\n\t\t\tdisk, derr := store.InspectDisk(d.Name, d.FSType)\n\t\t\tif derr != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to load disk %#q: %w\", d.Name, derr)\n\t\t\t}\n\t\t\tif disk.Instance != \"\" {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to run attach disk %#q, in use by instance %#q\", disk.Name, disk.Instance)\n\t\t\t}\n\t\t\tif lerr := disk.Lock(inst.Dir); lerr != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to lock disk %#q: %w\", d.Name, lerr)\n\t\t\t}\n\t\t\textraDiskPath := filepath.Join(disk.Dir, filenames.DataDisk)\n\t\t\tlogrus.Infof(\"Mounting disk %#q on %#q\", disk.Name, disk.MountPoint)\n\t\t\tif cerr := diskUtil.Convert(ctx, raw.Type, extraDiskPath, extraDiskPath, nil, true); cerr != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to convert extra disk %#q to raw: %w\", extraDiskPath, cerr)\n\t\t\t}\n\t\t\targs = append(args, \"--device\", fmt.Sprintf(\"virtio-blk,path=%s,format=raw\", extraDiskPath))\n\t\t}\n\t}\n\n\t// Network commands\n\tnetworkArgs, err := buildNetworkArgs(inst)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to build network arguments: %w\", err)\n\t}\n\n\t// File sharing commands\n\tif *inst.Config.MountType == limatype.VIRTIOFS {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/driver/krunkit/krunkit_darwin_arm64.go#L54-L90","documentation":"After passing the in-use check, Cmdline locks the disk for this instance via disk.Lock(inst.Dir). If the lock operation fails (stale lock files, permission problems on the disk directory, or concurrent lock contention), the error is wrapped as `failed to lock disk %#q: %w` and instance start aborts.","triggerScenarios":"Calling Start/Cmdline on an instance with additionalDisks when the disk's lock file cannot be acquired — e.g. leftover lock from a crashed VM, read-only or permission-denied ~/.lima/disks/<name>, or a race where another process locks the disk first.","commonSituations":"After a hard crash/kill -9 of limactl or the VM process leaving locks behind; running Lima instances under different users; syncing the Lima home via a filesystem that doesn't honor locks (some network mounts).","solutions":["Check the wrapped `%w` error; if it indicates a stale lock, run `limactl disk undeploy <disk>` then retry the start.","Fix permissions on ~/.lima/disks/<name> so the current user can write lock files.","Ensure no other limactl/VM process is concurrently starting an instance that shares this disk.","Move LIMA_HOME off network filesystems that break file locking."],"exampleFix":"// before\n$ limactl start myinstance   // fails: failed to lock disk \"data\"\n// after\n$ limactl disk undeploy data\n$ limactl start myinstance","handlingStrategy":"validation","validationCode":"// Shell: ensure disk dir is writable and no stale lock before start\ntest -w \"$HOME/.lima/disks/<name>\" || { echo \"disk dir not writable\"; exit 1; }\nlimactl disk undeploy <name> 2>/dev/null || true","typeGuard":null,"tryCatchPattern":"if err := inst.Start(ctx); err != nil {\n    if strings.Contains(err.Error(), \"failed to lock disk\") {\n        _ = exec.Command(\"limactl\", \"disk\", \"undeploy\", diskName).Run()\n        return inst.Start(ctx)\n    }\n    return err\n}","preventionTips":["Shut down instances cleanly (limactl stop) to release locks","Avoid running Lima under different users or on lock-breaking network filesystems","Undeploy disks after abnormal termination","Check disk directory permissions after OS/user changes"],"tags":["krunkit","disks","lock","macos"],"backgroundTag":"disk-lock-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}