Fix Ubuntu on WSL that failed to boot after reinstalling

When reinstalling Ubuntu on WSL (Windows Subsystem for Linux), the following error message may appear and it may not boot.

Failed to attach disk 'C:\Users\ahaya\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx' to WSL2: 指定されたファイルが見つかりません。
Error code: Wsl/Service/CreateInstance/MountVhd/ERROR_FILE_NOT_FOUND
Failed to attach disk 'C:\Users\ahaya\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx' to WSL2: 指定されたファイルが見つかりません。
Error code: Wsl/Service/CreateInstance/MountVhd/ERROR_FILE_NOT_FOUND
Failed to attach disk 'C:\Users\ahaya\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx' to WSL2: 指定されたファイルが見つかりません。
Error code: Wsl/Service/CreateInstance/MountVhd/ERROR_FILE_NOT_FOUND
Press any key to continue...
TOC

How to fix

This can be fixed by performing the initialization process that Ubuntu on WSL performs on first boot. Reinstalling Ubuntu will not perform the initialization process because the registration information in the system is still there.

Do as follows.

STEP
If an Ubutnu boot error is displayed, press any key to exit.
STEP
Launch Windows PowerShell.
STEP
Run “wsl -l” in PowerShell to get the registered distribution.
PS C:\Users\Name> wsl -l
Windows Subsystem for Linux Distributions:
docker-desktop-data (Default)
docker-desktop
Ubuntu

In this example, three distributions are registered.

STEP
Unregister Ubuntu.

Run wsl --unregister Ubuntu in PowerShell to unregister Ubuntu.

PS C:\Users\User> wsl --unregister Ubuntu
Unregistering.
The operation completed successfully.
STEP
Launch Ubuntu and perform the initialization process.

When you launch Ubuntu after unregistration, the initialization process will begin. You will be able to create an Ubuntu account as follows.

Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username:
Let's share this post !

Author of this article

Akira Hayashiのアバター Akira Hayashi Representative, Software Engineer

I am an application developer loves programming. This blog is a tech blog, its articles are learning notes. In my work, I mainly focus on desktop and mobile application development, but I also write technical books and teach seminars. The websites of my work and books are here -> RK Kaihatsu.

TOC