24

I got a warning of my /boot partition is almost full(85%). What should I do? Can I remove one of the backup kernel? How to do it safely?

My partition right now

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2             10321208    719856   9077064   8% /
tmpfs                  4015460         0   4015460   0% /dev/shm
/dev/sda1               101133     80781     15130  85% /boot
/dev/sda8            253782660  47668764 193222404  20% /home
/dev/sda7              1032088    535840    443820  55% /tmp
/dev/sda3             10321208   4823740   4973180  50% /usr
/dev/sda5             10321208   1807284   7989636  19% /var

The Kernel I have

root@server1 [/boot]# rpm -q kernel
kernel-2.6.32-358.el6.x86_64
kernel-2.6.32-358.18.1.el6.x86_64
kernel-2.6.32-358.23.2.el6.x86_64

The /Boot directory

root@server1 [/boot]# ls -la /boot
total 78741
dr-xr-xr-x.  5 root root     2048 Dec  3 05:33 ./
drwxr-xr-x. 23 root root     4096 Dec  4 05:46 ../
-rw-r--r--   1 root root   104112 Aug 28 12:43 config-2.6.32-358.18.1.el6.x86_64
-rw-r--r--   1 root root   104112 Oct 16 14:01 config-2.6.32-358.23.2.el6.x86_64
-rw-r--r--.  1 root root   104081 Feb 21  2013 config-2.6.32-358.el6.x86_64
drwxr-xr-x.  3 root root     1024 Sep 20 20:15 efi/
drwxr-xr-x.  2 root root     1024 Oct 21 15:06 grub/
-rw-r--r--   1 root root 16191847 Sep 20 20:21 initramfs-2.6.32-358.18.1.el6.x86_64.img
-rw-r--r--   1 root root 16261655 Oct 21 15:06 initramfs-2.6.32-358.23.2.el6.x86_64.img
-rw-r--r--.  1 root root 16187335 Sep 20 20:16 initramfs-2.6.32-358.el6.x86_64.img
-rw-------   1 root root  3698835 Sep 20 20:27 initrd-2.6.32-358.18.1.el6.x86_64kdump.img
-rw-------   1 root root  3983771 Dec  3 05:33 initrd-2.6.32-358.23.2.el6.x86_64kdump.img
-rw-------   1 root root  3695290 Sep 20 20:21 initrd-2.6.32-358.el6.x86_64kdump.img
drwx------.  2 root root    12288 Sep 20 20:13 lost+found/
-rw-r--r--   1 root root   185949 Aug 28 12:44 symvers-2.6.32-358.18.1.el6.x86_64.gz
-rw-r--r--   1 root root   185978 Oct 16 14:02 symvers-2.6.32-358.23.2.el6.x86_64.gz
-rw-r--r--.  1 root root   185734 Feb 21  2013 symvers-2.6.32-358.el6.x86_64.gz
-rw-r--r--   1 root root  2408641 Aug 28 12:43 System.map-2.6.32-358.18.1.el6.x86_64
-rw-r--r--   1 root root  2408974 Oct 16 14:01 System.map-2.6.32-358.23.2.el6.x86_64
-rw-r--r--.  1 root root  2407466 Feb 21  2013 System.map-2.6.32-358.el6.x86_64
-rwxr-xr-x   1 root root  4046224 Aug 28 12:43 vmlinuz-2.6.32-358.18.1.el6.x86_64*
-rw-r--r--   1 root root      171 Aug 28 12:43 .vmlinuz-2.6.32-358.18.1.el6.x86_64.hmac
-rwxr-xr-x   1 root root  4047152 Oct 16 14:01 vmlinuz-2.6.32-358.23.2.el6.x86_64*
-rw-r--r--   1 root root      171 Oct 16 14:01 .vmlinuz-2.6.32-358.23.2.el6.x86_64.hmac
-rwxr-xr-x.  1 root root  4043888 Feb 21  2013 vmlinuz-2.6.32-358.el6.x86_64*
-rw-r--r--.  1 root root      166 Feb 21  2013 .vmlinuz-2.6.32-358.el6.x86_64.hmac

The Kernel I'm using

root@server1 [/boot]# uname -a
Linux server1 2.6.32-358.23.2.el6.x86_64 #1 SMP Wed Oct 16 18:37:12 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
  • 4
    Why was this marked as a duplicate? The other question isn't even about yum. I don't doubt it is a duplicate, just not of that particular question. – Bratchley Feb 9 '15 at 21:23
51

Do the following to keep just the last 2 kernels on your system, to keep /boot clean

1 - Edit /etc/yum.conf and set the following parameter

installonly_limit=2

This will make your package manager keep just the 2 last kernels on your system(including the one that is running)

2 - Install yum-utils:

yum install yum-utils

3- Make an oldkernel cleanup:

package-cleanup --oldkernels --count=2

Done. This will erase in a good fashion the old kernels, and, keep just the last 2 of them for the next upgrades.

For special cases where you have vmlinuz-0-rescue-* and initramfs-0-rescue-* files using too much disk space, please take a look at this question on U&L:

| improve this answer | |
  • Thanks nwildner! Can I do it right now? Do I need to reboot the system after doing that? Do I need to backup all my data? – Tester Dec 13 '13 at 16:06
  • Yes you can. A backup of your /boot, just for precaution could be a good thing to do. You will not need to reboot, since the step 3 will erase the oldest kernel, unless you are running it right now. The first step, will make this configuration permanent ;) – user34720 Dec 13 '13 at 16:44
  • Though this isn't always enough. I followed these steps and found that I already only had 2 kernels - the problem for me was a 60MB "initramfs-0-rescue" file which was 5 months old. Deleted that and everything was fine. – Codemonkey Feb 19 '19 at 9:24
  • 1
    Hey @Codemonkey . I've updated my answer with details about rescue files... – user34720 Feb 19 '19 at 13:41
11

You can delete old kernels safely by doing the following:

# Install the yum-utils if they aren't installed
yum install yum-utils
# Cleanup old kernels and don't keep more than 2
package-cleanup --oldkernels --count=2

And should you wish, you can limit this always by doing the following in /etc/yum.conf

installonly_limit=2
| improve this answer | |
  • After seeing Joel Davis's answer, I would also agree with him. Check to see what really is using all that space. – sparticvs Dec 13 '13 at 15:48
  • If you look at his ls and add up the files, it's about 25MB per kernel, mostly in initramfs. – cjm Dec 13 '13 at 15:58
  • Yea, I had a feeling it might be the initramfs files. The cleanup above should remove those as well. – sparticvs Dec 13 '13 at 15:59
  • @sparticvs, I checked -rw-r--r-- 1 root root 16191847 Sep 20 20:21 initramfs-2.6.32-358.18.1.el6.x86_64.img -rw-r--r-- 1 root root 16261655 Oct 21 15:06 initramfs-2.6.32-358.23.2.el6.x86_64.img -rw-r--r--. 1 root root 16187335 Sep 20 20:16 initramfs-2.6.32-358.el6.x86_64.img use a lot of space. – Tester Dec 13 '13 at 16:03
  • @sparticvs, can I do it right now? Do I need to reboot the system after doing that? Do I need to backup all my data? – Tester Dec 13 '13 at 16:05
2

Kernel images are actually really small:

[root@ditirlns01 ~]# ls -lh /boot/vmlinuz-2.6.18-3*
-rw-r--r-- 1 root root 2.2M May  4  2012 /boot/vmlinuz-2.6.18-308.8.1.el5xen
-rw-r--r-- 1 root root 2.2M Jul 27 01:43 /boot/vmlinuz-2.6.18-348.16.1.el5xen
-rw-r--r-- 1 root root 2.2M Mar 22  2013 /boot/vmlinuz-2.6.18-348.4.1.el5xen

There's more to the kernel package, obviously, but that's the part that's on /boot which is what your concern is.

So with a 100MB /boot partition, deleting a 2-3MB kernel probably isn't going to get you very far.

100MB is actually usually way more than people need. I would do enough du -sh invocations so you can see what's taking up all that space, because you shouldn't even be getting kind of close to using 100MB on that mount point:

[root@ditirlns01 ~]# df -h /boot
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1             99M   34M   60M  37% /boot

Which is with three kernels installed:

[root@ditirlns01 ~]# rpm -qa kernel*
kernel-xen-2.6.18-348.16.1.el5
kernel-xen-2.6.18-348.4.1.el5
kernel-headers-2.6.18-348.16.1.el5
kernel-xen-2.6.18-308.8.1.el5
[root@ditirlns01 ~]#

I'm willing to wager that someone put a file on /boot as a temporary move and forgot to move it back off later on.

| improve this answer | |
  • 3
    But there are the initramfs files, that are way bigger than the kernel files. Looking at @Don ls, they use 14MB. – user34720 Dec 13 '13 at 15:48
  • ah yeah I'm seeing that now. Oh well, I'll leave my answer up and just upvote your guys' – Bratchley Dec 13 '13 at 15:53
0

What should I do?

if you do a uname -a that will report your currently running version.

Per your posting I assume that is 2.6.32-358.23.2.el6.x86_64 is your current running version, so move all the old ones to some other partition where there is adequate space to save, do something like:

mkdir /root/oldkernels
mv   /boot/initramfs-2.6.32-358.18.1.el6.x86_64.img    /root/oldkernels

The /boot/efi/EFI/centos/grub.cfg file you want to check and it will be easy enough to read the menu code in it, the top one will be the default one you see when booting and also look for the rescue one; you will likely have numerous ones listed. It is here you can also verify what version you are actually running.

I typically just keep the latest one (at the top) and the rescue (at the bottom) in grub.cfg. Know the real grub.cfg (in your case because I see the efi folder) is in /boot/efi/EFI/centos/grub.cfg. You do not edit this file directly, but I would look at this file to verify the files being booted because it is this grub.cfg that is used when booting.

The rescue is typically the kernel version going back to system installation, which can be many versions prior to what you may be running now. For a rescue option, which is probably a good idea in the long run, you simply need to point it to a reliable and working version so the system will at least boot and you can edit files on the disk should a new kernel go belly up after install and not boot or not work. Basically you want at least 2 boot options in the grub menu, your latest one and then some reliable version to fall back on.

you edit /etc/default/grub.cfg and modify this file; make the the menu how you want simply by commenting out the ones you don't want with a #, then do a grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg

KDUMP is the problem

And from the initrd-2.6.32-358.18.1.el6.x86_64kdump.img files having kdump in the name, it looks like you have kdump enabled. Unless you use it, you can disable kdump which will help save space. And unless you are debugging system crashes and the like, you do not need the *kdump.img files so you can delete those. I don't use kdump, never have, but it is enabled by default during installation and I suspect by default saves to your /boot folder; which if only 100mb is bad. So either modify kdump to dump elsewhere, or you most likely don't use it so disable kdump.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.