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...
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.
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.
Run wsl --unregister Ubuntu
in PowerShell to unregister Ubuntu.
PS C:\Users\User> wsl --unregister Ubuntu
Unregistering.
The operation completed successfully.
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: