Is there any way to fix after WSL failed to start when compacted using wslcompact (https://github.com/okibcn/wslcompact/)
Error received is The operation timed out because a response was not received from the virtual machine or container. Error code: Wsl/Service/CreateInstance/HCS_E_CONNECTION_TIMEOUT
- 135
- 1
- 1
- 8
2 Answers
Is there any way to fix after WSL failed to start when compacted using wslcompact
Err, maybe? I'm not all that hopeful, but it's certainly worth a shot, of course.
I'm assuming you've already rebooted the system, but if not, of course, give that a try.
With that all-too-obvious suggestion out of the way ...
Worth a shot suggestion ...
Try starting with:
wsl ~ -d <distro_name> /usr/bin/bash --noprofile --norc
Doubtful, but if that works, then things will probably be much easier to recover.
Try re-importing VHDX
Since you were compacting, I'm guessing disk space might be an issue in working through the following. You are going to want to back up any files that might remotely be usable, and these could be fairly large, so I'd recommend a separate drive for this. A USB drive will work, as long as you trust it (i.e., you've used more than half the drive's space in the past and been able to read the data afterwards -- So many "cheap" drivers report the space incorrectly and will cause corruption).
There are at least two places to look for the files to backup:
Your distribution data directory:
From Powershell, run:
Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss\ | ForEach-Object { (Get-ItemProperty $_.PSPATH) | Select-Object DistributionName,BasePath }Look in the directory reported for your distribution for
ext4.vhdxand back it up.The
wslcompacttemp directory:According to the source, this should be:
$Env:TEMP\wslcompactLook here as well for any
.vhdxfile. It should, if I'm reading the source correctly, be named after the distribution. Back them up.
Recommended: Compare the hashes of the files on your disk to the ones you backed up using PowerShell's Get-FileHash <filename> -Algorithm MD5 (credit to this SO answer).
Again, since I'm assuming space is an issue:
- One last time, confirm that you can't start WSL
- You've backed up the
ext4, right?
Then go ahead and start clean with the distribution with:
wsl --unregister <distro_name>
Final Warning: This will REMOVE the WSL distribution and virtual drive from your system without confirmation.
After removing the distribution, create a new distribution in a new location with a new name. If you found multiple .vhdx files, I believe the first one I asked you to back up above probably has a better chance of being intact, but I'm not sure. If the following doesn't work, try again with any other .vhdx files you found.
mkdir <NEW-path-for-distribution>
wsl --import --vhd <NEW_distro_name> <NEW-path-for-distribution> <location_of_backed_up.vhdx>
wsl ~ -d <NEW_distro_name>
If this works, then you'll probably be root in that distro. You'll need to follow the instructions in my answer here to set the default user.
Again if it works, you'll probably want to set it as the default distribution:
wsl --set-default <NEW_distro_name>
Again, if it doesn't work, try again with any other .vhdx you found.
Best of luck!
- 28,025
well i finally figured the way out. I fixed the corrupted vhdx by attaching it to another vm then fsck it
- 135
- 1
- 1
- 8