clean old kernels

Mar 6, 2014
109
7
18
Stuttgart, Germany
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
 

Dan Nicolae

Member
Apr 27, 2016
71
2
8
39
apt-get update && apt-get -y upgrade && apt-get -y dist-upgrade && apt-get -y autoremove && apt-get -y autoclean
 

fabian

Proxmox Staff Member
Staff member
Jan 7, 2016
3,456
540
113
apt-get update && apt-get -y upgrade && apt-get -y dist-upgrade && apt-get -y autoremove && apt-get -y autoclean
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 ;)
 
  • Like
Reactions: tjh

Dan Nicolae

Member
Apr 27, 2016
71
2
8
39
@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 :)
 

Rob Loan

Member
Mar 25, 2017
48
5
8
54
apt-get purge $( dpkg --list | grep -P -o "pve-kernel-\d\S+" | grep -v $(uname -r | grep -P -o ".+\d") )
 

GadgetPig

Member
Apr 26, 2016
138
19
18
50
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!
 
Last edited:
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 ;)
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:

you should never ever run 'apt-get upgrade' on a PVE systems
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
 

tjh

New Member
Feb 15, 2018
19
3
3
43
@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?
 
@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!

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?
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. :)
 
Last edited:

fabian

Proxmox Staff Member
Staff member
Jan 7, 2016
3,456
540
113
@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.
 
  • Like
Reactions: UHL-Services
Sep 29, 2018
1
1
1
we don't autoremove them by default because /boot is not a separate (and thus space-limited) partition on PVE
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
 
Last edited:
  • Like
Reactions: aPollO

fabian

Proxmox Staff Member
Staff member
Jan 7, 2016
3,456
540
113
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
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE and Proxmox Mail Gateway. We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get your own in 60 seconds.

Buy now!