[Bug 1990624] Re: Removing old kernel-core leaves modules.builtin.alias.bin under /lib/modules
Jeffrey Walton
1990624 at bugs.launchpad.net
Fri Sep 23 15:08:03 UTC 2022
> 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})
echo "Current kernel:"
echo " ${current_kernel} (${version_only})"
# 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
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))
if [ "${#old_kernels[@]}" -eq 0 ]; then
echo "No old kernels found"
exit 0
fi
if ! dnf -y remove "${old_kernels[@]}"; then
echo "Failed to remove old kernels"
exit 1
fi
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to systemd in Ubuntu.
https://bugs.launchpad.net/bugs/1990624
Title:
Removing old kernel-core leaves modules.builtin.alias.bin under
/lib/modules
Status in systemd package in Ubuntu:
Incomplete
Bug description:
After I remove old kernels, I see there are artifacts left over in
/lib/modules. Below, I should have only two folders - one for the
latest 5.4 kernel, and one for the latest 5.15 kernel.
$ ls /lib/modules
5.15.0-41-generic 5.15.0-46-generic 5.4.0-126-generic
5.15.0-43-generic 5.15.0-48-generic
$ ls /lib/modules/5.15.0-41-generic/
misc modules.builtin.alias.bin modules.dep.bin modules.symbols
modules.alias modules.builtin.bin modules.devname modules.symbols.bin
modules.alias.bin modules.dep modules.softdep
This appears to be a rehash of Red Hat Issue 2016630 - Removing old
kernel-core leaves modules.builtin.alias.bin under /lib/modules,
https://bugzilla.redhat.com/show_bug.cgi?id=2016630 .
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1990624/+subscriptions
More information about the foundations-bugs
mailing list