{"record":{"id":"47af1e4723d6f790","repo":"lima-vm/lima","slug":"failed-to-attach-disk-q-w","errorCode":null,"errorMessage":"failed to attach disk %#q: %w","messagePattern":"failed to attach disk %#q: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/driver/vz/vm_darwin.go","lineNumber":593,"sourceCode":"\t\tisoDev, err := vz.NewUSBMassStorageDeviceConfiguration(isoAttachment)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tconfigurations = append(configurations, isoDev)\n\t}\n\n\tdiskUtil := proxyimgutil.NewDiskUtil(ctx)\n\n\tfor _, d := range inst.Config.AdditionalDisks {\n\t\tdiskName := d.Name\n\t\tdisk, err := store.InspectDisk(diskName, d.FSType)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to run load disk %#q: %w\", diskName, err)\n\t\t}\n\n\t\tlogrus.Infof(\"Mounting disk %#q on %#q\", diskName, disk.MountPoint)\n\t\tif err = disk.LockForInstance(inst.Dir); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to attach disk %#q: %w\", diskName, err)\n\t\t}\n\t\textraDiskPath := filepath.Join(disk.Dir, filenames.DataDisk)\n\t\t// ConvertToRaw is a NOP if no conversion is needed\n\t\tlogrus.Debugf(\"Converting extra disk %#q to a raw disk (if it is not a raw)\", extraDiskPath)\n\n\t\tif err = diskUtil.Convert(ctx, raw.Type, extraDiskPath, extraDiskPath, nil, true); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to convert extra disk %#q to a raw disk: %w\", extraDiskPath, err)\n\t\t}\n\t\textraDiskPathAttachment, err := vz.NewDiskImageStorageDeviceAttachmentWithCacheAndSync(extraDiskPath, false, diskImageCachingMode, vz.DiskImageSynchronizationModeFsync)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create disk attachment for extra disk %#q: %w\", extraDiskPath, err)\n\t\t}\n\t\textraDisk, err := vz.NewVirtioBlockDeviceConfiguration(extraDiskPathAttachment)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create new virtio block device config for extra disk %#q: %w\", extraDiskPath, err)\n\t\t}\n\t\tconfigurations = append(configurations, extraDisk)\n\t}","sourceCodeStart":575,"sourceCodeEnd":611,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/driver/vz/vm_darwin.go#L575-L611","documentation":"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.","triggerScenarios":"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.","commonSituations":"Running two instances sharing one additionalDisk; an earlier VM crashed leaving a lock; running limactl as different users against the same LIMA_HOME.","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"],"exampleFix":"// before: two lima.yaml files both with\nadditionalDisks: [\"shared\"]\n// after\n$ limactl stop instance-a   # release shared disk before starting instance-b","handlingStrategy":"validation","validationCode":"running, _ := exec.Command(\"limactl\", \"list\").Output()\nif strings.Contains(string(running), \"Running\") {\n    // ensure no other running instance references the same additionalDisks entry\n}","typeGuard":null,"tryCatchPattern":"if err := startInstance(cfg); err != nil {\n    if strings.Contains(err.Error(), \"failed to attach disk\") {\n        // stop the conflicting instance or clear the stale lock\n    }\n}","preventionTips":["Never share one additionalDisk between simultaneously running instances","After a crash, clean stale locks before restarting","Use consistent user/permissions for one LIMA_HOME"],"tags":["disk","locking","vz-driver"],"backgroundTag":"resource-is-locked","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}