Announcement

Collapse
No announcement yet.

How to remove old kernels with pkcon?

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to remove old kernels with pkcon?

    I have got the message that with Neon one should use pkcon in preference to apt-get or apt. However, since I started with it, no old kernels are not being removed.

    $ ll /boot/vml*
    lrwxrwxrwx 1 root root 25 mars 30 19:07 /boot/vmlinuz -> vmlinuz-5.4.0-107-generic
    -rw------- 1 root root 11746656 déc. 14 16:23 /boot/vmlinuz-5.11.0-44-generic
    -rw------- 1 root root 11746784 janv. 7 00:27 /boot/vmlinuz-5.11.0-46-generic
    -rw------- 1 root root 10161824 janv. 14 00:50 /boot/vmlinuz-5.13.0-27-generic
    -rw------- 1 root root 10170592 janv. 19 14:43 /boot/vmlinuz-5.13.0-28-generic
    -rw------- 1 root root 10171040 févr. 7 15:03 /boot/vmlinuz-5.13.0-30-generic
    -rw------- 1 root root 10171296 mars 7 09:09 /boot/vmlinuz-5.13.0-35-generic
    -rw------- 1 root root 10174368 mars 15 16:28 /boot/vmlinuz-5.13.0-37-generic
    -rw------- 1 root root 10174400 mars 24 17:34 /boot/vmlinuz-5.13.0-39-generic
    -rw------- 1 root root 13664512 févr. 4 18:04 /boot/vmlinuz-5.4.0-100-generic
    -rw------- 1 root root 13664512 mars 2 19:37 /boot/vmlinuz-5.4.0-104-generic
    -rw------- 1 root root 13664512 mars 7 17:20 /boot/vmlinuz-5.4.0-105-generic
    -rw------- 1 root root 13664512 mars 24 16:52 /boot/vmlinuz-5.4.0-107-generic
    -rw------- 1 root root 13656320 nov. 26 15:45 /boot/vmlinuz-5.4.0-92-generic
    -rw------- 1 root root 13656320 janv. 7 00:07 /boot/vmlinuz-5.4.0-94-generic
    -rw------- 1 root root 13656320 janv. 12 17:22 /boot/vmlinuz-5.4.0-96-generic
    -rw------- 1 root root 13660416 janv. 13 19:04 /boot/vmlinuz-5.4.0-97-generic
    -rw------- 1 root root 13660416 févr. 2 17:23 /boot/vmlinuz-5.4.0-99-generic
    lrwxrwxrwx 1 root root 25 mars 30 19:07 /boot/vmlinuz.old -> vmlinuz-5.13.0-39-generic

    I have tried apt autoremove, to no avail, and can't figure out from the help how any autoremove might work with pkcon.

    Any suggestions appreciated. I'm at vmlinuz-5.13.0-39-generic.
    'I must have a prodigious quantity of mind; it takes me as much as a week sometimes to make it up.' Mark Twain

    #2

    Originally posted by joneall View Post
    have got the message that with Neon one should use pkcon in preference to apt-get or apt.
    Feel free to ignore that, if you want. That preferecne is mainly for the new users, and those unfamiliar with apt and


    pkcon actually uses apt (in Debian and Ubuntu variants), so if it did have such an option, it would be doing an apt autoremove anyway.

    Sometimes, it seems kernels in Ubuntu can have their autoremove -ability broken.

    $ apt search linux-image | grep installed

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

    linux-image-5.13.0-39-generic/focal-security,focal-updates,now 5.13.0-39.44~20.04.1 amd64 [installed,automatic]
    linux-image-5.4.0-107-generic/focal-security,focal-updates,now 5.4.0-107.121 amd64 [installed,automatic]
    linux-image-generic/focal-security,focal-updates,now 5.4.0.107.111 amd64 [installed,automatic]
    linux-image-generic-hwe-20.04/focal-security,focal-updates,now 5.13.0.39.44~20.04.24 amd64 [installed,automatic]
    Note the 'automatic' - I think this marks kernel packages (linux-image) as being able to be removed automatically. if they are marked as 'manual', they will not be.

    There is a way to fix this, using the tool called purge-old-kernels, which you can get via the package byobu (Ubuntu's terminal multiplexer and set of DevOps tool, oddly enough)

    sudo purge-old-kernels will clean up old kernels, leaving 2 or 3 behind. You might use apt autoremove to see if any headers or other related support packages for these kernels also gets removed - not sure if this happens automatically with purge-old-kernels or not.


    Lol, this just runs sudo apt-autoremove now so.......nvrmind
    Last edited by claydoh; Apr 05, 2022, 01:19 PM.

    Comment


      #3
      See this old thread

      Kernel packages are handled differently. Once you "jump" to a new series the old one hangs around. Auroremove doesn't "see" it. What you have now is 5.4.0-107 is booting because it was the last kernel installed. I just went through this exact thing with my Ubuntu server.

      What I did was first, edited the symlinks to reflect the correct kernel versions, and rebooted into 5.13. All you have to do is rename vmlinuz to something, rename vmlinuz.old to vmlinuz - and do the same with initrd.img. You may want to manually create the .old versions pointing at 5.13.0-37

      Then after reboot you should be on 5.13.0-39.


      For the 5.4 series, you probably have this package installed:

      linux-headers-generic

      Running this in konsole:

      dpkg -l |grep linux-headers-generic

      will reveal it and should show that it's version is 5.4.0-whatever. IIRC, removing this package should allow autoremove to dump all the 5.4 kernel packages.


      I'm not sure what to do about your 5.11 series except manually remove them. It's a bit of a PITA because it won't let you remove the kernel if the modules exist. So run this in konsole:

      dpkg -l |grep -E '5.11.0.*modules' |grep -v 'rc' |awk '{print $2}'

      This will list all modules that are installed of version 5.11.0. Review the list to be sure you're happy with the output, then remove them. A one-liner if you want to try it:

      for p in `dpkg -l |grep -E '5.11.0.*modules' |grep -v 'ii' |awk '{print $2}'` ; do sudo apt remove --purge $p ; done

      Once you've done that I believe autoremove will now dump the remaining kernel packages from 5.11.0 or you will at least be able to manually remove the kernels and headers.


      Finally, you should remove all but the last two kernels from the 5.13.0.


      Side note: it seems more often than not that the module folders will not be cleaned off even if you use the --purge option. When you're all done removing kernels, I suggest looking at the /lib/modules folder and deleting all folders that are not related to a kernel you actually have installed.



      Please Read Me

      Comment


        #4
        Here's the result of your suggested command:

        $ dpkg -l |grep linux-headers-generic
        ii linux-headers-generic-hwe-20.04 5.13.0.39.44~20.04.24 amd64 Generic Linux kernel headers
        This looks like version 5.13, which looks like the one I want to keep.

        And, curiously, I am on 5.13:

        $ uname -a
        Linux john-desktop 5.13.0-39-generic #44~20.04.1-Ubuntu SMP Thu Mar 24 16:43:35 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

        As to the old thread linked by oshunlover. I see this in the apt conf files:

        $ less /etc/apt/apt.conf.d/01autoremove-kernels

        // DO NOT EDIT! File autogenerated by /etc/kernel/postinst.d/apt-auto-removal
        APT::NeverAutoRemove
        {
        "^linux-.*-5\.13\.0-37-generic$";
        "^linux-.*-5\.13\.0-39-generic$";
        "^linux-.*-5\.4\.0-107-generic$";
        "^kfreebsd-.*-5\.13\.0-37-generic$";
        "^kfreebsd-.*-5\.13\.0-39-generic$";
        "^kfreebsd-.*-5\.4\.0-107-generic$";
        "^gnumach-.*-5\.13\.0-37-generic$";
        "^gnumach-.*-5\.13\.0-39-generic$";
        "^gnumach-.*-5\.4\.0-107-generic$";
        "^.*-modules-5\.13\.0-37-generic$";
        "^.*-modules-5\.13\.0-39-generic$";
        "^.*-modules-5\.4\.0-107-generic$";
        "^.*-kernel-5\.13\.0-37-generic$";
        "^.*-kernel-5\.13\.0-39-generic$";
        "^.*-kernel-5\.4\.0-107-generic$";
        };
        Is this telling apt not to delete those files. Is all this really just because I forgot to do apt autoremove after a new kernel install?

        'I must have a prodigious quantity of mind; it takes me as much as a week sometimes to make it up.' Mark Twain

        Comment


          #5
          Or do as I do and just install the Ubuntu Mainline Kernel Installer.

          https://ubuntuhandbook.org/index.php...tu-linux-mint/
          Constant change is here to stay!

          Comment

          Working...
          X