How to Upgrade to Fedora 37 In Place on Windows Subsystem for Linux (WSL)
Tags: linux, fedora, wsl, tutorial
Published: 2021-04-18 21:42:29

The time has once again arrived to upgrade Fedora. As [detailed in another article][fedora-wsl], I installed Fedora on WSL 2. Now I want to upgrade to Fedora version 37. I could do a clean install of course, using the steps detailed in that article, but I want to upgrade in place.

How do we do that?

Here are the steps I use, based on [official Fedora instructions][fedora-upgrade].

## Backup first

Just in case, yes?

First, clean up downloaded packages, etc. within Fedora:

```console
sudo dnf clean all
```

Then, exit WSL and export the whole installation to a tarball (this assumes your distro name is "fedora"):

```Powershell
wsl --export fedora $HOME\Downloads\fedora-wsl.tar
```

You may want a different folder than `Downloads`; specify the location you desire.

Depending on what packages you installed, it may be as small as a quarter GB, or it could be far larger. You could gzip it if you want the storage size to be even smaller. Next time you want to start fresh, you can do something like this:

```Powershell
mkdir $HOME\wsl\freshfedora
wsl --import freshfedora $HOME\wsl\freshfedora $HOME\Downloads\fedora-wsl.tar
```

## Begin the upgrade: freshen up

It is important to have a refreshed package index, and upgrade all packages to the latest. You can do so with

```console
sudo dnf upgrade --refresh
```

## Install the upgrade system

We will need [DNF System Upgrade][fedora-upgrade] in order to make the leap, so let's install it now.

```console
sudo dnf install dnf-plugin-system-upgrade
```

## Download new release packages

To prepare and download for a system upgrade to Fedora 37, the following should do the trick:

```console
sudo dnf system-upgrade download --releasever=37
```

This will take a bit of time.

Yes, you should feel fine about importing the new GPG for Fedora 37, so you can answer "y" to that.

## Reboot?

If using WSL, this is where it gets a little strange, but only a little.

I first set a flag to indicate reboots are not necessary.

```console
export DNF_SYSTEM_UPGRADE_NO_REBOOT=1
```

Not sure how necessary that is, but it doesn't hurt. We can restart WSL ourselves, if we need to, but I have not found that to be required. If you are doing this on a full Fedora system (not WSL), please do not set this flag; you need to do an actual reboot.

Now we trigger the update, strangely, with the upgrade and reboot command (pass the `-E` flag to `sudo` in order to utilize the `DNF_SYSTEM_UPGRADE_NO_REBOOT` variable defined earlier):

```console
sudo -E dnf system-upgrade reboot
```

You should see `Reboot turned off, not rebooting.`

## Moment of truth: launch the upgrade

Now trigger the actual upgrade with

```console
sudo -E dnf system-upgrade upgrade
```

## Finalization

You should now have a fresh Fedora 37 system.

In case you upgraded from Fedora 32 or earlier, the RPM database backend has changed somewhat. Refresh it with

```console
sudo rpmdb --rebuilddb
```

Again, this should not be necessary unless you were on a much earlier version of Fedora.

Then refresh and upgrade all the packages.

```console
sudo dnf upgrade --refresh
```

Just to be as clean as possible (you may still have processes running that are actually older versions than installed), why not restart your WSL distro. Open a Powershell window, and terminate your WSL instance. Assuming your instance is named "fedora" you can `wsl -t fedora`.

Then, relaunch with `wsl -d fedora`

## Reference: all the steps in one place

For your reference, here are all the steps in one block:

```console
sudo dnf upgrade --refresh
sudo dnf install dnf-plugin-system-upgrade
sudo dnf system-upgrade download --releasever=37
export DNF_SYSTEM_UPGRADE_NO_REBOOT=1
sudo -E dnf system-upgrade reboot
sudo -E dnf system-upgrade upgrade
sudo dnf upgrade --refresh
```

Enjoy your shiny new Fedora!

## Keep upgrading

If you chose to upgrade to a beta or prerelease, there should be no need to reinstall. [Just keep upgrading](https://fedoraproject.org/wiki/Upgrading_from_pre-release_to_final#Performing_the_upgrade), as often as you like; the process is pretty seamless:

```console
sudo dnf upgrade
```

If you daringly chose to use Fedora 37, for instance, upgrade as often as you like with the above command, and you will eventually (by the end of October 2022) be at release.

[fedora-wsl]: https://dev.to/bowmanjd/install-fedora-on-windows-subsystem-for-linux-wsl-4b26
[fedora-upgrade]: https://docs.fedoraproject.org/en-US/quick-docs/dnf-system-upgrade/