Announcement

Collapse
No announcement yet.

How to keep a few kernels for back up purposes?

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

    How to keep a few kernels for back up purposes?

    I just installed Kubuntu 20.04, and no problem there. Over time for you'll be noticing that you have 4 or 5 previously kernels installed if you change the grub timeout from 0 to 3 seconds for example. When you run a "sudo apt auto-remove" in Konsole, you get rid of everything except the newest kernel.

    My question is:
    What do you do if you want to keep the previously installed kernel. For example, you just want to save 1 or 2 previously installed kernels and delete the rest of them?

    #2
    Autoremove should be keeping your current kernel, and the previous one, uninstalling the rest.
    This has no relation to your grub timeout.
    You usually see them under the 'Advanced' option. if you don't want to change the grub timeout, hit the esc key repeatedly just after the bios splash to get the menu if you don't see it.

    Comment


      #3
      I guess I didn't clarify well. Let say you have 6 kernels installed over time, and you just want to keep the last 3, but remove the older ones. How do you do that?

      Comment


        #4
        Running sudo apt autoremove --purge will remove all the old ones, except your current kernel and the last kernel.
        This is a long standing setup in *buntu. There are apt configs and rules that are specifically set up to keep them, which iirc are updated with each new kernel.
        That's how it is supposed to work, at least. Has for me, for many years. Well, four, as it was initially set up previous to 16.04

        I don't see how to set it to three, the configs are all Greek to me atm, and possibly any settings edits may get overridden with each new update.





        Do note that kernels NOT automatically installed by updates, ie things installed manually, such as mainline kernels, or other custom third party builds, are NOT auto-removed.
        Last edited by claydoh; Dec 06, 2020, 06:13 PM.

        Comment


          #5
          Thanks for the info.

          Comment


            #6
            Originally posted by fhins View Post
            I guess I didn't clarify well. Let say you have 6 kernels installed over time, and you just want to keep the last 3, but remove the older ones. How do you do that?
            You don't have to run apt autoremove. If you want to keep, say, the last 5 kernels, you can manually remove the 6th oldest. Using muon or synaptic you can easily search for the kernel version number and remove them that way.

            If you do adopt this approach, old, non-kernel stuff could accumulate; probably not a problem and won't be much unless you do a lot of removing packages, but you can do an autoremove dry run to see what it would remove and manually remove it.
            Regards, John Little

            Comment


              #7
              I've used autoremove for a long time. I DO NOT install kernels outside of what is offered in the usual update process. Autoremove leaves the most current kernel, plus the next older kernel. Assuming that the "next older" kernel worked when it was #1, you will always have a drop back point.

              If you are one who experiments with kernels, then autoremove is likely not for you.
              The next brick house on the left
              Intel i7 11th Gen | 16GB | 1TB | KDE Plasma 5.27.11​| Kubuntu 24.04 | 6.8.0-31-generic



              Comment


                #8
                fhins, you can check another thread on this issue ... Go to my post here, I tell you how I do this (manually), Post #12, fwiw; and you can read other posts about it:
                https://www.kubuntuforums.net/showth...615#post440615
                An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

                Comment


                  #9
                  I'm gonna post it here, too.

                  From various previous discussions of this subject, I copied-saved these notes on manually cleaning old kernels. Sorry, I don't have time to clean it up at the moment, but I think it's in pretty decent shape as is (fwiw, this is what I do -- I simply use Muon as described here):

                  Removing old kernels

                  Every kernel has four packages (kernel 3.5.0-15 is shown as an example); and these are the files (for old kernels) that you want to remove:

                  linux-headers-3.5.0-15 (header files)
                  linux-headers-3.5.0-15-generic (additional headers depending on kernel type)
                  linux-image-3.5.0-15-generic (kernel image) <-- Important
                  linux-image-extra-3.5.0-15-generic (extra image)

                  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 around 220 MB 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.

                  In Muon (or Synaptic), 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).

                  Un-installing
                  Some users here (e.g., vinny and I) recommend you use the "purge" option (in Muon, for example), to remove these files.

                  Someone else said:
                  > Remove the linux-image-VERSION-generic packages and it will also remove the modules for you.

                  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                  re commands, I have this:

                  Remove old kernels -- using apt-get
                  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
                  (Correction: kubicle): autoclean is just a "softer" version of 'clean', removing old packages from the download cache, keeping still available packages in cache (while 'clean' removes everything in the cache, including currently available packages)...autoclean does not uninstall anything, nor does it check for any 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.
                  Last edited by Qqmike; Dec 07, 2020, 02:48 PM.
                  An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

                  Comment


                    #10
                    Originally posted by Qqmike View Post
                    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:
                    I may have misunderstood what you meant, but that's not really a completely accurate description of what autoclean does.
                    autoclean is just a "softer" version of 'clean', removing old packages from the download cache, keeping still available packages in cache (while 'clean' removes everything in the cache, including currently available packages)...autoclean does not uninstall anything, nor does it check for any issues.
                    Last edited by kubicle; Dec 07, 2020, 12:24 PM.

                    Comment


                      #11
                      Thanks, kubicle. I made that correction in the link and the post above (and in my notes ;-) ).
                      An intellectual says a simple thing in a hard way. An artist says a hard thing in a simple way. Charles Bukowski

                      Comment


                        #12
                        Hello,
                        I'm attaching to this recent discussion to still talk about automatic old kernel pruning.
                        Yesterday, when trying to install the latest kernel version for my Kubuntu 20.04 installation, I went out of space in my /boot partition. Looking at the installed kernels, I saw that I had 6 (SIX!) old kernels installed, including the one I was running on.
                        I knew I had all the automatic kernel update and cleaning in place thanks to unattended-upgrades, because I looked at it some time ago, so, I took back the Ubuntu documentation page at https://help.ubuntu.com/community/RemoveOldKernels and re-read it from scratch.
                        Substantially this sentence is enlightening:
                        Note: The following methods will only remove kernels that are marked as being automatically installed as described above.
                        My problem was that all the installed kernels where marked as MANUALLY INSTALLED:
                        Code:
                        [FONT=monospace][COLOR=#54ff54][B]mauro@hppb[/B][/COLOR][COLOR=#5454ff][B]~ $[/B][/COLOR][COLOR=#000000] apt-mark showauto 'linux-image-.*' [/COLOR]
                        linux-image-generic 
                        [COLOR=#54ff54][B]mauro@hppb[/B][/COLOR][COLOR=#5454ff][B]~ $[/B][/COLOR][COLOR=#000000] apt-mark showmanual 'linux-image-.*' [/COLOR]
                        linux-image-5.4.0-54-generic 
                        linux-image-5.4.0-56-generic 
                        linux-image-5.4.0-58-generic 
                        linux-image-5.4.0-59-generic 
                        linux-image-5.4.0-62-generic 
                        linux-image-5.4.0-64-generic 
                        linux-image-5.4.0-65-generic
                        [/FONT]
                        (note: the last kernel version was the one I was not able to completely install due to insufficient disk space)

                        Also, looking at
                        Code:
                        /etc/apt/apt.conf.d/01autoremove-kernels
                        I had:

                        Code:
                        [FONT=monospace][COLOR=#000000]rc  linux-image-5.4.0-42-generic                                5.4.0-42.46                                 amd64        Signed kernel image generic [/COLOR]
                        rc  linux-image-5.4.0-48-generic                                5.4.0-48.52                                 amd64        Signed kernel image generic 
                        rc  linux-image-5.4.0-51-generic                                5.4.0-51.56                                 amd64        Signed kernel image generic 
                        rc  linux-image-5.4.0-52-generic                                5.4.0-52.57                                 amd64        Signed kernel image generic 
                        rc  linux-image-5.4.0-53-generic                                5.4.0-53.59                                 amd64        Signed kernel image generic 
                        rc  linux-image-5.4.0-60-generic                                5.4.0-60.67                                 amd64        Signed kernel image generic 
                        ii  linux-image-5.4.0-62-generic                                5.4.0-62.70                                 amd64        Signed kernel image generic 
                        ii  linux-image-5.4.0-64-generic                                5.4.0-64.72                                 amd64        Signed kernel image generic 
                        iF  linux-image-5.4.0-65-generic                                5.4.0-65.73                                 amd64        Signed kernel image generic 
                        ii  linux-image-generic                                         5.4.0.65.68                                 amd64        Generic Linux kernel image
                        [/FONT]
                        So, some kernel versions were indeed automatically pruned in the past (those marked with "rc"), but other are missing there and indeed they were marked as "manually installed".

                        I'm pretty sure the problem lies here: some kernel version were automatically installed by unattended-upgrades (and these where automatically purged), some others were installed by me by hitting "update all" button in Discover, when it periodically notifies me about new updates.

                        So, looking again at the Ubuntu wiki page, I see:

                        In Ubuntu 16.04 kernels installed by Software Updater are marked as being automatically installed. In Ubuntu 14.04 only kernels installed by unattended-upgrades are marked as being automatically installed. See bug #1439769 for details.
                        So, I suspect such a "bug" is still present in Kubuntu 20.04 Discover, which marks all kernels installed through it as "manually installed". Is this a known problem?

                        Thanks in advance.

                        Comment


                          #13
                          Discover has nothing to do with this, actually.

                          Have you run apt autoremove at all?

                          All those configs are to make sure that there are a certain number of kernels kept when an apt autoremove action is done.

                          'Autoremove' references the command option for apt, and not any regular automatic removal of packages.

                          Ain't anything that actually automatically autoremoves anything at all. At least not by default.

                          One still has to do this manually.


                          Code:
                           $ apt search linux-image-5 | grep installed
                          
                          
                          linux-image-5.4.0-59-generic/focal-security,focal-updates,now 5.4.0-59.65 amd64 [installed]
                          linux-image-5.4.0-62-generic/focal-security,focal-updates,now 5.4.0-62.70 amd64 [installed]
                          linux-image-5.4.0-65-generic/focal-security,focal-updates,now 5.4.0-65.73 amd64 [installed,automatic]
                          Sent from my LM-V600 using Tapatalk
                          Last edited by claydoh; Jan 28, 2021, 04:48 AM.

                          Comment


                            #14
                            Originally posted by claydoh View Post
                            Have you run apt autoremove at all?
                            Yes I did it and it was doing nohing, because these kernel updates where marked as manually installed.

                            Originally posted by claydoh View Post
                            Ain't anything that actually automatically autoremoves anything at all. At least not by default.
                            One still has to do this manually.
                            I'm not quite convinced. If you look at https://help.ubuntu.com/community/RemoveOldKernels you'll see that unattended-upgrades, which is installed by default, is going to purge old kernels for you, by default, but they must be marked as automatically installed.

                            There was a bug in the past that prevented kernels installed by the Ubuntu Update Manager from being automatically removed because they were marked as manually installed: https://bugs.launchpad.net/ubuntu/+s...r/+bug/1439769
                            This is why I'm now suspecting something similar is happening with updates installed by Discover.

                            Indeed, today I found these bug reports:
                            https://bugs.kde.org/show_bug.cgi?id=430296
                            https://github.com/hughsie/PackageKit/issues/450

                            so I think there must be something not working properly.

                            Comment


                              #15
                              Yes, something is going on with your system.

                              I do the sudo apt autoremove, and etc., sequence after a new kernel is installed. The last kernel update was several days ago and after doing that sequence of inputs, df -h showed a drop in used space of a few 100K, and I have two kernels currently on the system's SSD - 5.8.0-40 and 5.8.0-41. I do not ever manually install kernels; they are only the result of the sudo apt update and sudo apt full-upgrade sequence.
                              The next brick house on the left
                              Intel i7 11th Gen | 16GB | 1TB | KDE Plasma 5.27.11​| Kubuntu 24.04 | 6.8.0-31-generic



                              Comment

                              Working...
                              X