3

According to the Ubuntu help wiki:

You can remove old kernels with a simple autoremove command in a terminal:

sudo apt-get autoremove --purge

For some reason, this doesn't work for me, and the kernels are piling up:

 apt list --installed | rg linux-image

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

linux-image-5.4.0-31-generic/focal-updates,focal-security,now 5.4.0-31.35 amd64 [installed]
linux-image-5.4.0-40-generic/focal-updates,focal-security,now 5.4.0-40.44 amd64 [installed]
linux-image-5.4.0-42-generic/focal-updates,focal-security,now 5.4.0-42.46 amd64 [installed]
linux-image-5.4.0-45-generic/focal-updates,focal-security,now 5.4.0-45.49 amd64 [installed]
linux-image-5.4.0-47-generic/focal-updates,focal-security,now 5.4.0-47.51 amd64 [installed]
linux-image-5.4.0-48-generic/focal-updates,focal-security,now 5.4.0-48.52 amd64 [installed]
linux-image-5.4.0-52-generic/focal-updates,focal-security,now 5.4.0-52.57 amd64 [installed]
linux-image-5.4.0-54-generic/focal-updates,now 5.4.0-54.60 amd64 [installed]
linux-image-5.4.0-56-generic/now 5.4.0-56.62 amd64 [installed,local]
linux-image-5.4.0-58-generic/focal-updates,focal-security,now 5.4.0-58.64 amd64 [installed]
linux-image-5.4.0-60-generic/focal-updates,focal-security,now 5.4.0-60.67 amd64 [installed]
linux-image-5.4.0-62-generic/focal-updates,focal-security,now 5.4.0-62.70 amd64 [installed]
linux-image-5.4.0-64-generic/focal-updates,now 5.4.0-64.72 amd64 [installed]
linux-image-5.4.0-65-generic/focal-updates,focal-security,now 5.4.0-65.73 amd64 [installed]
linux-image-5.4.0-66-generic/focal-updates,focal-security,now 5.4.0-66.74 amd64 [installed,automatic]
linux-image-generic/now 5.4.0.66.69 amd64 [installed,upgradable to: 5.4.0.67.70]

I'm running Kubuntu 20.04.2 on a freshly built machine, and I've only been using it for a few months after many years with Macs, so I've never consciously tried to adjust anything about the kernel.

I disabled unattended-upgrades via the Discover store, because silent Nvidia updates were causing the display to freeze. I do, however, run sudo apt-get autoremove after every update.

I looked for answers before posting, and found that most were many years old, though an answer to this previous question caused me to check my /etc/apt/apt.conf.d/01autoremove-kernels file, and it seems to correctly focus on only the two latest kernels:

// DO NOT EDIT! File autogenerated by /etc/kernel/postinst.d/apt-auto-removal
APT::NeverAutoRemove
{
   "^linux-.*-5\.4\.0-65-generic$";
   "^linux-.*-5\.4\.0-66-generic$";
   "^kfreebsd-.*-5\.4\.0-65-generic$";
   "^kfreebsd-.*-5\.4\.0-66-generic$";
   "^gnumach-.*-5\.4\.0-65-generic$";
   "^gnumach-.*-5\.4\.0-66-generic$";
   "^.*-modules-5\.4\.0-65-generic$";
   "^.*-modules-5\.4\.0-66-generic$";
   "^.*-kernel-5\.4\.0-65-generic$";
   "^.*-kernel-5\.4\.0-66-generic$";
};

So, I'm super confused, and looking for a way to clean up the system without breaking anything, then limit the number of retained kernels to 2-3.

Thank you for reading, I would appreciate any help you can offer!

EDIT: Per the request from @user535733 here is some additional output:

sudo apt update
Hit:1 http://us.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease                                                                                              
Hit:3 http://security.ubuntu.com/ubuntu focal-security InRelease                                                                      
Hit:4 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease                                                                   
Ign:5 https://apt.fury.io/flirc  InRelease                                                
Hit:6 http://ppa.launchpad.net/appimagelauncher-team/stable/ubuntu focal InRelease
Hit:7 http://download.opensuse.org/repositories/home:/ungoogled_chromium/Ubuntu_Focal  InRelease
Ign:8 https://apt.fury.io/flirc  Release                                                       
Ign:9 https://apt.fury.io/flirc  Packages                                
Ign:10 https://apt.fury.io/flirc  Translation-en                         
Hit:11 http://ppa.launchpad.net/jonaski/strawberry/ubuntu focal InRelease
Ign:12 https://apt.fury.io/flirc  Translation-en_US                      
Get:9 https://apt.fury.io/flirc  Packages                                
Ign:10 https://apt.fury.io/flirc  Translation-en                         
Hit:13 http://ppa.launchpad.net/micahflee/ppa/ubuntu focal InRelease
Ign:12 https://apt.fury.io/flirc  Translation-en_US                      
Ign:10 https://apt.fury.io/flirc  Translation-en                         
Ign:12 https://apt.fury.io/flirc  Translation-en_US                      
Hit:14 http://ppa.launchpad.net/mkusb/ppa/ubuntu focal InRelease
Ign:10 https://apt.fury.io/flirc  Translation-en
Ign:12 https://apt.fury.io/flirc  Translation-en_US
Ign:10 https://apt.fury.io/flirc  Translation-en
Ign:12 https://apt.fury.io/flirc  Translation-en_US
Ign:10 https://apt.fury.io/flirc  Translation-en
Ign:12 https://apt.fury.io/flirc  Translation-en_US
Ign:10 https://apt.fury.io/flirc  Translation-en
Ign:12 https://apt.fury.io/flirc  Translation-en_US
Fetched 6,518 B in 2s (3,153 B/s)
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.

