Kernel bloat

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
davo4prog

Kernel bloat

Post by davo4prog »

I used to have an 8 gig partition for root (an another larger for home). This was adequate for the past 20 odd years. I increased that to 15 gig a year or so ago and it has been running out of space. The constant updating of Kernels is what is doing it. So apart from cleaning our /var/cache/apt/archives from time to time I started deleting old versions of vmlinuz in /boot. Recently I ran a check for large files and found /lib/modules was big, deleting old versions here cleared up 4 gig. Point of this post is that the frequent release of kernel versions, virtually every time I do an update, is bloating the system because they don't get deleted.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Moem
Level 22
Level 22
Posts: 16230
Joined: Tue Nov 17, 2015 9:14 am
Location: The Netherlands
Contact:

Re: Kernel bloat

Post by Moem »

So delete them. It's a normal part of OS maintenance and can be done through the Update Manager.
We're getting a lot more kernel updates recently because of the patches needed to help protect us from Spectre and Meltdown, so it's for a good cause.

Is there anything you wanted to ask with regards to this?

Mod note: moving this post because it's not about software or applications.
Image

If your issue is solved, kindly indicate that by editing the first post in the topic, and adding [SOLVED] to the title. Thanks!
User avatar
kc1di
Level 18
Level 18
Posts: 8175
Joined: Mon Sep 08, 2008 8:44 pm
Location: Maine USA

Re: Kernel bloat

Post by kc1di »

Kernels become bloated because users keep asking for it to do more and more. - you can keep your disc usage in check by removing unused kernels. I usually make it a habit of keep one older kernel and the one I'm currently using. Just in case I need to go back because of hardware or such. But once I'm satisfied that the new kernel is working properly I may even delete that older one.
Easy tips : https://easylinuxtipsproject.blogspot.com/ Pjotr's Great Linux projects page.
Linux Mint Installation Guide: http://linuxmint-installation-guide.rea ... en/latest/
Registered Linux User #462608
Cosmo.
Level 24
Level 24
Posts: 22968
Joined: Sat Dec 06, 2014 7:34 am

Re: Kernel bloat

Post by Cosmo. »

There is indeed a problem with the amount of kernels, which can fill a drive after some time. Newbie users do not necessarily know, that in difference to all other packages, where an updated package replaces the previous one, new kernels get added to the system. If there should be a way to make it easier to remove not needed kernels, is an open questions, which starts with the question, which kernels are really not needed for an easy way to revert in case of problems. But as the update manager is permanently adding new kernels it should have an option to display a message, if a certain number of installed kernels (possibly configurable in the preferences) have been reached. This could e. g. be done with a colored bar at the top of the update manager, similar to the bar which advises to switch to a mirror.
User avatar
Pjotr
Level 24
Level 24
Posts: 20092
Joined: Mon Mar 07, 2011 10:18 am
Location: The Netherlands (Holland) 🇳🇱
Contact:

Re: Kernel bloat

Post by Pjotr »

Restore normality with this kernel cleaning method:
https://sites.google.com/site/easylinux ... one-stroke
(item 8.1, right column)

As I've already tried to communicate to the devs: this is a feature that should be built into Update Manager, imo.....
Tip: 10 things to do after installing Linux Mint 21.3 Virginia
Keep your Linux Mint healthy: Avoid these 10 fatal mistakes
Twitter: twitter.com/easylinuxtips
All in all, horse sense simply makes sense.
davo4prog

Re: Kernel bloat

Post by davo4prog »

Thanks for the help. Much better than manually deleting them.
User avatar
majpooper
Level 8
Level 8
Posts: 2085
Joined: Thu May 09, 2013 1:56 pm
Location: North Carolina, USA

Re: Kernel bloat

Post by majpooper »

As a rule of thumb I always keep one or two prior kernels - just in case. However every time I download a new kernel and do a restart I then remove the oldest kernel via the update manager. I have yet to have to go back to a prior kernel - but one never knows . . . Anyway this keeps the number of kernels to a manageable level.
davo4prog

Re: Kernel bloat

Post by davo4prog »

Discussing this in https://www.linuxquestions.org/question ... ost5829000


Originally Posted by chrism01
ok - also in /etc/yum.conf we have
Code:

Code: Select all

installonly_limit=3
which automatically limits installed kernels to last ie newest 3.
It auto purges oldest when you install a '4th', so you never actually need to run yum manually to reduce kernels :)
Hi Thanks,

Mint does not use YUM, in looking in /etc I did find a generated file /etc/apt/apt.conf.d/01autoremove-kernels which is created by
/etc/kernel/postinst.d/apt-auto-removal
There was mention on #lines about keeping 4 kernels, but this hasn't been my experience, My linux progaming skills extend to simple scripts, however I will pass this over to Mint Forums. Thanks indeed, the answer is there somewhere.
Last edited by Moem on Fri Mar 09, 2018 8:34 am, edited 1 time in total.
Reason: Some improvements in formatting.
User avatar
kc1di
Level 18
Level 18
Posts: 8175
Joined: Mon Sep 08, 2008 8:44 pm
Location: Maine USA

Re: Kernel bloat

Post by kc1di »

This ubuntu wiki page (Though quite old now) addresses the problems involved in auto removal of kernels. And it's the same rational used by Mint, I don't believe this has changed over the years.
https://wiki.ubuntu.com/KernelTeam/removing-old-kernels
Easy tips : https://easylinuxtipsproject.blogspot.com/ Pjotr's Great Linux projects page.
Linux Mint Installation Guide: http://linuxmint-installation-guide.rea ... en/latest/
Registered Linux User #462608
davo4prog

Re: Kernel bloat

Post by davo4prog »

This is /etc/apt/apt.conf.d/01autoremove-kernels

Code: Select all

