clean old kernels

Discussion in 'Proxmox VE: Installation and configuration' started by aPollO, Mar 9, 2018.

  1. aPollO

    aPollO Member
    Proxmox Subscriber

    Joined:
    Mar 6, 2014
    Messages:
    108
    Likes Received:
    7
    Hi,

    quick question. Is it possible to "autoremove" old kernels? I have a lot of kernels installed:

    Code:
    Found linux image: /boot/vmlinuz-4.4.98-6-pve
    Found initrd image: /boot/initrd.img-4.4.98-6-pve
    Found linux image: /boot/vmlinuz-4.4.98-5-pve
    Found initrd image: /boot/initrd.img-4.4.98-5-pve
    Found linux image: /boot/vmlinuz-4.4.98-4-pve
    Found initrd image: /boot/initrd.img-4.4.98-4-pve
    Found linux image: /boot/vmlinuz-4.4.98-3-pve
    Found initrd image: /boot/initrd.img-4.4.98-3-pve
    Found linux image: /boot/vmlinuz-4.4.98-2-pve
    Found initrd image: /boot/initrd.img-4.4.98-2-pve
    Found linux image: /boot/vmlinuz-4.4.83-1-pve
    Found initrd image: /boot/initrd.img-4.4.83-1-pve
    Found linux image: /boot/vmlinuz-4.4.76-1-pve
    Found initrd image: /boot/initrd.img-4.4.76-1-pve
    Found linux image: /boot/vmlinuz-4.4.67-1-pve
    Found initrd image: /boot/initrd.img-4.4.67-1-pve
    Found linux image: /boot/vmlinuz-4.4.62-1-pve
    Found initrd image: /boot/initrd.img-4.4.62-1-pve
    Found linux image: /boot/vmlinuz-4.4.59-1-pve
    Found initrd image: /boot/initrd.img-4.4.59-1-pve
    Found linux image: /boot/vmlinuz-4.4.49-1-pve
    Found initrd image: /boot/initrd.img-4.4.49-1-pve
    Found linux image: /boot/vmlinuz-4.4.44-1-pve
    Found initrd image: /boot/initrd.img-4.4.44-1-pve
    Found linux image: /boot/vmlinuz-4.4.40-1-pve
    Found initrd image: /boot/initrd.img-4.4.40-1-pve
    Found linux image: /boot/vmlinuz-4.4.35-2-pve
    Found initrd image: /boot/initrd.img-4.4.35-2-pve
    Found linux image: /boot/vmlinuz-4.4.35-1-pve
    Found initrd image: /boot/initrd.img-4.4.35-1-pve
    Found linux image: /boot/vmlinuz-4.4.21-1-pve
    Found initrd image: /boot/initrd.img-4.4.21-1-pve
    Found linux image: /boot/vmlinuz-4.4.19-1-pve
    Found initrd image: /boot/initrd.img-4.4.19-1-pve
    Found linux image: /boot/vmlinuz-4.4.15-1-pve
    Found initrd image: /boot/initrd.img-4.4.15-1-pve
    Found linux image: /boot/vmlinuz-4.4.8-1-pve
    Found initrd image: /boot/initrd.img-4.4.8-1-pve
    Found linux image: /boot/vmlinuz-4.2.8-1-pve
    Found initrd image: /boot/initrd.img-4.2.8-1-pve
    Found linux image: /boot/vmlinuz-4.2.6-1-pve
    Found initrd image: /boot/initrd.img-4.2.6-1-pve
    Found memtest86+ image: /boot/memtest86+.bin
    Found memtest86+ multiboot image: /boot/memtest86+_multiboot.bin
    done
    Setting up proxmox-ve (4.4-107) ...
    root@proxmox01 ~ # apt-get autoremove
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    
    But apt does not find any package to remove. Is this OK? Is the only possible way to remove very old kernels by remove them manually?

    Cheers,
    Chris
     
  2. wolfgang

    wolfgang Proxmox Staff Member
    Staff Member

    Joined:
    Oct 1, 2014
    Messages:
    4,763
    Likes Received:
    316
    Hi,
    Yes you have to remove them manual.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Dan Nicolae

    Dan Nicolae Member

    Joined:
    Apr 27, 2016
    Messages:
    71
    Likes Received:
    2
    apt-get update && apt-get -y upgrade && apt-get -y dist-upgrade && apt-get -y autoremove && apt-get -y autoclean
     
  4. fabian

    fabian Proxmox Staff Member
    Staff Member

    Joined:
    Jan 7, 2016
    Messages:
    3,390
    Likes Received:
    523
    that is a very effective way to hose your system. you should never ever run 'apt-get upgrade' on a PVE systems. running apt-get with -y is also a very easy way to accidentally remove important packages, just saying ;)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    tjh likes this.
  5. Dan Nicolae

    Dan Nicolae Member

    Joined:
    Apr 27, 2016
    Messages:
    71
    Likes Received:
    2
    @fabian , I'm sure that you know better proxmox than me. I did'nt had any problems so far. Well, from the whole command line, he can use, hopefully safe, apt-get autoremove && apt-get autoclean :)
     
  6. Rob Loan

    Rob Loan Member

    Joined:
    Mar 25, 2017
    Messages:
    48
    Likes Received:
    5
    apt-get purge $( dpkg --list | grep -P -o "pve-kernel-\d\S+" | grep -v $(uname -r | grep -P -o ".+\d") )
     
  7. GadgetPig

    GadgetPig Member

    Joined:
    Apr 26, 2016
    Messages:
    138
    Likes Received:
    19
    Hello Apollo,

    Very good question! First before doing anything on your server, especially if it's production server, always do full backups of your VMs, and also the data within the VMs.

    Notes & Tips:
    • For me personally, I don't recommend "autoremoving" a bunch of old kernels all at once, instead do them manually, a few at at a time, and future removal are much easier.
    • You will generally want to keep at least 3-5 older kernels to fall back to, in case of any issues. In my example below I only have 2 kernels.
    • I recommend using an SSH client such as putty instead of browser CLI shell within ProxMox gui. That way you can copy/paste the kernel package name
    • If the hard drives are getting old, check hard drive health first using smartctl before updating.

    Steps To Remove Old Kernels
    ======================
    • This is optional, but normally I first run # apt update && apt dist-upgrade and then reboot the server, so it's running the latest updates/kernels. After updating and rebooting the server, verify all your VMs and Containers are running fine.
    • Next I run # uname -r, to find the "current" active running kernel, and make a note of it, for example:
    #root@proxmox:~# uname -r
    4.15.10-1-pve
    • Next I do # dpkg --list|grep pve-kernel to show the list of installed pve-kernels. In the output below, we focus only on "pve-kernel-x-x-x-pve", We do not touch pve-firmware and pve-kernel-x.xx
    root@proxmox:~# dpkg --list|grep pve-kernel
    ii pve-firmware 2.0-4 all Binary firmware code for the pve-kernel [do not ever touch!]
    ii pve-kernel-4.13 5.1-43 all Latest Proxmox VE Kernel Image [not valid, does not have "-pve" at end]
    ii pve-kernel-4.13.16-1-pve 4.13.16-43 amd64 The Proxmox PVE Kernel Image [valid kernel to remove]
    ii pve-kernel-4.15 5.1-2 all Latest Proxmox VE Kernel Image [not valid, does not have "-pve" at end]
    ii pve-kernel-4.15.10-1-pve 4.15.10-2 amd64 The Proxmox PVE Kernel Image [do not remove since this is current kernel! ]

    • Now in the sample above, I want to remove "pve-kernel-4.13.16-1-pve", and also the kernel entry in grub menu, so to do this I do:
    # apt purge pve-kernel-4.13.16-1-pve (note: if you only do # apt remove pve-kernel-x-x-x-pve, it will leave the old kernel grub entry in grub menu)

    It will now say:

    root@proxmox:~# apt purge pve-kernel-4.13.16-1-pve
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    The following packages will be REMOVED:
    proxmox-ve* pve-kernel-4.13* pve-kernel-4.13.16-1-pve*
    0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
    After this operation, 252 MB disk space will be freed.
    Do you want to continue? [Y/n]

    Now at this point double and triple check to make very sure that's the kernel you want to purge, and say
    "Y". It will then uninstall the kernel, purge and delete the kernel entry in grub menu, and update grub menus.

    Hope this helps!
     
    #8 GadgetPig, Mar 28, 2018
    Last edited: Mar 28, 2018
    aPollO, mhagen, janssensm and 2 others like this.
  8. morph027

    morph027 Active Member

    Joined:
    Mar 22, 2013
    Messages:
    424
    Likes Received:
    52
    the purge-old-kernels script also keeps at least 2 by default, can be more via command line argument
     
  9. UHL-Services

    UHL-Services Member
    Proxmox Subscriber

    Joined:
    Aug 4, 2015
    Messages:
    63
    Likes Received:
    2
    I am curious how does one update his Proxmox machine,
    Fabian can you explain on this one? Don't you think words should be used maybe carefully when it comes to users who do not have experience.

    If there is one issue I noticed here on forums, is that the OFFICIAL support is always or MOST of the times:
    - POORLY DOCUMENTED
    - BOGUS REPLIES
    - EXPECTANCE THAT WE ARE PROXMOX GURUS


    I just got into the same issue as reported in this forum.

    I tried several ways to remove extra kernels those @ 10 at number. Alto it works fine on Centos/Ubuntu...
    Code:
    root@node03-sxb-pve01:~# dpkg --list|grep pve-kernel
    ii  pve-firmware                         2.0-4                          all          Binary firmware code for the pve-kernel
    ii  pve-kernel-4.13                      5.1-45                         all          Latest Proxmox VE Kernel Image
    ii  pve-kernel-4.13.13-1-pve             4.13.13-31                     amd64        The Proxmox PVE Kernel Image
    ii  pve-kernel-4.13.13-2-pve             4.13.13-33                     amd64        The Proxmox PVE Kernel Image
    ii  pve-kernel-4.13.13-4-pve             4.13.13-35                     amd64        The Proxmox PVE Kernel Image
    ii  pve-kernel-4.13.13-5-pve             4.13.13-38                     amd64        The Proxmox PVE Kernel Image
    ii  pve-kernel-4.13.13-6-pve             4.13.13-42                     amd64        The Proxmox PVE Kernel Image
    ii  pve-kernel-4.13.16-2-pve             4.13.16-48                     amd64        The Proxmox PVE Kernel Image
    ii  pve-kernel-4.13.16-3-pve             4.13.16-50                     amd64        The Proxmox PVE Kernel Image
    rc  pve-kernel-4.13.8-1-pve              4.13.8-27                      amd64        The Proxmox PVE Kernel Image
    ii  pve-kernel-4.13.8-2-pve              4.13.8-28                      amd64        The Proxmox PVE Kernel Image
    ii  pve-kernel-4.13.8-3-pve              4.13.8-30                      amd64        The Proxmox PVE Kernel Image
    ii  pve-kernel-4.15                      5.2-3                          all          Latest Proxmox VE Kernel Image
    ii  pve-kernel-4.15.17-2-pve             4.15.17-10                     amd64        The Proxmox PVE Kernel Image
    ii  pve-kernel-4.15.17-3-pve             4.15.17-14                     amd64        The Proxmox PVE Kernel Image
    ii  pve-kernel-4.4.44-1-pve              4.4.44-84                      amd64        The Proxmox PVE Kernel Image
    ii  pve-kernel-4.4.67-1-pve              4.4.67-92                      amd64        The Proxmox PVE Kernel Image
    ii  pve-kernel-4.4.76-1-pve              4.4.76-94                      amd64        The Proxmox PVE Kernel Image
    ii  pve-kernel-4.4.79-1-pve              4.4.79-95                      amd64        The Proxmox PVE Kernel Image
    ii  pve-kernel-4.4.83-1-pve              4.4.83-96                      amd64        The Proxmox PVE Kernel Image
    ii  pve-kernel-4.4.95-1-pve              4.4.95-99                      amd64        The Proxmox PVE Kernel Image
    I got issues with purge kernels hence the kernels are still there and they are not purged.

    Why is there no documentation of any kind to this? And when will people STOP thinking everyone who asks here MUST be or IT is an expert. We all learn, yet we cannot learn from these kind of statements:

    Please enlighten me what should I run when I want to upgrade my servers? I just received the message:

    Code:
    The following updates are available:
    
    ceph: 12.2.5-1~bpo90+1 ==> 12.2.6-1~bpo90+1
    ceph-base: 12.2.5-1~bpo90+1 ==> 12.2.6-1~bpo90+1
    ceph-common: 12.2.5-1~bpo90+1 ==> 12.2.6-1~bpo90+1
    ceph-mgr: 12.2.5-1~bpo90+1 ==> 12.2.6-1~bpo90+1
    ceph-mon: 12.2.5-1~bpo90+1 ==> 12.2.6-1~bpo90+1
    ceph-osd: 12.2.5-1~bpo90+1 ==> 12.2.6-1~bpo90+1
    iproute2: 4.13.0-3 ==> 4.15.0-5
    libcephfs2: 12.2.5-1~bpo90+1 ==> 12.2.6-1~bpo90+1
    libpve-apiclient-perl: 2.0-4 ==> 2.0-5
    libpve-common-perl: 5.0-33 ==> 5.0-35
    libpve-guest-common-perl: 2.0-16 ==> 2.0-17
    librados2: 12.2.5-1~bpo90+1 ==> 12.2.6-1~bpo90+1
    libradosstriper1: 12.2.5-1~bpo90+1 ==> 12.2.6-1~bpo90+1
    librbd1: 12.2.5-1~bpo90+1 ==> 12.2.6-1~bpo90+1
    librgw2: 12.2.5-1~bpo90+1 ==> 12.2.6-1~bpo90+1
    pve-container: 2.0-23 ==> 2.0-24
    pve-kernel-4.13.16-3-pve: 4.13.16-49 ==> 4.13.16-50
    pve-kernel-4.15.17-3-pve: 4.15.17-13 ==> 4.15.17-14
    pve-manager: 5.2-2 ==> 5.2-5
    python-ceph: 12.2.5-1~bpo90+1 ==> 12.2.6-1~bpo90+1
    python-cephfs: 12.2.5-1~bpo90+1 ==> 12.2.6-1~bpo90+1
    python-rados: 12.2.5-1~bpo90+1 ==> 12.2.6-1~bpo90+1
    python-rbd: 12.2.5-1~bpo90+1 ==> 12.2.6-1~bpo90+1
    python-rgw: 12.2.5-1~bpo90+1 ==> 12.2.6-1~bpo90+1
    qemu-server: 5.0-28 ==> 5.0-29
     
  10. tjh

    tjh New Member

    Joined:
    Feb 15, 2018
    Messages:
    19
    Likes Received:
    2
    @UHL-Services It's free software. If you don't like the support you're getting, for free, running free software, go elsewhere. This is community support, if you want official support, pay for it. I don't even know why I am bothering to answer your question, but I will anyway.

    You don't use apt-get update, you use apt-get dist-upgrade. Oh look it's even DOCUMENTED.

    To remove a kernel is easy. apt-get remove pve-kernel-4.4.76-1-pve --purge

    No one expects you're a proxmox guru. But this is support from the community, it often assumes a level of knowledge, or at least a willingness to search, ask clear questions and that you're not going to post bold shouty rants about how bad the free support you're getting is.

    Edit: You're a proxmox supporter! That's great. Why don't you use that channel you've paid for to ask questions you don't know the answer to?
     
  11. UHL-Services

    UHL-Services Member
    Proxmox Subscriber

    Joined:
    Aug 4, 2015
    Messages:
    63
    Likes Received:
    2
    @tjh First of all this was not addressed to you, second I do not make conversation based on my opinion. And lastly it is free for you, I paid for it!

    This is that channel - This Joke How?

    I am too tired to even explain you why I posted that. Check my previous posts, get used with the very UNPROFESSIONAL replies, and you will see the difference. And no need to explain me what to do about my support. In my country you are called a Bug in someone's food.

    I can recommend you to see of your own issues and live, have fun online, be good!

    P.S. Let me enlighten you on this issue, Ubuntu package:
    byobu that contains the utility purge-old-kernels / ie: sudo purge-old-kernels --keep 2 -qy

    It does NOT work with Debian and in special with Proxmox, due to renamed Kernel headers from Linux-Image* to PVE-Kernel

    This goes the same for:
    /etc/apt/apt.conf.d/01autoremove-kernels
    and
    /etc/apt/apt.conf.d/01autoremove

    Both are there by default in Debian image that was with Proxmox by default.
    Yet alto 2 rules for autoremove, and one specific for kernels, again does not apply without changes on naming convention.


    C. V. M. I ignored your profile... Because after 20 years online people like you are not novelty. :)
     
    #12 UHL-Services, Jul 11, 2018
    Last edited: Jul 11, 2018
  12. tjh

    tjh New Member

    Joined:
    Feb 15, 2018
    Messages:
    19
    Likes Received:
    2
    No, this is community support.

    If you're a paying customer, you'd use the ticket system.

    I'm sorry you think I'm a bug. Good luck with being shouty.
     
  13. UHL-Services

    UHL-Services Member
    Proxmox Subscriber

    Joined:
    Aug 4, 2015
    Messages:
    63
    Likes Received:
    2
    Study the licensing, my bad for making you insignificant, I am here in my critical hours, and your answer for all I know and passed through was not helping and very irritating .

    Have a good one.
     
  14. GadgetPig

    GadgetPig Member

    Joined:
    Apr 26, 2016
    Messages:
    138
    Likes Received:
    19
    @UHL-Services.

    You can also try dpkg -P (packagename) to purge old kernels:

    #dpkg -P pve-kernel-4.13.13-1-pve

    As for updating, I now recommend doing apt-clean first (to clear out old temp files under /var/cache/apt/archives)

    #apt clean && apt update && apt dist-upgrade
     
  15. fabian

    fabian Proxmox Staff Member
    Staff Member

    Joined:
    Jan 7, 2016
    Messages:
    3,390
    Likes Received:
    523
    @UHL-Services the proper way to upgrade a PVE system is documented in the admin guide as well as built into the web interface. it's plastered all over this forum as well. removing old kernels works just like removing any other package on a Debian based system - we don't autoremove them by default because /boot is not a separate (and thus space-limited) partition on PVE, and users want the ability to reboot into older kernels when they hit a problem with a new one.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    UHL-Services likes this.
  16. Jaroslaw Filiochowski

    Joined:
    Sep 29, 2018
    Messages:
    1
    Likes Received:
    1
    Except when it is a separate space-limited partition.

    At least the fix is quite simple:
    Code:
    rm /etc/apt/apt.conf.d/75pveconf
    apt-get autoremove
    
     
    #17 Jaroslaw Filiochowski, Sep 29, 2018
    Last edited: Sep 30, 2018
    aPollO likes this.
  17. patefoniq

    patefoniq New Member
    Proxmox Subscriber

    Joined:
    Jan 7, 2019
    Messages:
    3
    Likes Received:
    0
    Is it safe for sure?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  18. fabian

    fabian Proxmox Staff Member
    Staff Member

    Joined:
    Jan 7, 2016
    Messages:
    3,390
    Likes Received:
    523
    PVE 6.x will now allow easy autoremoval of kernels. Only the following will be marked as not eligible for autoremoval:
    - currently running kernel
    - last installed kernel
    - two latest kernels
    - last kernel of each series
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. patefoniq

    patefoniq New Member
    Proxmox Subscriber

    Joined:
    Jan 7, 2019
    Messages:
    3
    Likes Received:
    0
    What about PMG?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice