Windows Subsystem for Linux 2 (WSL2) is a feature in Windows 10 that allows you to run a Linux distribution directly on your Windows machine. It provides a seamless integration of Linux commands and tools within the Windows environment. However, there may be instances where you need to uninstall WSL2, and if you have Ubuntu virtual machines (VMs) running, it is important to know how to recover them. In this article, we will guide you through the steps to recover your Ubuntu VMs after uninstalling WSL2 on Windows 10.
Step 1: Backup your Ubuntu VMs
Before uninstalling WSL2, it is crucial to create a backup of your Ubuntu VMs. This will ensure that you do not lose any important data or configurations. To backup your Ubuntu VMs, follow these steps:
- Open File Explorer and navigate to the following directory:
C:\Users\YourUsername\AppData\Local\Packages - Locate the folder with a name similar to
CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc. This folder represents your Ubuntu VM. - Right-click on the folder and select "Copy".
- Paste the copied folder to a safe location, such as an external hard drive or cloud storage.
Step 2: Uninstall WSL2
Now that you have backed up your Ubuntu VMs, you can proceed with uninstalling WSL2. To uninstall WSL2, follow these steps:
- Open PowerShell as an administrator. You can do this by right-clicking on the Start button and selecting "Windows PowerShell (Admin)".
- Run the following command to list all installed WSL distributions:
wsl --list --verbose
This command will display a list of installed distributions along with their version numbers.
- To uninstall WSL2, run the following command:
wsl --unregister Ubuntu-20.04
Replace "Ubuntu-20.04" with the name of your Ubuntu distribution.
Step 3: Reinstall WSL2
After uninstalling WSL2, you can reinstall it to recover your Ubuntu VMs. To reinstall WSL2, follow these steps:
- Open PowerShell as an administrator.
- Run the following command to enable the WSL feature:
wsl --install
This command will download and install the latest version of WSL2.
- Once the installation is complete, open the Microsoft Store.
- Search for "Ubuntu" and select the desired Ubuntu distribution to install.
- Click on the "Install" button to download and install the Ubuntu distribution.
Step 4: Restore your Ubuntu VMs
Now that you have reinstalled WSL2 and Ubuntu, you can restore your Ubuntu VMs from the backup. To restore your Ubuntu VMs, follow these steps:
- Open File Explorer and navigate to the location where you saved the backup of your Ubuntu VMs.
- Copy the folder representing your Ubuntu VM.
- Navigate to the following directory:
C:\Users\YourUsername\AppData\Local\Packages - Paste the copied folder into the "Packages" directory.
Once the folder is pasted, you should see your Ubuntu VM listed when you run the command wsl --list --verbose in PowerShell.
Congratulations! You have successfully recovered your Ubuntu VMs after uninstalling WSL2 on Windows 10. You can now continue using your Ubuntu VMs within the Windows environment.
References
| [1] | Microsoft Docs - Install WSL 2 | https://docs.microsoft.com/en-us/windows/wsl/install-win10 |
| [2] | Microsoft Store - Ubuntu | https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6 |