No announcement yet.

Why is the number of installed unused old kernel images increasing?

  • Filter
  • Time
  • Show
Clear All
new posts

    Why is the number of installed unused old kernel images increasing?

    I recently upgraded to Kubuntu 22.04 release. There was little free space during installation. Then I was faced with how many installed but unused old kernel images are on the Linux partition, which also take up several GB of space. In addition, due to an error, these kernels cannot be automatically removed with the sudo apt-get autoremove command, because they were marked as manually installed by the discover application.

    My question is, why are so many kernel images necessary and how can they be deleted at once, so that only the three most recently installed kernels remain?​


    It probably is a bug in the upgrade. Not entirely common, but not unheard of. I have seen this myself, but quite a long time ago.
    But it may depend on what you upgraded from. The 'last three kernels' on LTS releases seem to involve the least three in each 'series' if you will. Non-HWE vs HWE kernel releases (eventually), Can't recall how this works on non-LTS releases upgrades, but those don't last long enough for kernel to pile up. Long-term early LTS installs (pre *.2?) can potentially have the last three versions of the original non-HWE kernel, plus three of the latest HWE versions, for example.

    There is no sure-fire super-simple way to clean this up , but there are multiple methods. One way would be to use Muon and search for all the linux-image-* packages installed, then mark and uninstall all but the three most current Jammy versions. You can then do an autoremove to get rid of the leftover headers, modules, etc.

    Another option is to use some scripting to do similar actions.

    I used this in the past for experimentation and curiosity purposes
    This was well after I had to manually fix my own issues with excess kernels after multiple years of upgrades.
    I tested it out to remove some excess third-party kernels, as well as some older kernels I manually installed just to test this on, to make sure it still works today. It worked as expected.
    The currently booted kernel for me was blank, with no text in the Version section, and there were two of these empty sections. But otherwise all my extras appeared and were selectable.

    The GUI script version requires 'zenity' be installed, if not present, and the other needs 'dialog' installed.
    I'll ask Jeeves


      Afterward, to mark the remaining linux image packages as 'automatic' you will need to manually set that for each.
      You might be able to do so in Muon or Synaptic, but I dunno.

      Search for your packages:
      $ apt search linux-image | grep installed

      linux-image-5.15.0-53-generic/jammy-security,jammy-updates,now 5.15.0-53.59 amd64 [installed,automatic]
      linux-image-generic/jammy-security,jammy-updates,now amd64 [installed]
      linux-image-generic-hwe-22.04/jammy-security,jammy-updates,now amd64 [installed,automatic]
      linux-image-5.15.0-52-generic/jammy-security,jammy-updates,now 5.15.0-52.58 amd64 [installed,auto-removable]

      sudo apt-mark auto linux-image-5.15.0-52-generic
      Then, to check:
      $ apt search linux-image-5.15.0-52-generic
      linux-image-5.15.0-52-generic/jammy-security,jammy-updates,now 5.15.0-52.58 amd64 [installed,automatic]

      I'll ask Jeeves


        Thank you for your answer. In the meantime, I did some research and found this.
        I did what you said here and it worked, freed up several GB of space.
        I hope yesterday's update from Kubuntu 20.04 to 22.04 was not significantly influenced by the space constraints that existed at the time. During the update with the Software Updater on the graphical interface, I received several messages that there was not enough free space, even though I had already freed up as much space as the installer requested before starting the update, because my first update attempt was interrupted because of this. I also received another system message that linux firmware cannot be installed/updated and insecure operation may occur, which is not legal, but the update continues. But after all this, the second update process was completed successfully according to the system message confirming this. Despite this, the system restart after installation was not successful, so it was necessary to start in recovery mode to free up space by deleting certain packages. After that, the updated system started smoothly.
        Today, as already mentioned, I freed up 11 GB of space by deleting unused old kernel images. Hopefully the system will work as well as it did before upgrading to the new release. The lesson is that for package updates, instead of the Discover application, apt update/apt upgrade issued in the traditional command line is recommended, because in this way the kernel images will be marked for automatic installation.​