How to upgrade Fedora to latest version on wsl2
How to upgrade fedora on wsl
Last week, Fedora 39 was released, and it is now time to upgrade Fedora container installed on wsl to Fedora 39. Fedora has an excellent article about Upgrading Fedora Using the DNF System Plugin for both desktop and server versions, which I used as a guide in this blog post.
Here are the steps to follow:
- Backup your system.
- update all installed packages
- install DNF System Plugin
- Use DNF System Plugin to:
- download the latest Fedora version
- upgrade the system and reboot
Update the system
Before upgrading or taking a backup, we need to remove unneccessary files and update all the packages:
wsl -d <distrobution-name>
sudo dnf upgrade --refresh
sudo dnf clean all
exit
Back up your system
To make a backup from your Fedora on wsl, you can use the “wsl” command:
wsl --export <distrobution-name> <path-to-backup-directory> <distrobution-backup-name>
Installing and using DNF System Plugin
Start your fedora instance on WSL to install and use dnf system plugin:
wsl -d <distrobution-name>
sudo dnf install dnf-plugin-system-upgrade
sudo dnf system-upgrade download --releasever=39
You can change "--releasever=39" with any future release. There is no need to specify "Fedora container" as Dnf system-upgrade downloads the correct version of fedora which matches your installed instance.
The last command for upgrading is “sudo dnf system-upgrade reboot”. But this will raise an error like image below. The reason is Fedora on wsl is a container image and there is no “systemctl” available thus “reboot” is not possible.
To fix the problem “No such file or directory: ‘systemctl’”, we need to tell the system to not reboot after the upgrade. For this we can simply add an environment variable like this:
export UPGRADE_WITHOUT_REBOOT=1
and then continue with upgrade:
sudo dnf system-upgrade reboot
sudo dnf system-upgrade upgrade
When the upgrade is complete, you may see the same error again “[Errno 2] No such file or directory: ‘systemctl’“. The upgrade is complete and before rebooting manually, you can check the os version:
cat /etc/os-release
To reboot the fedora, simply use “wsl” command to terminate and start the distribution agian:
exit
wsl -t <distribution-name>
wsl -d <distribution-name>