Introduction
DNF history is useful because it separates completed transactions from commands that failed before a transaction was committed. A rollback target must be a completed transaction, not just any failed command line.
In this lab, setup installs the small tree package and records that transaction ID. You will capture a failed package operation, inspect DNF history, review the staged install transaction, undo it, and verify that tree is no longer installed.
Inspect Recent DNF History
In this step, you will read recent package transactions before attempting any rollback.
Move into the project directory and create a workspace.
cd /home/labex/project
mkdir -p update-rollback
Save recent DNF history.
sudo dnf history list | tee update-rollback/history-before.txt
Check that tree is currently installed.
rpm -q tree | tee update-rollback/tree-query-before.txt
The latest successful transaction is the staged tree install from setup.
Capture a Failed Package Operation
In this step, you will run a package command that fails before installing anything. This gives you failure output to compare with completed history.
Try to install a package name that does not exist.
sudo dnf -y install rhce-missing-package 2>&1 | tee update-rollback/failed-install.txt || true
Read the failure.
sed -n '1,16p' update-rollback/failed-install.txt
This failed command is useful evidence, but it is not the transaction you will undo.
Review the Rollback Target
In this step, you will inspect the completed transaction that installed tree. In a real incident, you would choose this ID from dnf history list; the lab stores the staged ID so you can focus on the undo workflow.
Save the staged transaction ID.
cat /var/tmp/rhce-tree-transaction-id | tee update-rollback/transaction-id.txt
Read details for that transaction.
tid=$(cat update-rollback/transaction-id.txt)
sudo dnf history info "$tid" | sed -n '1,28p' | tee update-rollback/transaction-info.txt
The transaction details should show the tree install.
Undo the Completed Install Transaction
In this step, you will undo the completed tree install transaction. The undo command uses the transaction ID, not the failed package command.
Read the transaction ID.
tid=$(cat update-rollback/transaction-id.txt)
Undo the transaction.
sudo dnf -y history undo "$tid" | tee update-rollback/undo.txt
Save history after the undo.
sudo dnf history list | tee update-rollback/history-after.txt
DNF records the undo as a new transaction.
Verify the Rollback Result
In this step, you will confirm that the package installed by the staged transaction is no longer present.
Query the package.
rpm -q tree | tee update-rollback/tree-query-after.txt || true
Check the command path.
command -v tree || true
Read the latest history entries.
sudo dnf history list | sed -n '1,6p'
The rollback removed tree, while the failed missing-package command remained only diagnostic evidence.
Summary
You inspected DNF history, captured a failed package operation, reviewed a completed install transaction, used dnf history undo to roll it back, and verified that the package installed by that transaction was removed.



