Skip to content

Instantly share code, notes, and snippets.

@zobayer1
Created December 8, 2022 05:28
Show Gist options
  • Select an option

  • Save zobayer1/23b6290ce68544cfc89da2b3ea283b60 to your computer and use it in GitHub Desktop.

Select an option

Save zobayer1/23b6290ce68544cfc89da2b3ea283b60 to your computer and use it in GitHub Desktop.
Cleanup your old Kernels after booting up the latest kernel
#!/usr/bin/env bash
##
## Cleanup your old Kernels after booting up the latest kernel.
## Source: https://docs.fedoraproject.org/en-US/quick-docs/dnf-system-upgrade/#sect-clean-up-old-kernels
##
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment