Last active
October 10, 2020 02:17
-
-
Save CaledoniaProject/243e00fa6ce5866efe39287cf94f1d3c to your computer and use it in GitHub Desktop.
Remove expired kernel in Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
installed=( $(dpkg-query -W --showformat='${Package}\n' | grep -oP '^linux-image-\K\d.*' | sort -r) ) | |
running=$(uname -r) | |
echo Installed versions: ${installed[@]} | |
if [[ ${#installed[@]} -le 1 ]]; then | |
echo Nothing to do | |
exit | |
fi | |
if [[ ${installed[0]} != $running ]]; then | |
echo Must reboot system to load ${installed[0]} | |
echo Current version $running | |
exit | |
fi | |
packages= | |
for version in ${installed[@]} | |
do | |
if [[ $version == ${installed[0]} ]]; then | |
continue | |
fi | |
packages="linux-headers-${version} linux-image-${version} linux-modules-${version} linux-modules-extra-${version} $packages" | |
done | |
echo Packages to uninstall: $packages | |
apt autoremove --purge $packages |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment