Managing CentOS System Packages with DNF: A Practical Task Guide
A step-by-step guide to safely applying CentOS system updates with DNF, including pre-flight checks, transaction verification, and rollback procedures for production environments.
20 Dec 2025, 01:32 UTC

Desired Outcome
Apply pending security and bug-fix updates to a CentOS 8 or 9 system using DNF, verify the changes, and have a recovery path if an update breaks a critical service.
Prerequisites
- Root or sudo access on the target CentOS host.
- Network connectivity to configured repositories (baseos, appstream, epel, or local mirrors).
- A recent backup or snapshot of the root filesystem (LVM snapshot, VM snapshot, or filesystem backup).
- Knowledge of which services must remain available during the maintenance window.
Check Available Updates Without Installing
Run the following command as root or with sudo to list packages that have newer versions in the enabled repositories. This operation is read-only and does not modify the system.
dnf check-updateExit codes: 0 = no updates available, 100 = updates available, 1 = error. Capture the output to a file for audit purposes:
dnf check-update > /root/pending-updates-$(date +%F).txtReview Repository Configuration
Before applying updates, confirm that /etc/yum.repos.d/ contains only the repositories you intend to use. Disable third-party repos that might pull incompatible packages:
dnf repolist enabledIf a repo should be temporarily disabled, edit its .repo file and set enabled=0, or use --disablerepo=repoid on the command line.
Apply Updates in a Controlled Transaction
Run the update command. DNF downloads all packages, resolves dependencies, and performs a single transaction. Use -y only in automated scripts; for interactive sessions, omit it to review the transaction summary.
dnf updateExpected behavior:
- Metadata refresh (if cache is older than
metadata_timer_sync, default 48h). - Dependency resolution and transaction preview.
- Package download to
/var/cache/dnf/. - RPM transaction: pre-install scripts, file installation, post-install scripts, cleanup.
If a kernel package is updated, a new boot entry is added to GRUB. The running kernel remains active until reboot.
Verify the Update Result
After the transaction completes, run these checks:
- Transaction log:
dnf history info lastshows packages installed, upgraded, or removed. - Service health: Restart or reload services that were updated (e.g.,
systemctl reload httpd,systemctl restart sshd). - Package integrity:
rpm -Vaverifies file attributes against the RPM database (may take several minutes). - Kernel version:
uname -rstill shows the old kernel until reboot;grubby --default-kernelshows the kernel that will boot next.
Recovery Options
Roll Back the Last DNF Transaction
If an update causes a regression, DNF can undo the most recent transaction using its history database:
dnf history undo lastThis reinstalls the previous package versions and runs the associated scriptlets. It requires the old packages to still be available in the repositories or in /var/cache/dnf/.
Boot the Previous Kernel
If a kernel update introduces a panic or hardware regression, select the previous kernel at the GRUB menu during boot. To make it the default without rebooting:
grubby --set-default=/boot/vmlinuz-$(rpm -q kernel --last | head -2 | tail -1 | awk '{print $1}' | sed 's/kernel-//')Restore from Snapshot
If the system is unbootable or the DNF database is corrupted, revert to the pre-update LVM/VM snapshot. This is the only reliable recovery when dnf history is unavailable.
Limitations and Caveats
- Third-party kernels or DKMS modules (e.g., NVIDIA drivers, VirtualBox kernel modules) must be rebuilt after a kernel update. DNF does not manage out-of-tree modules.
- Configuration file merges: RPM marks modified config files as
.rpmnewor.rpmsave. Review them manually; DNF does not auto-merge. - Excluded packages: Packages listed in
exclude=in/etc/dnf/dnf.confor repo files will not be updated. Verify exclusions are intentional. - Modular streams: On CentOS 8/9, AppStream modules (e.g., nodejs, postgresql) follow stream lifecycles. Switching streams requires
dnf module resetanddnf module install, not a plaindnf update.
Automation Considerations
For unattended updates via dnf-automatic or a cron job:
- Set
apply_updates = yesin/etc/dnf/automatic.conf. - Restrict to security updates only with
upgrade_type = security. - Configure
emit_via = stdiooremailto capture output. - Test the automation on a staging host before enabling on production.
Quick Verification Checklist
| Check | Command | Pass Criteria |
|---|---|---|
| No broken dependencies | dnf check | Exit code 0, no output |
| Critical services running | systemctl is-active sshd httpd postgresql | All report "active" |
| No .rpmnew files unreviewed | find /etc -name '*.rpmnew' | Empty or each file reviewed |
| History record exists | dnf history list | head -5 | Latest entry shows today's transaction |
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.