{"record":{"id":"db012ca5307d6a89","repo":"lima-vm/lima","slug":"failed-to-run-wsl-exe-import-s-s-s-w-out","errorCode":null,"errorMessage":"failed to run `wsl.exe --import %s %s %s`: %w (out=%#q)","messagePattern":"failed to run `wsl\\.exe --import (.+?) (.+?) (.+?)`: %w \\(out=%#q\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/driver/wsl2/vm_windows.go","lineNumber":52,"sourceCode":"\t\treturn fmt.Errorf(\"failed to run `wsl.exe --distribution %s`: %w (out=%#q)\",\n\t\t\tdistroName, err, out)\n\t}\n\treturn nil\n}\n\n// initVM calls WSL to import a new VM specifically for Lima.\nfunc initVM(ctx context.Context, instanceDir, distroName string) error {\n\tbaseDisk := filepath.Join(instanceDir, filenames.BaseDiskLegacy)\n\tlogrus.Infof(\"Importing distro from %#q to %#q\", baseDisk, instanceDir)\n\tout, err := executil.RunUTF16leCommand([]string{\n\t\t\"wsl.exe\",\n\t\t\"--import\",\n\t\tdistroName,\n\t\tinstanceDir,\n\t\tbaseDisk,\n\t}, executil.WithContext(ctx))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to run `wsl.exe --import %s %s %s`: %w (out=%#q)\",\n\t\t\tdistroName, instanceDir, baseDisk, err, out)\n\t}\n\treturn nil\n}\n\n// stopVM calls WSL to stop a running VM.\nfunc stopVM(ctx context.Context, distroName string) error {\n\tout, err := executil.RunUTF16leCommand([]string{\n\t\t\"wsl.exe\",\n\t\t\"--terminate\",\n\t\tdistroName,\n\t}, executil.WithContext(ctx))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to run `wsl.exe --terminate %s`: %w (out=%#q)\",\n\t\t\tdistroName, err, out)\n\t}\n\treturn nil\n}","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/pkg/driver/wsl2/vm_windows.go#L34-L70","documentation":"initVM runs `wsl.exe --import <distroName> <instanceDir> <baseDisk>` to create the Lima WSL distro from the base disk image. Non-zero exit from wsl.exe is wrapped with the distro name, target directory, base disk path, and decoded output. This means the distro could not be imported/registered.","triggerScenarios":"Start() -> initVM when the import fails: baseDisk file missing or corrupt, instanceDir invalid/in use, distro name already registered, or wsl.exe environment problems.","commonSituations":"Corrupted or truncated baseDisk (failed earlier download); leftover registration from a previous install causing 'already exists'; antivirus or permissions blocking the instance directory; running out of disk space while expanding the image.","solutions":["Delete the existing/conflicting distro: `wsl.exe --unregister <distroName>` (or `limactl delete <instance>`) and start again","Verify baseDisk exists and is a valid image; re-download via `limactl start` of the template","Check free disk space — importing expands the image; ensure instanceDir is on a writable NTFS path","Read the out= field for wsl.exe's specific error code and address it (e.g. access denied)","Run `wsl.exe --update` if wsl.exe itself is outdated or corrupted"],"exampleFix":"// before\nwsl.exe --import lima-myvm C:\\...\\myvm base.img   // fails: already exists\n// after\nwsl.exe --unregister lima-myvm\nlimactl start myvm","handlingStrategy":"validation","validationCode":"// pre-checks before import\nif _, err := os.Stat(baseDisk); err != nil {\n    return fmt.Errorf(\"base disk missing: %w\", err)\n}\nif wslDistroExists(distroName) {\n    return errors.New(\"distro already registered; unregister first\")\n}\nif freeDiskSpace(instanceDir) < minRequiredBytes {\n    return errors.New(\"insufficient disk space for import\")","typeGuard":null,"tryCatchPattern":"if err := driver.Start(ctx); err != nil {\n    if strings.Contains(err.Error(), \"--import\") {\n        // safe recovery: remove the partial distro and retry\n        exec.Command(\"wsl.exe\", \"--unregister\", distroName).Run()\n        return driver.Start(ctx)\n    }\n    return err\n}","preventionTips":["Ensure the baseDisk download completed fully before starting","Unregister stale distros after deleting instances","Keep the instance directory on a writable local NTFS volume","Maintain ample free disk space for image expansion"],"tags":["wsl2","windows","wsl-exe","import"],"backgroundTag":"wsl-command-failed","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}