After reinstalling Ubuntu on WSL, you might encounter an issue where Ubuntu fails to boot. You’ll see the following error in the console:
Failed to attach disk 'C:\Users\ahaya\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx' to WSL2: The system cannot find the file specified.
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: The system cannot find the file specified.
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: The system cannot find the file specified.
Error code: Wsl/Service/CreateInstance/MountVhd/ERROR_FILE_NOT_FOUND
Press any key to continue...
TOC
How to fix it
To fix this problem, you’ll need to carry out the initialization process. Ubuntu on WSL executes this process during its first boot. Unfortunately, this process gets skipped during a reinstallation of Ubuntu as some information remains in the system.
Follow these steps to clear this residual information.
STEP
Press any key to quit if you see an error message.
STEP
Launch the Windows PowerShell.
STEP
Get the registered distributions.
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 the Ubuntu distribution.
PS C:\Users\User> wsl --unregister Ubuntu
Unregistering.
The operation completed successfully.
STEP
Launch Ubuntu. This triggers the initialization process.
Ubuntu will now perform the initialization process as the previous registration information has been removed from your system. After completing the process, you can create a new account for Ubuntu.
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: