Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to launch wsl2 #11474

Closed
1 of 2 tasks
ReinForce-II opened this issue Apr 16, 2024 · 9 comments
Closed
1 of 2 tasks

Unable to launch wsl2 #11474

ReinForce-II opened this issue Apr 16, 2024 · 9 comments

Comments

@ReinForce-II
Copy link

ReinForce-II commented Apr 16, 2024

Windows Version

10.0.22631.3007

WSL Version

2.1.5.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.146.1-2

Distro Version

Ubuntu 20.04

Other Software

No response

Repro Steps

type wsl in powershell

Expected Behavior

wsl2 launched with no errors

Actual Behavior

The distribution failed to start. Error code: 5, failure step: 2
Error code: Wsl/Service/CreateInstance/E_FAIL

Diagnostic Logs

Copy link

View similar issues

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

Diagnostic information
Detected appx version: 2.1.5.0
Detected user visible error: Wsl/Service/CreateInstance/E_FAIL

@FreedSoul
Copy link

@ReinForce-II i have the same issue, how did you resolve it?

@ReinForce-II
Copy link
Author

@ReinForce-II i have the same issue, how did you resolve it?

In my case, the rootfs is corrupted, run e2fsck on it solved the problem.

@FreedSoul
Copy link

i cant even start wsl, can you give some insights or links, how to run e2fsck?

@ReinForce-II
Copy link
Author

i cant even start wsl, can you give some insights or links, how to run e2fsck?

attach the vhdx containing rootfs of wsl2 to another linux system

@FreedSoul
Copy link

whoever that get this error message, the problem is that, you have your ext filesystem corrupted, because a dirty shutdown (in my case close vscode then quickly shutdown the pc) or power outage, you can repair the issue here or follow this other thread

@new-TonyWang
Copy link

whoever that get this error message, the problem is that, you have your ext filesystem corrupted, because a dirty shutdown (in my case close vscode then quickly shutdown the pc) or power outage, you can repair the issue here or follow this other thread

TKS,this worked for me

@zhhugh
Copy link

zhhugh commented Jan 2, 2025

I fixed it,here is the details:

Issue Description

When WSL2 shows the following error:

The distribution failed to start. Error code: 5, failure step: 2
Error code: Wsl/Service/CreateInstance/E_FAIL

This is typically caused by filesystem corruption due to:

  • Abnormal shutdown
  • Power outage
  • Quick shutdown while programs like VSCode are still running
  • Other scenarios that lead to a "dirty shutdown"

Repair Steps

1. Preparation

  1. First, backup your corrupted vhdx file:

    • The original file is usually located at: %USERPROFILE%\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx
    • Copy this file to a safe location
  2. Create a new Linux instance in WSL for repair:

wsl --install -d Ubuntu-20.04

2. Install Repair Tools

In the newly created WSL instance, run:

sudo apt update
sudo apt install qemu-utils

3. Repair the Filesystem

  1. Enable the nbd module:
sudo modprobe nbd
  1. Mount the vhdx file that needs repair (use your actual backup file path):
sudo qemu-nbd -c /dev/nbd0 -f vhdx /mnt/path/to/your/ext4.vhdx
  1. Run filesystem check and repair:
sudo e2fsck -f /dev/nbd0
  1. When prompted during repair, you can type 'a' to automatically answer 'yes' to all questions

  2. After completion, unmount:

sudo qemu-nbd -d /dev/nbd0

4. Replace the File

  1. Shut down all WSL instances:
wsl --shutdown
  1. Replace files:
    • Rename the original corrupted file as backup
    • Copy the repaired file to the original location

5. Testing

Start WSL to test if the repair was successful:

wsl -d Ubuntu

Important Notes

  1. Always backup the original file before starting the repair process
  2. Filesystem corruption is usually caused by improper shutdown, develop good shutdown habits
  3. If issues occur after repair, you can restore using the renamed original file
  4. Ensure you have enough disk space for the backup files
  5. The repair process requires administrative privileges in WSL

Prevention Tips

To avoid similar issues:

  1. Ensure all WSL instances are properly closed before shutting down
  2. Use wsl --shutdown command to properly close WSL
  3. Don't force shutdown your computer while WSL is running
  4. Consider using a UPS if power outages are common in your area

Troubleshooting

If you encounter issues during repair:

  1. Make sure you have sufficient disk space
  2. Verify that you have administrative privileges
  3. Check that the paths to your vhdx files are correct
  4. Ensure no WSL instances are running during the repair

Credits

This guide is based on real-world experience fixing WSL2 filesystem corruption. Feel free to share and improve this guide.

References

@LandRover
Copy link

@zhhugh thanks for the detailed solution, it worked for me, and I could recover my WSL via e2fsck from another instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants