0

I thought I had finally found a solution to my issues with apt not being smart enough to remove kernels/headers that are not needed with 'purge-old-kernels' thanks to byobu. It works great for kernels (thankfully since that is in it's name), but it doesn't work so well for the header packages. It seems to only remove the generic packages and doesn't touch the base packages at all.

Example:

# dpkg -l | grep linux-header
ii  linux-headers-4.4.0-101           4.4.0-101.124                              all          Header files related to Linux kernel version 4.4.0
ii  linux-headers-4.4.0-103           4.4.0-103.126                              all          Header files related to Linux kernel version 4.4.0
ii  linux-headers-4.4.0-103-generic   4.4.0-103.126                              amd64        Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii  linux-headers-4.4.0-104           4.4.0-104.127                              all          Header files related to Linux kernel version 4.4.0
ii  linux-headers-4.4.0-104-generic   4.4.0-104.127                              amd64        Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii  linux-headers-4.4.0-108           4.4.0-108.131                              all          Header files related to Linux kernel version 4.4.0
ii  linux-headers-4.4.0-108-generic   4.4.0-108.131                              amd64        Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii  linux-headers-4.4.0-109           4.4.0-109.132                              all          Header files related to Linux kernel version 4.4.0
ii  linux-headers-4.4.0-109-generic   4.4.0-109.132                              amd64        Linux kernel headers for version 4.4.0 on 64 bit x86 SMP
ii  linux-headers-4.4.0-75            4.4.0-75.96                                all          Header files related to Linux kernel version 4.4.0
ii  linux-headers-4.4.0-78            4.4.0-78.99                                all          Header files related to Linux kernel version 4.4.0
ii  linux-headers-4.4.0-79            4.4.0-79.100                               all          Header files related to Linux kernel version 4.4.0
ii  linux-headers-4.4.0-81            4.4.0-81.104                               all          Header files related to Linux kernel version 4.4.0
ii  linux-headers-4.4.0-83            4.4.0-83.106                               all          Header files related to Linux kernel version 4.4.0
ii  linux-headers-4.4.0-87            4.4.0-87.110                               all          Header files related to Linux kernel version 4.4.0
ii  linux-headers-4.4.0-89            4.4.0-89.112                               all          Header files related to Linux kernel version 4.4.0
ii  linux-headers-4.4.0-91            4.4.0-91.114                               all          Header files related to Linux kernel version 4.4.0
ii  linux-headers-4.4.0-93            4.4.0-93.116                               all          Header files related to Linux kernel version 4.4.0
ii  linux-headers-4.4.0-96            4.4.0-96.119                               all          Header files related to Linux kernel version 4.4.0
ii  linux-headers-4.4.0-97            4.4.0-97.120                               all          Header files related to Linux kernel version 4.4.0
ii  linux-headers-4.4.0-98            4.4.0-98.121                               all          Header files related to Linux kernel version 4.4.0

As you can see, I have used it on this system and it only removes the -generic packages. It seems to run apt to remove packages, which looks like this:

The following packages will be REMOVED:
  linux-headers-4.4.0-103-generic* linux-headers-4.4.0-104-generic* 
linux-image-4.4.0-103-generic* linux-image-4.4.0-104-generic*
0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded.

As you can see, it is only removing the header generic packages and not touching the base packages at all.

Any way to make it pay attention to those as well??? Trying to automate this across quite a few systems using cron and trying to make it as easy as possible. Thanks.

1 Answers1

4

Byobu is the program containing the script purge-old-kernels (it was taken from earlier program bikeshed)

According to Byobu maintainer Dustin Kirkland:

purge-old-kernels has been deprecated, in favor of "apt autoremove". If you have problems, please file bugs against apt.

(2017-04-27 https://bugs.launchpad.net/byobu/+bug/1646276)

Which is a similar bug to this question, which is maybe better described as a feature request.

Therefore the script will not be updated via Byobu, unless it is taken over by a different maintainer.

However the script is only 58 lines and located at /usr/bin/purge-old-kernels in many systems. So, you could probably rewrite the simple awk filter it uses to run dpkg and apt remove --purge but then you're left maintaining your own script.

There is more discussion of depreciating purge-old-kernels in favour of apt autoremove at https://bugs.launchpad.net/ubuntu/+source/byobu/+bug/1686138 which includes some description of both malfunctioning in some cases.

That discussion for the bug gets closed in a way to maintain both packages basic functionality but does not fix problems of kernels/headers being incorrectly purged in some cases.

Instead Jarno Suni, dissatisfied with this outcome, has offered a more recent (2018 updated) script called linux-purge https://launchpad.net/linux-purge. This script is not packaged but can be used via these instructions: https://launchpad.net/linux-purge/+announcement/14752 which does require manual update if the script is changed in the future.

Linux-purge runs a command line graphical choosing interface (similar to debian install graphical command line) that is quite verbose and includes description of linux-header* and linux-module* files that may be removed. This script can be run safely non-root with the -s, --simulate dry run option before actually making changes.

In conclusion: purge-old-kernels script can only be manually rewritten as it will not be updated. The kernel removal improvements requested are available from the newer manually installable script linux-purge.

  • I just made it easier to install linux-purge: https://launchpad.net/linux-purge/+announcement/15313 – jarno Aug 12 '19 at 19:54