sudo apt upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

sudo apt autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

uname -r
5.4.0-67-generic

EDIT 2: After updating to include the additional output, another kernel was added (linux-image-5.4.0-67-generic). I noticed that both linux-image-5.4.0-66-generic and linux-image-5.4.0-67-generic are marked as automatic, while all previous versions are marked manual. Based on that timing, I'm guessing that updating via the 'update all' button in the Discover store has somehow been causing kernels to be marked as manually installed (along with headers and modules). It looks like the only two installed via cli are correctly marked as automatically installed (but haven't been subject to autoremove because they are the two newest versions).

I guess the answer is to use apt-mark auto on the versions that were installed via the Discover store, and stick with cli from here, thank you to everyone who helped!

6

1 Answer 1

7

So, @nobody suggested using apt-mark showmanual, which was new to me.

Since this is my first time with linux, I had been using Kubuntu's Discover Store to update everything for the first few months.

It looks like all the kernels installed via the 'update all' button in Kubuntu's Discover store, along with the related modules and headers, were being marked as manually installed.

Fortunately, command line updates are correctly marking new kernels, headers, and modules as automatically installed.

Using a list of the mis-marked packages from apt-mark showmanual | grep linux-, I was able to easily correct the status of all 65 packages with sudo apt-mark auto $(cat path/to/listofpackages.txt), thanks to the suggestion posted here.

Now sudo apt-get autoremove is detecting these packages, and I will be sure to stick with cli updates from now on! Thanks again to everyone who helped!

sudo apt-get autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  linux-headers-5.4.0-40 linux-headers-5.4.0-40-generic linux-headers-5.4.0-42 linux-headers-5.4.0-42-generic linux-headers-5.4.0-45
  linux-headers-5.4.0-45-generic linux-headers-5.4.0-47 linux-headers-5.4.0-47-generic linux-headers-5.4.0-48 linux-headers-5.4.0-48-generic
  linux-headers-5.4.0-52 linux-headers-5.4.0-52-generic linux-headers-5.4.0-54 linux-headers-5.4.0-54-generic linux-headers-5.4.0-56
  linux-headers-5.4.0-56-generic linux-headers-5.4.0-58 linux-headers-5.4.0-58-generic linux-headers-5.4.0-60 linux-headers-5.4.0-60-generic
  linux-headers-5.4.0-62 linux-headers-5.4.0-62-generic linux-headers-5.4.0-64 linux-headers-5.4.0-64-generic linux-headers-5.4.0-65
  linux-headers-5.4.0-65-generic linux-image-5.4.0-40-generic linux-image-5.4.0-42-generic linux-image-5.4.0-45-generic linux-image-5.4.0-47-generic
  linux-image-5.4.0-48-generic linux-image-5.4.0-52-generic linux-image-5.4.0-54-generic linux-image-5.4.0-56-generic linux-image-5.4.0-58-generic
  linux-image-5.4.0-60-generic linux-image-5.4.0-62-generic linux-image-5.4.0-64-generic linux-image-5.4.0-65-generic linux-modules-5.4.0-40-generic
  linux-modules-5.4.0-42-generic linux-modules-5.4.0-45-generic linux-modules-5.4.0-47-generic linux-modules-5.4.0-48-generic linux-modules-5.4.0-52-generic
  linux-modules-5.4.0-54-generic linux-modules-5.4.0-56-generic linux-modules-5.4.0-58-generic linux-modules-5.4.0-60-generic linux-modules-5.4.0-62-generic
  linux-modules-5.4.0-64-generic linux-modules-5.4.0-65-generic linux-modules-extra-5.4.0-40-generic linux-modules-extra-5.4.0-42-generic
  linux-modules-extra-5.4.0-45-generic linux-modules-extra-5.4.0-47-generic linux-modules-extra-5.4.0-48-generic linux-modules-extra-5.4.0-52-generic
  linux-modules-extra-5.4.0-54-generic linux-modules-extra-5.4.0-56-generic linux-modules-extra-5.4.0-58-generic linux-modules-extra-5.4.0-60-generic
  linux-modules-extra-5.4.0-62-generic linux-modules-extra-5.4.0-64-generic linux-modules-extra-5.4.0-65-generic
0 upgraded, 0 newly installed, 65 to remove and 0 not upgraded.
After this operation, 4,682 MB disk space will be freed.
Do you want to continue? [Y/n] 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.