> Are you invoking kernel-install to remove kernels? Or what action did you perform exactly?
Good question, Nick.
I am not using kernel-install. Instead, I use a command like:
# For the case of 5.15.0-41-generic kernel
$ sudo apt-get remove --purge '*5.15.0-41*'
In fact, I ran the command manually when I noticed the accumulation of old kernel parts in /lib/modules. Apt said there was nothing to do.
I knew about the 2016630 bug from Red Hat because I first experienced the issue on Fedora 35. Now I am seeing it on Ubuntu, too.
----------
Here is the actual script I am running. It looks at the current kernel, and makes a list of all kernels. It removes the current kernel from the list of all kernels, and then removes all the old kernels.
# Get a list mostly removed kernels. The kernel and package have been
# removed, but the configuration files and directory remains.
old_kernels=($(dpkg -l | grep linux-image | grep '^rc' | tr -s " " | \
cut -f 2 -d ' ' | sort | uniq))
if [ "${#old_kernels[@]}" -ne 0 ]; then
apt-get remove -y --purge "${old_kernels[@]}" 1>/dev/null
fi
# Get the current kernel
current_kernel=$(uname -r)
version_only=$(get_version ${current_kernel})
# Get a list of installed kernels. The `grep -v` removes the
# current kernel from the list, which should be the latest kernel.
old_kernels=($(dpkg -l | grep linux-image | grep '^ii' | tr -s " " | \
cut -f 2 -d ' ' | sort -V | uniq | grep -v "${current_kernel}"))
temp_list=()
for k in "${old_kernels[@]}"
do
# Skip the metapackage linux-image-generic
if [[ "${k}" == linux-image-generic* ]]; then continue
fi temp_list+=("${k}")
done
# Swap-in the new list
old_kernels=("${temp_list[@]}")
if [ "${#old_kernels[@]}" -eq 0 ]; then
echo "No old kernels found"
exit 0
fi
echo "Old kernels to remove:"
for k in "${old_kernels[@]}"
do version_only=$(get_version ${k})
echo " ${k} (${version_only})"
done
for k in "${old_kernels[@]}"
do version_only=$(get_version ${k})
if ! apt-get remove -y --purge "*${version_only}*"; then
echo "Failed to remove ${k}" some_error=1
fi
> Are you invoking kernel-install to remove kernels? Or what action did you perform exactly?
Good question, Nick.
I am not using kernel-install. Instead, I use a command like:
# For the case of 5.15.0-41-generic kernel
$ sudo apt-get remove --purge '*5.15.0-41*'
In fact, I ran the command manually when I noticed the accumulation of old kernel parts in /lib/modules. Apt said there was nothing to do.
I knew about the 2016630 bug from Red Hat because I first experienced the issue on Fedora 35. Now I am seeing it on Ubuntu, too.
----------
Here is the actual script I am running. It looks at the current kernel, and makes a list of all kernels. It removes the current kernel from the list of all kernels, and then removes all the old kernels.
# Get a list mostly removed kernels. The kernel and package have been kernels= ($(dpkg -l | grep linux-image | grep '^rc' | tr -s " " | \
# removed, but the configuration files and directory remains.
old_
cut -f 2 -d ' ' | sort | uniq))
if [ "${#old_ kernels[ @]}" -ne 0 ]; then
apt-get remove -y --purge "${old_kernels[@]}" 1>/dev/null
fi
# Get the current kernel kernel= $(uname -r) only=$( get_version ${current_kernel})
current_
version_
echo "Current kernel:"
echo " ${current_kernel} (${version_only})"
# Get a list of installed kernels. The `grep -v` removes the kernels= ($(dpkg -l | grep linux-image | grep '^ii' | tr -s " " | \ kernel} "))
# current kernel from the list, which should be the latest kernel.
old_
cut -f 2 -d ' ' | sort -V | uniq | grep -v "${current_
temp_list=() generic* ]]; then
continue
temp_list+ =("${k} ")
for k in "${old_kernels[@]}"
do
# Skip the metapackage linux-image-generic
if [[ "${k}" == linux-image-
fi
done
# Swap-in the new list kernels= ("${temp_ list[@] }")
old_
if [ "${#old_ kernels[ @]}" -eq 0 ]; then
echo "No old kernels found"
exit 0
fi
echo "Old kernels to remove:"
version_ only=$( get_version ${k})
for k in "${old_kernels[@]}"
do
echo " ${k} (${version_only})"
done
for k in "${old_kernels[@]}"
version_ only=$( get_version ${k}) only}*" ; then
some_ error=1
do
if ! apt-get remove -y --purge "*${version_
echo "Failed to remove ${k}"
fi
done
apt-get install -y --reinstall linux-image-generic linux-headers- generic
Fedora is a lot easier to remove old kernels. On Fedora I use:
old_ kernels= ($(dnf repoquery --installonly --latest-limit=-1 -q)) kernels[ @]}" -eq 0 ]; then
if [ "${#old_
echo "No old kernels found"
exit 0
fi
if ! dnf -y remove "${old_ kernels[ @]}"; then
echo "Failed to remove old kernels"
exit 1
fi