How can I dnf upgrade without necessitating restart?

In the “Software” GUI I can upgrade just the flatpaks, and it’s nice that they don’t require restart, but I’d like to also upgrade the RPMs that don’t require restarting. Software does not seem to distinguish between them.

I thought at some point in the past I had done something like dnf upgrade –no-restart although that’s obviously not it. Maybe I had written a script to filter packages to upgrade somehow. Is there a built-in option or a custom script anyone is using to do this? Thanks!

In most cases a restart is not necessary. If there are driver updates or firmware updates a restart may be necessary. If a kernel upgrade occurs then a restart is also strongly encouraged though it may not be 100% necessary. (of course, in order to use the new kernel the restart is required)

You should, though, consider closing and restarting apps and/or log out and back in even if a restart is not required since it is possible that the app in use may be affected by changes with updated software.

I have gone weeks at times without a restart or log out even when performing updates frequently.

When using dnf for the upgrade it is easy to see exactly what packages are being upgraded and choose to restart or not. The gui software manager hides those details.

For me I use dnf and flatpak to perform updates and may have used the gui software app as much as once or twice in the last 3 years.

If you use the command line to do updates, a restart won’t be triggered until you manually request one. Personally speaking, I only restart if KDE or the kernel is updated.

1 Like

After you have used dnf upgrade this command will report what needs restarting.

dnf needs-restarting --services --reboothint
2 Likes

I did a sudo dnf update that updated a bunch of stuff including the kernel and tried that command, which sounds very useful, but got this error:

sudo dnf needs-restarting --services --reboothint
Updating and loading repositories:
Repositories loaded.
[System.Error.ENOMEDIUM] Failed to open bus (No medium found)

I have not seen that error. not sure what would trigger it except d-bus.
Is d-bus running?

If I login as ssh root@host then the command works (which is how my automation works).

If I sudo dnf then the command fails.
If I run0 dnf the comman fails.
However sudo systemctl status httpd works (I assume uses d-bus).

But dnf needs-restarting --services --reboothint as my user does work

I raised 2419668 – sudo dnf needs-restarting --services fails with [System.Error.ENOMEDIUM] Failed to open bus (No medium found) for dnf developers to consider the issue.

1 Like

I have made this bash script to update flatpaks (if flatpak is installed), update dnf packages, check if reboot is recommended, check for (but don’t update) firmware updates, and finally list any background jobs running after the update (nice for NVIDIA kmods):

#!/usr/bin/env bash
set -e

if command -v flatpak > /dev/null 2>&1; then
    echo "🔷🔷 === Updating Flatpaks ==="
    flatpak update
fi

echo "🔷🔷 === Updating DNF packages ==="
sudo dnf update --refresh

echo "🔷🔷 === Checking if reboot is recommended ==="
if ! sudo dnf needs-restarting; then
    echo "⚠ Reboot recommended!"
fi

echo "🔷🔷 === Checking for firmware updates (no installation) ==="
if fwupdmgr get-updates; then
    echo "✅ Firmware check completed."
else
    rc=$?
    if [ $rc -eq 2 ]; then
        echo "✅ No firmware updates available."
    else
        echo "⚠ Firmware check failed with exit code $rc"
        echo "   Manual intervention needed, check output!"
    fi
fi

echo "🔷🔷 === Checking background jobs after update ==="
systemctl list-jobs
echo "🔷🔷 === All checks complete ==="

I have it in my ~/.local/bin as fedupdate.sh - very convenient :slight_smile:

/Jaybe

2 Likes

I don’t know how to tell if d-bus is running. It’s fairly stock Workstation install.

I tried it on another Fedora WS install and I didn’t see the Failed to open bus error. However, even though there were a lot of updates including the kernel, it didn’t tell me anything.

Then I tried this and it still thinks I don’t need to reboot:

sudo dnf needs-restarting
Updating and loading repositories:
Repositories loaded.
No core libraries or services have been updated since boot-up.
Reboot should not be necessary.

I really appreciate everyone chiming in. I still wish dnf would provide some kind of best-effort no-restart option to automatically exclude upgrading packages for which upgrading would require significant downtime, like the kernel, and kmods.

I do appreciate the insight, @computersavvy that I probably don’t necessarily need to restart, even when upgrading the kernel, and the new kernel will simply wait until next boot. So I’ll try out just not worrying about it.

I usually upgrade in the morning and shutdown or reboot at the end of the day, so maybe being roughly 8-16 hours behind is acceptable. :laughing:

1 Like

My approach is to not do the update until I am willing to do a reboot.
Of course if you know that there is a fix that is important to you then you would do any necessary reboot.

1 Like

personally i never restart at all since i do on command line, I just do it when i shut them down. But im not sure its a good practice or not since i usually dont want to be bothered by restart. So far no issues with my lazy approach

Possibly a change in schedule would solve the concern. Is it possible to do the upgrade just before shutting down instead of when first starting up.?