{"record":{"id":"00d82d90b017e113","repo":"lima-vm/lima","slug":"failed-to-rename-q-to-q-w-00d82d","errorCode":null,"errorMessage":"failed to rename %#q to %#q: %w","messagePattern":"failed to rename %#q to %#q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/driverutil/disk.go","lineNumber":107,"sourceCode":"\t\t\tos.Remove(diskPath)\n\t\t\t_ = os.Rename(isoPath, imagePath)\n\t\t\treturn err\n\t\t}\n\t\tif err := diskUtil.Convert(ctx, diskImageFormat, diskPath, diskPath, &diskSizeInBytes, false); err != nil {\n\t\t\tos.Remove(diskPath)\n\t\t\t_ = os.Rename(isoPath, imagePath)\n\t\t\treturn fmt.Errorf(\"failed to create disk %#q: %w\", diskPath, err)\n\t\t}\n\t} else {\n\t\tformat, err := nativeimgutil.DetectFormat(imagePath)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t// Resize handled by prepareDisk() after CreateDisk()\n\t\tif format == string(diskImageFormat) {\n\t\t\tif err = os.Rename(imagePath, diskPath); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to rename %#q to %#q: %w\", imagePath, diskPath, err)\n\t\t\t}\n\t\t\tif err := os.Chmod(diskPath, 0o644); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to chmod %#q: %w\", diskPath, err)\n\t\t\t}\n\t\t} else {\n\t\t\tif err := diskUtil.Convert(ctx, diskImageFormat, imagePath, diskPath, &diskSizeInBytes, false); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to convert %#q to %#q: %w\", imagePath, diskPath, err)\n\t\t\t}\n\t\t\tos.Remove(imagePath)\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":89,"sourceCodeEnd":121,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/driverutil/disk.go#L89-L121","documentation":"EnsureDisk wraps an os.Rename failure when moving the downloaded non-ISO image to its final disk path inside the instance directory. This library throws it because it cannot promote the downloaded image to the VM disk file. The wrapped os error (e.g. ENOENT, EXDEV, EACCES) is the actual cause.","triggerScenarios":"Calling EnsureDisk (via CreateDisk) on a non-ISO image whose detected format equals the requested diskImageFormat, when os.Rename(imagePath, diskPath) fails: image file missing, instance dir removed mid-run, cross-device rename, or permission problem on instDir.","commonSituations":"Disk space/cleanup scripts deleted the downloaded image before EnsureDisk ran; instDir on a different filesystem after relocation; running limactl as a user without write access to the instance directory; concurrent lima processes racing on the same instance.","solutions":["Check the wrapped error for ENOENT/EACCES and verify imagePath and the instance directory exist and are writable","Re-create the instance or re-download the image (limactl delete + limactl start) so the image file is present again","Ensure instDir is on the same filesystem as the image (avoid moving ${LIMA_HOME} across mounts)","Fix ownership/permissions on the instance directory (chown/chmod to the user running limactl)"],"exampleFix":"// before: image deleted externally, rename fails\n// after: guard before starting or retry download\nif _, err := os.Stat(imagePath); errors.Is(err, os.ErrNotExist) {\n    return fmt.Errorf(\"image %s missing; re-download before EnsureDisk\", imagePath)\n}","handlingStrategy":"validation","validationCode":"imagePath := filepath.Join(instDir, \"image\")\nif _, err := os.Stat(imagePath); err != nil {\n    return fmt.Errorf(\"image missing before EnsureDisk: %w\", err)\n}\nif fi, err := os.Stat(instDir); err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"instDir unusable: %w\", err)\n}","typeGuard":"func canRename(dir string) bool {\n    f, err := os.CreateTemp(dir, \".probe-*\")\n    if err != nil {\n        return false\n    }\n    name := f.Name()\n    f.Close()\n    os.Remove(name)\n    return true\n}","tryCatchPattern":"if err := driverutil.EnsureDisk(ctx, instDir, diskSize, format); err != nil {\n    var perr *os.PathError\n    if errors.As(err, &perr) {\n        // inspect perr.Err (ENOENT/EACCES/EXDEV) and recover: re-download or fix perms\n    }\n    return err\n}","preventionTips":["Keep ${LIMA_HOME} on a single local filesystem to avoid EXDEV","Never run cleanup jobs against an instance directory mid-start","Run limactl as the same user that owns the instance files"],"tags":["filesystem","rename","disk-image"],"backgroundTag":"file-rename-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}