Prerequisites
If we are using a username different than root, we need to know it running the command (WSL side):
# Linux Terminal whoami Also, we need to know the distro name and WSL version, running the command on PowerShell (Windows side):
#PowerShell wsl --list --verbose Knowing the username: equiman, the Linux distribution: Ubuntu, and confirming that we are using the WSL 2 version, we are ready to...
Backup
All next steps need to be done on PowerShell (Windows side).
First, we need to close all terminals that are using WSL, and then shut it down to avoid data corruption running the command.
# PowerShell wsl --shutdown Next, we are going to create a backup from our Ubuntu Linux distribution.
# PowerShell mkdir D:\backup wsl --export Ubuntu D:\backup\ubuntu.tar Don't worry if you do not see progress indicators. This can take a while depending on how much data you have. Maybe it's a good idea to take a rest.
When finished, it is very important ensure that the D:\backup\ubuntu.tarfile was created.
Relaunch
Relaunch WSL by running the command:
# PowerShell wsl --distribution Ubuntu All next steps need to be done on WSL (Linux side).
Update the packages' source and update the outdated installed applications.
# Linux Terminal sudo apt update sudo apt list --upgradable sudo apt upgrade -y It’s important to install this update manager core package this will trick the system to think there is a new LTS available and allow you to do an in-place upgrade.
# Linux Terminal sudo apt install update-manager-core Install the new version with
# Linux Terminal sudo do-release-upgrade If you are using an LTS version (recommended) and found that there is no new LTS version available it will show this message
Checking for a new Ubuntu release
There is no development version of an LTS available.
To upgrade to the latest non-LTS development release
set Prompt=normal in /etc/update-manager/release-upgrades.
⚠ If it's not relevant to you to not use LTS versions, you can change the Prompt to normal in /etc/update-manager/release-upgrades file and rerun the previous command.
Another alternative is to use the -d flag added with the command
# Linux Terminal sudo do-release-upgrade -d This is done because an upgrade to the latest LTS is not directly available till July of the year of release of the LTS. However, the -d flag forces the command to upgrade to the latest development release, and it also considers an LTS release as a development release.
Then, accept all packages you have to download, and it will take a while depending on your network and disk speed mostly.
Finally, run the command
# Linux Terminal sudo reboot Recover
If something goes wrong in the process, don't worry, we can restore our previous WSL disk from the backup.
Didn't You skip the backup step? right?
All next steps need to be done on PowerShell (Windows side).
First, we need to unregister the Linux distribution
⚠️ Beware that everything that was stored on the WSL drive will be lost, and the command won't ask for a confirmation, so make sure you backup everything you need first!
# PowerShell wsl --unregister Ubuntu And then, import again on the desired path. I'll use the D: disk as an example.
# PowerShell mkdir D:\WSL wsl --import Ubuntu D:\WSL\ D:\backup\ubuntu.tar By default Ubuntu will use root as the default user, to switch to our user we need to run these commands.
# PowerShell cd $env:USERPROFILE\AppData\Local\Microsoft\WindowsApps ubuntu config --default-user equiman Ensure replacing
equimanwith yours.
Restart WSL running the command:
# PowerShell wsl --distribution Ubuntu FAQ
Answer: Once restarting the terminal, got this error message:
grep: /proc/sys/fs/binfmt_misc/WSLInterop: No such file or directory Solution: You miss running the command sudo reboot after updating Ubuntu. If this still does not work, restart WSL by running wsl --shutdown and then wsl --distribution Ubuntu
That’s All Folks!
Happy Coding 🖖





Top comments (8)
Thanks! This was helpful especially with regards to changing the upgrade prompt for LTS to non-LTS versions.
Very nice step by step guide, wow !
Bookmarked so I can upgrade my Ubuntu 20.04 soon... Thanks a million.
I've followed the steps, then at the end when I try to
sudo rebootI get the error:System has not been booted with systemd as init system (PID 1). Can't operate.Failed to connect to bus: Host is down
Failed to talk to init daemon.
Any advice?
WSL2
Previous: Ubuntu 20.04.5 LTS
Updated: Ubuntu 22.04.1 LTS
Maybe this article can help
partitionwizard.com/partitionmanag...
First, many thanks for such an useful guide.
However, when running the command
sudo apt update, my WSL session gets stuck, trying to connect to Ubuntu's severs. It shows the following message,0% [Connecting to security.ubuntu.com], and after a while it warns you abt failure to connect.
Have googled this issue and, among the alternative solutions found, nothing works.
Any advice? Thanks vm in advance,
Jose
Ubuntu version?
WSL version?
Thanks. Great guide! I get stuck after installing update-manager-core.
Trying to install a new version with sudo do-release-upgrade, I get ModuleNotFoundError: No module named 'apt_pkg'
Ubuntu version 20.04
WSL 2
Seem to be something related to Python
stackoverflow.com/questions/562185...