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...
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.
Please note that you will be deleting Ubuntu and your data will be lost.
Follow these steps to clear this residual information.
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.
This operation will delete Ubuntu itself. Therefore, please note that the data will also be lost.
PS C:\Users\User> wsl --unregister Ubuntu
Unregistering.
The operation completed successfully.
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: