{"record":{"id":"4e537a7fd0f1c156","repo":"lima-vm/lima","slug":"disk-q-already-exists-q","errorCode":null,"errorMessage":"disk %#q already exists (%#q)","messagePattern":"disk %#q already exists \\(%#q\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/disk.go","lineNumber":106,"sourceCode":"\t\treturn err\n\t}\n\n\tswitch format {\n\tcase \"qcow2\", \"raw\":\n\tdefault:\n\t\treturn fmt.Errorf(\"disk format %#q not supported, use `qcow2` or `raw` instead\", format)\n\t}\n\n\t// only exactly one arg is allowed\n\tname := args[0]\n\n\tdiskDir, err := store.DiskDir(name)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif _, err := os.Stat(diskDir); !errors.Is(err, fs.ErrNotExist) {\n\t\treturn fmt.Errorf(\"disk %#q already exists (%#q)\", name, diskDir)\n\t}\n\n\tlogrus.Infof(\"Creating %s disk %#q with size %s\", format, name, units.BytesSize(float64(diskSize)))\n\n\tif err := os.MkdirAll(diskDir, 0o700); err != nil {\n\t\treturn err\n\t}\n\n\t// qemu may not be available, use it only if needed.\n\tdataDisk := filepath.Join(diskDir, filenames.DataDisk)\n\tdiskUtil := proxyimgutil.NewDiskUtil(ctx)\n\terr = diskUtil.CreateDisk(ctx, dataDisk, diskSize)\n\tif err != nil {\n\t\trerr := os.RemoveAll(diskDir)\n\t\tif rerr != nil {\n\t\t\terr = errors.Join(err, fmt.Errorf(\"failed to remove a directory %#q: %w\", diskDir, rerr))\n\t\t}\n\t\treturn fmt.Errorf(\"failed to create %s disk in %#q: %w\", format, diskDir, err)","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/disk.go#L88-L124","documentation":"A disk with the given name already exists in the Lima store, detected by stat-ing the computed disk directory (store.DiskDir). Lima refuses to create a second disk with the same name; the message includes the conflicting directory path.","triggerScenarios":"`limactl disk create <name>` when ~/.lima/disks/<name> (or the LIMA_HOME equivalent) already exists — from a previous create, a leftover from a failed deletion, or a name collision.","commonSituations":"Re-running an install script that creates disks idempotently-unaware; orphaned disk dir after an interrupted delete; accidentally reusing a disk name.","solutions":["Use the existing disk: attach it with `additionalDisks` in the instance config instead of creating a new one","Delete the old disk first: `limactl disk delete <name>` (add --force if in use)","Pick a different disk name for the new disk","If the directory is an orphan with no disk metadata, remove the directory manually and re-create"],"exampleFix":"// before\n$ limactl disk create data --size 10GiB\n// disk \"data\" already exists (\"~/.lima/disks/data\")\n// after\n$ limactl disk list\n$ limactl disk delete data   # or choose a new name\n$ limactl disk create data2 --size 10GiB","handlingStrategy":"validation","validationCode":"const disks = await listDisks()\nif (disks.some(d => d.name === name)) {\n  console.log(`disk ${name} exists; reuse it via additionalDisks`)\n  return\n}","typeGuard":"function diskExists(name: string, disks: {name: string}[]): boolean {\n  return disks.some(d => d.name === name)\n}","tryCatchPattern":"try {\n  await createDisk(name, { size })\n} catch (err) {\n  if (/already exists/.test(err.message)) {\n    console.warn(`Reusing existing disk ${name}`)\n  } else throw err\n}","preventionTips":["Run `limactl disk list` before creating disks","Make disk-creation scripts idempotent (check-then-create)","Clean up orphaned ~/.lima/disks/<name> dirs after failed operations"],"tags":["disk","duplicate","limactl"],"backgroundTag":"disk-already-exists","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}