Announcement

Collapse
No announcement yet.

Removing old kernels

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

    [SOLVED] Removing old kernels

    I know this question has been discussed before, but I can't find it, so please excuse.

    For months now, 'apt-get autoremove' has been ignoring linux-image-4.15.0-45-generic. Can I just delete it by hand (then rerun update-grub) or is there a special command to use.

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

    #2
    I have some cheat sheet notes, taken through the years on this subject, and I need to clean it up. That said, here's the scoop:

    Code:
    [B]Removing old kernels[/B]
    
    [U]Every kernel has four packages[/U] (kernel 3.5.0-15 is shown as an example); and [COLOR=#0000ff][B]these are the files (for old kernels) that you want to remove[/B][/COLOR]:
    
    [B]linux-headers-[/B]3.5.0-15 [I](header files)[/I]
    [B]linux-headers-[/B]3.5.0-15[B]-generic[/B] [I](additional headers depending on kernel type)[/I]
    [B]linux-image-[/B]3.5.0-15[B]-generic[/B] [I](kernel image)[/I] [I]<-- Important[/I]
    [B]linux-image-extra-[/B]3.5.0-15[B]-generic[/B] [I](extra image)[/I]
    
    Once you have installed a new kernel and booted into it to see that it's working properly, you can remove all packages related to older kernels - generally [B]around 220 MB[/B] for all packages together per kernel. However, you may want to keep the kernel version previous to the newest (that you are using now) so you have a backup option should something go wrong with the current (newest) kernel.
    Code:
    [B]In Muon (or Synaptic)[/B], you can enter in the search box:
    
    linux-image
    linux-headers
    Or, try this:
    Simply enter the kernel version number; for example, enter
    3.13.0
    and the headers and image files should come up.
    
    You can now uninstall all packages except those four for the latest kernel (and maybe the four files for the previous kernel, if you want a backup option).
    
    [U]Un-installing[/U]
    Some users here (e.g., vinny and I) recommend you use the "[B]purge[/B]" option (in Muon, for example), to remove these files.


    Code:
    Removing kernels
    
    kubicle:
    Actually, removing a kernel image package frees over 100Mb (it's not just the image, the package installs a good number of [B]firmware and modules in /lib/firmware/{kernel} and /lib/modules/{kernel})[/B]; if you add the headers, that's another 100 MB.
    
    =====
    
    Someone else said:
    > Remove the linux-image-VERSION-generic packages and it will also remove the modules for you.
    Code:
    [U]Keep the last two kernels:[/U]
    
    (ronw) I let auto-remove remove old kernels, AFTER confirming the 'keep last 2 kernels' bit is working. In other words, I run an 'ls /boot' and check that what auto-remove is going to do is sane.
    
    [Important:]
    See [B]the '01autoremove-kernels' file in /etc/apt/apt.conf.d[/B] if you are interested in where the 'keep last 2' magic happens.

    Code:
    [B]Remove old kernels -- using apt-get [/B]
    Do the following if you wish to remove all older kernel versions that are not in use (except the previous one that you are not using. This is to make sure that if the current kernel version fails in some way, you have a way to go back to a previous state). Do the following:
    
     Code:
     sudo apt-get autoclean
    This will eliminate any old files (Including kernel versions) you may have. Note that if you have many old versions, it will take a while since it has to make sure that removing the kernel version has no issues. You can also do the following:
     Code:
     sudo apt-get clean
    Which will eliminate everything downloaded and stored in the cache folder of apt. Lastly you have:
     Code:
     sudo apt-get autoremove
    which would check for any unused packages and remove them if necessary. This is great for those libraries and dependency packages that are no longer needed by any app installed.
    (Note that apt-get has been superseded by apt, but it works.
    An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

    Comment


      #3
      I'm not surprised this happened, it often does. Kernel autoremove only happens in very specific circumstances. For example, installing a new series of kernels like the 5.0.0 series will always leave the last 4.15.0 kernel behind. I assume this is by design as a precaution against leaving you in an un-bootable state. Anyway...

      I've found the best method is to allow apt to remove a kernel and all it's add-ons this way:

      sudo apt remove 4.15.0-45

      This command will go through the package list and offer to remove everything with 4.15.0-45 in it's name. Although I've never had any packages come up that weren't related to the kernel, it's remotely possible, so I suggest taking a couple minutes to review the offered list of packages to be remove before hitting "Y"

      Please Read Me

      Comment


        #4
        I just removed old kernals this morning. I believe that the safest way to do that is with Update Manager. After you load it look under the menu option named View. Select Kernels. You should see a list of Kernels on the left side. Click on one of them. If that kernel is not installed, a button will apear for you to install it. If it is installed a button will show saying Remove.

        The list also shor which Kernel is Active. Don't unstall that one. (I don't think you can while it's active) It's usually advised that you keep that one and the two previous kernals.

        Comment


          #5
          Originally posted by ejazzkatt View Post
          I just removed old kernals this morning. I believe that the safest way to do that is with Update Manager. After you load it look under the menu option named View. Select Kernels. You should see a list of Kernels on the left side. Click on one of them. If that kernel is not installed, a button will apear for you to install it. If it is installed a button will show saying Remove.

          The list also shor which Kernel is Active. Don't unstall that one. (I don't think you can while it's active) It's usually advised that you keep that one and the two previous kernals.
          I don't see this option, not in the version of Discover/updater as found in Neon and Kubuntu 19.04 . There is no 'menu' per to go to

          Comment


            #6
            goofup

            Originally posted by oshunluvr View Post
            sudo apt remove 4.15.0-45
            I'm sure that's right, but I screwed up royally.

            I ran your command and it went thru a bunch of stuff, saying it was getting rid of things and ONLY THEN did it tell me I was trying to delete the running system. (No criticism of your post intended, it was entirely my idiocy.)

            Yep, It was right. I had trusted grub (Neon version) to pick the latest system, but for some reason, it only know 4.15.0-15, plus an old system on another disk, which I am now running. So it was partly grub's not doing its job the way I thought and writing the grub file elsewhere than the one I am using (I've had lots of problems with figuring out where grub is putting stuff). And partly, majorally, mine for not checking first.

            So how do I get my system back? Maybe I can use the other booter, whose name I have forgotten, to find the newer system.
            'I must have a prodigious quantity of mind; it takes me as much as a week sometimes to make it up.' Mark Twain

            Comment


              #7
              Refind found the latest system on that disk. I'm saved. And I did delete 4.15.0-45. So thanks for your help.

              Small question: Does refind do a scan of the disks at bot time or does he depend on a config file somewhere like grub?
              'I must have a prodigious quantity of mind; it takes me as much as a week sometimes to make it up.' Mark Twain

              Comment


                #8
                Code:
                Does refind do a scan of the disks at boot time
                rEFInd does a scan at boot time. rEFInd does have a configuration file, discussed by Rod Smith at his rEFInd web page, but--as I understand it--a scan is done on each boot-up. That's the power and beauty of rEFInd, IMO--great for rescue work. (You can see that config file in the refind folder on the ESP, btw.)
                An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

                Comment


                  #9
                  Sorry, one would assume you would not list the kernel version your were running from when attempting to remove kernels.

                  uname -r

                  shows what kernel is in use. That's also why I strongly suggest not blindly hitting "Y" but checking your actions first. If you have newer kernels than 4.15.0-45 then boot to the latest version and when you're reasonably certain all is well, THEN remove the older kernels.

                  Please Read Me

                  Comment


                    #10
                    Resolved

                    That's what I did and I'm back in work now. Refind was a life saver. Now if I can just figure out where grub is writing its info...

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

                    Comment


                      #11
                      Originally posted by joneall View Post
                      That's what I did and I'm back in work now. Refind was a life saver. Now if I can just figure out where grub is writing its info...

                      Thanks, all.
                      What info exactly? The EFI info is in the EFI partition. Probably partition 1 and fat32 type. /boot/grub/ golds the rest of grub's data.

                      Please Read Me

                      Comment


                        #12
                        Originally posted by oshunluvr View Post
                        What info exactly? The EFI info is in the EFI partition. Probably partition 1 and fat32 type. /boot/grub/ golds the rest of grub's data.
                        And to further clarify, if necessary:
                        an EFI system does not have anything like an MBR, so grub does not 'write' to anything in that sense, in this case. The bootloader's executable and a few other files go into a directory inside the EFI partition.
                        One can manually mount this to a directory and view the contents if desired.

                        Comment

                        Working...
                        X