lima-vm/lima · error
failed to run `wsl.exe --import %s %s %s`: %w (out=%#q)
Error message
failed to run `wsl.exe --import %s %s %s`: %w (out=%#q)
What it means
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.
Source
Thrown at pkg/driver/wsl2/vm_windows.go:52
return fmt.Errorf("failed to run `wsl.exe --distribution %s`: %w (out=%#q)",
distroName, err, out)
}
return nil
}
// initVM calls WSL to import a new VM specifically for Lima.
func initVM(ctx context.Context, instanceDir, distroName string) error {
baseDisk := filepath.Join(instanceDir, filenames.BaseDiskLegacy)
logrus.Infof("Importing distro from %#q to %#q", baseDisk, instanceDir)
out, err := executil.RunUTF16leCommand([]string{
"wsl.exe",
"--import",
distroName,
instanceDir,
baseDisk,
}, executil.WithContext(ctx))
if err != nil {
return fmt.Errorf("failed to run `wsl.exe --import %s %s %s`: %w (out=%#q)",
distroName, instanceDir, baseDisk, err, out)
}
return nil
}
// stopVM calls WSL to stop a running VM.
func stopVM(ctx context.Context, distroName string) error {
out, err := executil.RunUTF16leCommand([]string{
"wsl.exe",
"--terminate",
distroName,
}, executil.WithContext(ctx))
if err != nil {
return fmt.Errorf("failed to run `wsl.exe --terminate %s`: %w (out=%#q)",
distroName, err, out)
}
return nil
}View on GitHub (pinned to dd909d0973)
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
Example fix
// before wsl.exe --import lima-myvm C:\...\myvm base.img // fails: already exists // after wsl.exe --unregister lima-myvm limactl start myvm
Defensive patterns
Strategy: validation
Validate before calling
// pre-checks before import
if _, err := os.Stat(baseDisk); err != nil {
return fmt.Errorf("base disk missing: %w", err)
}
if wslDistroExists(distroName) {
return errors.New("distro already registered; unregister first")
}
if freeDiskSpace(instanceDir) < minRequiredBytes {
return errors.New("insufficient disk space for import") Try / catch
if err := driver.Start(ctx); err != nil {
if strings.Contains(err.Error(), "--import") {
// safe recovery: remove the partial distro and retry
exec.Command("wsl.exe", "--unregister", distroName).Run()
return driver.Start(ctx)
}
return err
} Prevention
- 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
When it happens
Trigger: Start() -> initVM when the import fails: baseDisk file missing or corrupt, instanceDir invalid/in use, distro name already registered, or wsl.exe environment problems.
Common situations: 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.
Related errors
- failed to run `wsl.exe --distribution %s`: %w (out=%#q)
- failed to run `wsl.exe --terminate %s`: %w (out=%#q)
- cannot use `--sync` with a wsl2 instance, the host directory
- unimplemented
- failed to construct wsl boot.sh script: %w
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/db012ca5307d6a89.
Report an issue: GitHub.