// DO NOT EDIT! File autogenerated by /etc/kernel/postinst.d/apt-auto-removal
APT::NeverAutoRemove
{
   "^linux-image-4\.10\.0-38-generic$";
   "^linux-image-4\.13\.0-36-generic$";
   "^linux-headers-4\.10\.0-38-generic$";
   "^linux-headers-4\.13\.0-36-generic$";
   "^linux-image-extra-4\.10\.0-38-generic$";
   "^linux-image-extra-4\.13\.0-36-generic$";
   "^linux-signed-image-4\.10\.0-38-generic$";
   "^linux-signed-image-4\.13\.0-36-generic$";
   "^kfreebsd-image-4\.10\.0-38-generic$";
   "^kfreebsd-image-4\.13\.0-36-generic$";
   "^kfreebsd-headers-4\.10\.0-38-generic$";
   "^kfreebsd-headers-4\.13\.0-36-generic$";
   "^gnumach-image-4\.10\.0-38-generic$";
   "^gnumach-image-4\.13\.0-36-generic$";
   "^.*-modules-4\.10\.0-38-generic$";
   "^.*-modules-4\.13\.0-36-generic$";
   "^.*-kernel-4\.10\.0-38-generic$";
   "^.*-kernel-4\.13\.0-36-generic$";
   "^linux-backports-modules-.*-4\.10\.0-38-generic$";
   "^linux-backports-modules-.*-4\.13\.0-36-generic$";
   "^linux-tools-4\.10\.0-38-generic$";
   "^linux-tools-4\.13\.0-36-generic$";
};
/* Debug information:
# dpkg list:
ii  linux-image-4.10.0-38-generic               4.10.0-38.42~16.04.1                         amd64        Linux kernel image for version 4.10.0 on 64 bit x86 SMP
ii  linux-image-4.13.0-36-generic               4.13.0-36.40~16.04.1                         amd64        Linux kernel image for version 4.13.0 on 64 bit x86 SMP
ii  linux-image-extra-4.10.0-38-generic         4.10.0-38.42~16.04.1                         amd64        Linux kernel extra modules for version 4.10.0 on 64 bit x86 SMP
iF  linux-image-extra-4.13.0-36-generic         4.13.0-36.40~16.04.1                         amd64        Linux kernel extra modules for version 4.13.0 on 64 bit x86 SMP
# list of installed kernel packages:
4.10.0-38-generic 4.10.0-38.42~16.04.1
4.13.0-36-generic 4.13.0-36.40~16.04.1
# list of different kernel versions:
4.13.0-36.40~16.04.1
4.10.0-38.42~16.04.1
# Installing kernel: 4.13.0-36.40~16.04.1 (4.13.0-36-generic)
# Running kernel: 4.10.0-38.42~16.04.1 (4.10.0-38-generic)
# Last kernel: 4.13.0-36.40~16.04.1
# Previous kernel: 4.10.0-38.42~16.04.1
# Kernel versions list to keep:
4.10.0-38.42~16.04.1
This is /etc/kernel/postinst.d/apt-auto-removal

Code: Select all

#!/bin/sh
set -e
# Mark as not-for-autoremoval those kernel packages that are:
#  - the currently booted version
#  - the kernel version we've been called for
#  - the latest kernel version (as determined by debian version number)
#  - the second-latest kernel version
#
# In the common case this results in two kernels saved (booted into the
# second-latest kernel, we install the latest kernel in an upgrade), but
# can save up to four. Kernel refers here to a distinct release, which can
# potentially be installed in multiple flavours counting as one kernel.

eval $(apt-config shell APT_CONF_D Dir::Etc::parts/d)
test -n "${APT_CONF_D}" || APT_CONF_D="/etc/apt/apt.conf.d"
config_file="${APT_CONF_D}/01autoremove-kernels"

eval $(apt-config shell DPKG Dir::bin::dpkg/f)
test -n "$DPKG" || DPKG="/usr/bin/dpkg"

list="$("${DPKG}" -l | awk '/^[ih][^nc][ ]+(linux|kfreebsd|gnumach)-image-[0-9]+\./ && $2 !~ /-dbg(:.*)?$/ && $2 !~ /-dbgsym(:.*)?$/ { print $2,$3; }' \
   | sed -e 's#^\(linux\|kfreebsd\|gnumach\)-image-##' -e 's#:[^:]\+ # #')"
debverlist="$(echo "$list" | cut -d' ' -f 2 | sort --unique --reverse --version-sort)"

if [ -n "$1" ]; then
	installed_version="$(echo "$list" | awk "\$1 == \"$1\" { print \$2;exit; }")"
fi
unamer="$(uname -r)"
if [ -n "$unamer" ]; then
	running_version="$(echo "$list" | awk "\$1 == \"$unamer\" { print \$2;exit; }")"
fi
latest_version="$(echo "$debverlist" | sed -n 1p)"
previous_version="$(echo "$debverlist" | sed -n 2p)"

debkernels="$(echo "$latest_version
$installed_version
$running_version
$previous_version" | sort -u | sed -e '/^$/ d')"
kernels="$( (echo "$1
$unamer"; for deb in $debkernels; do echo "$list" | awk "\$2 == \"$deb\" { print \$1; }"; done; ) \
   | sed -e 's#\([\.\+]\)#\\\1#g' -e '/^$/ d' | sort -u)"

generateconfig() {
	cat <<EOF
// DO NOT EDIT! File autogenerated by $0
APT::NeverAutoRemove
{
EOF
	for package in $(apt-config dump --no-empty --format '%v%n' 'APT::VersionedKernelPackages'); do
		for kernel in $kernels; do
			echo "   \"^${package}-${kernel}$\";"
		done
	done
	echo '};'
	if [ "${APT_AUTO_REMOVAL_KERNELS_DEBUG:-true}" = 'true' ]; then
		cat <<EOF
/* Debug information:
# dpkg list:
$(dpkg -l | grep '\(linux\|kfreebsd\|gnumach\)-image-')
# list of installed kernel packages:
$list
# list of different kernel versions:
$debverlist
# Installing kernel: $installed_version ($1)
# Running kernel: $running_version ($unamer)
# Last kernel: $latest_version
# Previous kernel: $previous_version
# Kernel versions list to keep:
$debkernels
# Kernel packages (version part) to protect:
$kernels
*/
EOF
	fi
}
generateconfig "$@" > "${config_file}.dpkg-new"
mv -f "${config_file}.dpkg-new" "$config_file"
chmod 444 "$config_file"
Last edited by Moem on Sat Mar 10, 2018 7:27 am, edited 1 time in total.
Reason: Please use the code tags for long code and terminal outputs.
Locked

Return to “Other topics”