Having discovered a new feature called Windows Subsystem for Linux (WSL) in Windows 10 through which you can install Linux bash shell in Windows 10, I went crazy and ended up installing multiple Linux distros through WSL. After installing Kali Linux and Alpine Linux, when I tried to launch bash shell, Windows showed an error 0x80070040. The error gave no description, just the error number and I could not find any explanation on the internet either. But with a little tinkering, I was able to fix this problem.
Here is how you can fix error 0x80070040 in WSL:
- Launch cmd.exe shell. This can be done by pressing Win+R, typing cmd and pressing Enter.
- In the command prompt, type wslconfig /all /list. This will show a list of all the installed Linux distros. Note down the default distro. In this screenshot, Debian is default.
- Since the default Linux distro is causing the error, we will unregister it using the command wslconfig /unregister [distroname] where [distroname] is the name of default Linux distro we found in step 2. In our case it is Debian, so we give command wslconfig /unregister Debian.
- If you have multiple Linux distros, WSL will automatically set the next available Linux distro as default. Now if you run bash.exe (using Win+R, typing bash.exe and press Enter) it will launch bash shell using this new default distro. However if you want the same distro back, you can visit https://aka.ms/wslstore to install available Linux distros from Microsoft Store.
The above steps are for Windows 10 versions earlier than 1903. If you are using Windows 10 version 1903 or above, then you have to use wsl command instead of wslconfig. For showing a list of all the installed Linux distributions, you have to use the command wsl –list –all and to unregister a distro, you have to give a command wsl –unregister [distribution]. where [distribution] is the name of Linux distro you want to unregister.