0

I'm running Kubuntu 14.04 on my private laptop. When the package system updates my Linux kernel it removes the old packages, only keeping the 2 newest versions of the kernel images (and associated packages). At the moment that would be (AFAIR) 3.13.0-32 and 3.13.0-48. How do I get the package system to stop removing the old kernel images?

I realize this will leave me with a long list of not used kernel images, but I would rather have to do the clean up myself, than risk ending up in a situation where I can't boot my laptop.

EDIT: Based on the answer from Aaron Digulla I created a file, /etc/apt/apt.conf.d/99keep-kernels, with this content:

APT::NeverAutoRemove
{
   "^linux-image-*-generic$";
   "^linux-image-*-generic$";
   "^linux-headers-*-generic$";
   "^linux-headers-*-generic$";
   "^linux-image-extra-*-generic$";
   "^linux-image-extra-*-generic$";
   "^linux-signed-image-*-generic$";
   "^linux-signed-image-*-generic$";
   "^kfreebsd-image-*-generic$";
   "^kfreebsd-image-*-generic$";
   "^kfreebsd-headers-*-generic$";
   "^kfreebsd-headers-*-generic$";
   "^gnumach-image-*-generic$";
   "^gnumach-image-*-generic$";
   "^.*-modules-*-generic$";
   "^.*-modules-*-generic$";
   "^.*-kernel-*-generic$";
   "^.*-kernel-*-generic$";
   "^linux-backports-modules-.*-generic$";
   "^linux-backports-modules-.*-generic$";
   "^linux-tools-*-generic$";
   "^linux-tools-*-generic$";
};

But that didn't work. Ubuntu still only keeps the 2 latest kernels.

jbang
  • 15

1 Answers1

0

Pinning won't work for you since it will prevent from upgrading kernels altogether.

Look into /etc/apt/apt.conf.d/01autoremove and /etc/apt/apt.conf.d/01autoremove-kernels. These files contain lists of packages which should be purged automatically. The second file is maintained by the script /etc/kernel/postinst.d/apt-auto-removal

To solve your problem, copy the file /etc/apt/apt.conf.d/01autoremove-kernels into /etc/apt/apt.conf.d/99keep-kernels and edit the patterns to match any version of the 11 packages in there.

So

"^linux-image-3\.13\.0-45-generic$";

would become

"^linux-image-";

This pattern now matches any version of the package and prevents apt from deleting them ever. The post-install script does the same thing which doesn't create a conflict - your version of the file simply matches more packages and prevents any version to be deleted automatically.

  • Thank you. I don't understand how simply copying the file, without changing anything would work. But I have done it, and now I'm waiting for the next kernel update from Ubuntu to see what will happen.

    I would have upvoted your answer, but because I'm new on this site, I don't have the reputation to do that yet. I will try to remember to come back here later, when I can upvote your answer.

    – jbang Mar 27 '15 at 11:51
  • I've tried to clarify my answer. Have a look. – Aaron Digulla Mar 27 '15 at 12:51
  • I get at least part of it now. :-) But I'm still confused, because the line at the start (APT::NeverAutoRemove) seems to say "Don't delete", even for the 01autoremove-kernels file. Am I completely missing the point, or maybe being ovberly literal?

    A second question? Do you know what the $-sign at the end of the original lines mean?

    – jbang Mar 28 '15 at 21:00
  • And also: Shouldn't there be some kind of wildcard in the lines in the 99keep-kernels file? Or is that implied?

    These lines in the 01autoremove-kernels file seem to imply the need for wildcards: "^.-modules-3.13.0-32-generic$"; "^.-modules-3.13.0-48-generic$"; "^.-kernel-3.13.0-32-generic$"; "^.-kernel-3.13.0-48-generic$";

    – jbang Mar 28 '15 at 21:02
  • The 01autoremove-kernels only contains the last 2 or 3 kernel packages. When you install another one, the first one in the list is removed from the file making it prone to auto removal. – Aaron Digulla Mar 29 '15 at 12:51
  • As for he patterns: "^foo.*$" is the same as "^foo". ^ matches only the start of the string. .*$ many "any character until the end of the string" but this is only necessary when the code requires a full match. Looking at other patterns in the apt config, "^foo" should work. – Aaron Digulla Mar 29 '15 at 12:53
  • I think I understand it now. Thank you for all your help and patience. – jbang Mar 29 '15 at 18:54
  • I tried creating the file as you suggested (see my edit of the original question), but Ubuntu still only keeps the 2 latest kernels. Did I misunderstand what you meant? – jbang May 02 '15 at 14:42
  • @jbang: You need to use .* for "match any characters". Note the . (dot) which means "any character" while * just means "any number of the previous character". So what you wrote only matches linux-image-----------------generic – Aaron Digulla May 04 '15 at 07:37
  • Oh! It's regular expressions, not file wild cards. I didn't realize that. Thank you. :-) – jbang May 04 '15 at 11:26