Skip to main content

Fedora upgrade using DNF System Upgrade plugin

  1. sudo dnf upgrade --refresh
  2. sudo dnf system-upgrade download --releasever=42
  3. If some of your packages have unsatisfied dependencies, the upgrade will refuse to continue until you run it again with an extra --allowerasing option. This often happens with packages installed from third-party repositories for which an updated repository hasn’t been yet published. Study the output very carefully and examine which packages are going to be removed. None of them should be essential for system functionality, but some of them might be important for your productivity.

    • In case of unsatisfied dependencies, you can sometimes see more details if you add --best option to the command line.

    • If you want to remove/install some packages manually before running dnf system-upgrade download again, it is advisable to perform those operations with --setopt=keepcache=1 dnf command line option. Otherwise the whole package cache will be removed after your operation, and you will need to download all the packages once again.

  4. When the new GPG key is imported, you are asked to verify the key’s fingerprint. Refer to https://fedoraproject.org/security to do so.
  5. sudo dnf system-upgrade reboot
  6. When upgrading from Fedora 41, the following is a valid command. sudo dnf5 offline reboot
  7. Optional post-upgrade tasks
    1. Update system configuration files
      1. sudo dnf install rpmconf
      2. sudo rpmconf -a
    2. Update GRUB bootloader on BIOS systems

      Systems with the BIOS firmware have the GRUB RPM packages updated. However, the installed or embedded bootloader is never updated automatically. It is a good idea to update it between Fedora Linux release versions.

      Find the device node the /boot/ directory is located on:

      sudo mount | grep "/boot "
      /dev/sda4 on /boot type ext4 (rw,relatime,seclabel)

      The device node is /dev/sda4. Reinstall the bootloader while specifying the device node without the number:

      sudo grub2-install /dev/sda

      The correct output should be:

      Installing for i386-pc platform.
      Installation finished. No error reported.
    3. Clean-up retired packages

      With every release, Fedora retires a few packages. There are various reasons; the packages become obsolete, they have a dead upstream, or the maintainer steps down. Fedora no longer distributes these packages; however, they are still on your system. These packages will not receive upgrades. It is highly recommended to remove them.

      If you upgrade across one release (e.g. Fedora Linux 41 to 42), run the following commands:

      sudo dnf install remove-retired-packages
      remove-retired-packages

      If you upgrade across two releases (e.g. Fedora Linux 40 to 42), you must supply the old release version to remove-retired-packages:

      sudo dnf install remove-retired-packages
      remove-retired-packages 40
    4. Clean-up old packages

      You can see duplicate packages (packages with multiple versions installed) with:

      sudo dnf repoquery --duplicates

      And you can remove them with:

      sudo dnf remove --duplicates

      For packages from the official repositories, the latest version should be installed. However, some packages that are still on your system may no longer be in the repositories. To see a list of these packages do:

      sudo dnf list --extras

      If you see a package you do not need, or use, you can remove it with:

      sudo dnf remove $(sudo dnf repoquery --extras --exclude=kernel,kernel-\*,kmod-\*)

      You can safely remove packages no longer in use with:

      sudo dnf autoremove
    5. Clean-up old kernels

      After you boot into the latest kernel and test the system you can remove previous kernels. Old kernels remain even after dnf autoremove to avoid unintentional removals.

      One of the easier ways to remove old kernels is with a script that retains the latest kernel. The script below works whenever Fedora updates a kernel, and does not depend upon a system upgrade.

      #!/usr/bin/env bash
      
      old_kernels=($(dnf repoquery --installonly --latest-limit=-1 -q))
      if [ "${#old_kernels[@]}" -eq 0 ]; then
          echo "No old kernels found"
          exit 0
      fi
      
      if ! dnf remove "${old_kernels[@]}"; then
          echo "Failed to remove old kernels"
          exit 1
      fi
      
      echo "Removed old kernels"
      exit 0

    6. Clean-up old keys trusted for RPM package signing

      Keys from older Fedora releases and third-party repositories will accumulate in the RPM database over time. You can remove keys no-longer referenced from /etc/yum.repos.d/ with:

      sudo dnf install clean-rpm-gpg-pubkey
      sudo clean-rpm-gpg-pubkey
    7. Clean-up old symlinks

      There may be some dangling symlinks in the filesystem after an upgrade. You can clean the dangling links by installing the symlinks utility and deleteing the old links.

      sudo dnf install symlinks

      Once the utility is installed you can audit for broken symlinks like shown below. -r means recursive.

      sudo symlinks -r /usr | grep dangling

      After you verify the list of broken symlinks you can delete them like shown below. -d means delete.

      sudo symlinks -r -d /usr
    8. Update rescue kernel

      The rescue kernel and initramfs are generated by Anaconda during system install. initramfs will be updated when the kernel is updated, but the rescue kernel may not be. Whether the rescue kernel is updated depends on the system configuration.

      If the rescue kernel is out-of-date, then issue the following commands to regenerate it.

      sudo rm /boot/*rescue*
      sudo kernel-install add "$(uname -r)" "/lib/modules/$(uname -r)/vmlinuz"

      The rescue kernel regeneration process can be automated by installing the dracut-config-rescue package.

      sudo dnf install dracut-config-rescue

      Once installed, the rescue kernel will be regenerated as long as dracut is the initrd generator. See /usr/lib/kernel/install.d/51-dracut-rescue.install for details.

https://docs.fedoraproject.org/en-US/quick-docs/upgrading-fedora-offline/#sect-clean-up-old-kernels