Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

My /boot partition is nearly full and I get a warning every time I reboot my system. I already deleted old kernel packages (linux-headers...), actually I did that to install a newer kernel version that came with the automatic updates. After installing that new version, the partition is nearly full again. So what else can I delete? Are there some other files associated to the old kernel images?

Here is a list of files that are on my /boot partition:

:~$ ls /boot/
abi-2.6.31-21-generic         lost+found
abi-2.6.32-25-generic         memtest86+.bin
abi-2.6.38-10-generic         memtest86+_multiboot.bin
abi-2.6.38-11-generic         System.map-2.6.31-21-generic
abi-2.6.38-12-generic         System.map-2.6.32-25-generic
abi-2.6.38-8-generic          System.map-2.6.38-10-generic
abi-3.0.0-12-generic          System.map-2.6.38-11-generic
abi-3.0.0-13-generic          System.map-2.6.38-12-generic
abi-3.0.0-14-generic          System.map-2.6.38-8-generic
boot                          System.map-3.0.0-12-generic
config-2.6.31-21-generic      System.map-3.0.0-13-generic
config-2.6.32-25-generic      System.map-3.0.0-14-generic
config-2.6.38-10-generic      vmcoreinfo-2.6.31-21-generic
config-2.6.38-11-generic      vmcoreinfo-2.6.32-25-generic
config-2.6.38-12-generic      vmcoreinfo-2.6.38-10-generic
config-2.6.38-8-generic       vmcoreinfo-2.6.38-11-generic
config-3.0.0-12-generic       vmcoreinfo-2.6.38-12-generic
config-3.0.0-13-generic       vmcoreinfo-2.6.38-8-generic
config-3.0.0-14-generic       vmcoreinfo-3.0.0-12-generic
extlinux                      vmcoreinfo-3.0.0-13-generic
grub                          vmcoreinfo-3.0.0-14-generic
initrd.img-2.6.31-21-generic  vmlinuz-2.6.31-21-generic
initrd.img-2.6.32-25-generic  vmlinuz-2.6.32-25-generic
initrd.img-2.6.38-10-generic  vmlinuz-2.6.38-10-generic
initrd.img-2.6.38-11-generic  vmlinuz-2.6.38-11-generic
initrd.img-2.6.38-12-generic  vmlinuz-2.6.38-12-generic
initrd.img-2.6.38-8-generic   vmlinuz-2.6.38-8-generic
initrd.img-3.0.0-12-generic   vmlinuz-3.0.0-12-generic
initrd.img-3.0.0-13-generic   vmlinuz-3.0.0-13-generic
initrd.img-3.0.0-14-generic   vmlinuz-3.0.0-14-generic

Currently, I'm using the 3.0.0-14-generic kernel.

share|improve this question

12 Answers 12

up vote 140 down vote accepted

You've a lot unused kernels. Remove all but the last kernels with:

sudo apt-get purge linux-image-{3.0.0-12,2.6.3{1-21,2-25,8-{1[012],8}}}

This is shorthand for:

sudo apt-get purge linux-image-3.0.0-12 linux-image-2.6.31-21 linux-image-2.6.32-25 linux-image-2.6.38-10 linux-image-2.6.38-11 linux-image-2.6.38-12 linux-image-2.6.38-8

Removing the linux-image-x.x.x-x package will also remove linux-image-x.x.x-x-generic.

The headers are installed into /usr/src and are used when building out-tree kernel modules (like the proprietary nvidia driver and virtualbox). Most users should remove these header packages if the matching kernel package (linux-image-*) is not installed.

To list all installed kernels, run:

dpkg -l linux-image-\* | grep ^ii

One command to show all kernels and headers that can be removed, excluding the current running kernel:

kernelver=$(uname -r | sed -r 's/-[a-z]+//')
dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve $kernelver

It selects all packages named starting with linux-headers-<some number> or linux-image-<some number>, prints the package names for installed packages and then excludes the current loaded/running kernel (not necessarily the latest kernel!). This fits in the recommendation of testing a newer kernel before removing older, known-to-work kernels.

So, after upgrading kernels and rebooting to test it, you can remove all other kernels with:

sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")
share|improve this answer
2  
Fantastic answer. One further piece of info would help: How can you tell (for sure) which of the kernels you're using? Presumably you can't just assume it's the last one... Edit: And it looks like the answer is uname -a. Probably best to ensure you don't have a pending restart-to-install-new-kernel pending (as I did; but I noted the mismatch between uname -a and the "latest" kernel). –  T.J. Crowder Jun 14 '12 at 8:39
    
The currently loaded kernel is indeed visible by executing uname -a. (you can extract the kernel version part with uname -r as often combined with sth like sudo apt-get install linux-headers-$(uname -r)). You can check the kernel that will be loaded on the next boot by checking the boot config, typically /boot/grub/grub.cfg. –  Lekensteyn Jun 14 '12 at 11:06
1  
@freddyb Done. Note that the commands prints/removes kernels other than the loaded/booted one. –  Lekensteyn Aug 13 '12 at 13:57
2  
@Lekensteyn For me, the GUI warning that /boot is running full comes mostly after upgrades. So you say this would also remove the latest one, that hasn't been booted yet? :/ –  freddyb Sep 20 '12 at 9:58
1  
If apt-get purge fails because of unmet dependencies then you can follow the advice at askubuntu.com/questions/171209/… –  svandragt Aug 7 '13 at 8:33

Your boot partition is full. Since this is a kernel update, these files will be copied to the boot partition so you need to clean in out. Here is a blog post that will show you how to clear the old kernel images with one command. I'll give a basic synopsis of the method. Use this command to print out the current version of your kernel:

uname -r

Then use this command to print out all the kernels you have installed that aren't your newest kernel:

dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9]

Make sure your current kernel isn't on that list. Notice how this is the majority of the final command (down below). To uninstall and delete these old kernels you will want to pipe these arguments to:

sudo apt-get -y purge

Now we can do everything we want by combining these last two commands into this unholy mess:

dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y purge

And that one command will take care of everything for you. I will confirm that this does work perfectly but never trust anybody on the internet. :) For more info, the blog post gives a very good explanation of what each part of the command does so read through it so you are satisfied that it does what you want it to do.

share|improve this answer
2  
This worked great, thanks. –  Michael Durrant Feb 21 '13 at 3:59
    
this also matches linux-libc-dev:amd64 –  Frederick Nord Aug 29 at 16:39

Thank you for your detailed post of your problem, this got me going in the right direction. Although it is useful to keep previous kernel files you can remove all of them in one go, check this post:
How to Remove All Unused Linux Kernel Headers, Images and Modules

Done via command line. If you are doing this via remote use something like WINSCP to open a terminal session and just paste it in, works very well.

Here it is copied from article link, I suggest you read the full article:

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
share|improve this answer

enter image description here

If you haven't already got synaptic manager installed:

sudo apt-get install synaptic

Start the application and select the options shown.

You should be able to highlight all the "linux-" packages with the version "2.6.x" where x is between 31 to 38 according to the files in your /boot folder.

Right-click each of those linux packages and choose the option "Mark for Complete Removal". Finally click the apply button. This will remove all the files and any associated files. Your /boot folder should now be a bit-more tidier.

share|improve this answer

I was able to fix the problem by using dpkg to remove the packages directly. Although the packages are still listed in dpkg -l, the files are removed from /boot, freeing up space.

phrogz@planar:/boot$ sudo dpkg --remove linux-image-2.6.32-30-server
(Reading database ... 145199 files and directories currently installed.)
Removing linux-image-2.6.32-30-server ...
Running postrm hook script /usr/sbin/update-grub.
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.32-35-server
Found linux image: /boot/vmlinuz-2.6.32-34-server
Found initrd image: /boot/initrd.img-2.6.32-34-server
Found linux image: /boot/vmlinuz-2.6.32-33-server
Found initrd image: /boot/initrd.img-2.6.32-33-server
Found linux image: /boot/vmlinuz-2.6.32-32-server
Found initrd image: /boot/initrd.img-2.6.32-32-server
Found linux image: /boot/vmlinuz-2.6.32-31-server
Found initrd image: /boot/initrd.img-2.6.32-31-server
Found memtest86+ image: /memtest86+.bin
done

# Repeat for kernels -31 and -32 and -33, up to (but not including)
# the version listed by `uname -a`

After this, apt-get -f install fixed my dependency problems, and all was well with the world.

I'll not be accepting this answer of mine, however, as I still need to know if I should be increasing my /boot size or doing something else.

share|improve this answer
    
You should either not have a separate /boot partition in the first place, or you should increase its size as 100mb is too small. –  psusi Dec 4 '11 at 4:07
    
Thanks, I delete via: sudo dpkg --remove linux-headers-3.5.0-28* –  TiloBunt Jul 16 '13 at 17:34
    
and sudo dpkg --remove linux-image-3.5.0-28* for the image, checked via df -h –  TiloBunt Jul 16 '13 at 17:57

You can stop using a separate /boot partition, then you won't have such limited space there. To do this, unmount the partition, then mount it somewhere else and copy all of the files there to the /boot directory in your root partition, then remove the entry from /etc/fstab and reinstall grub. For example ( you will need to use the correct partition ):

sudo -s
umount /boot
mount /dev/sda2 /mnt
cp -a /mnt/* /boot/
umount /mnt
gedit /etc/fstab
grub-install /dev/sda

You can then use gparted to delete the old /boot partition, and possibly extend the root partition to use that space. To extend the root partition you will need to boot from the livecd, and the free space needs to be immediately to the right. If the /boot partition is currently to the left of the root partition, then you will need to first move the root partition to the left, then extend it, but this can take a very, very long time, so may not be worth the trouble.

share|improve this answer
1  
Moving /boot to my main partition isn't a solution for me since everything but /boot is encrypted. You couldn't know that from my question, sorry. –  user6722 Dec 24 '11 at 14:15
    
This is a good solution if the solutions above don't work due to having no space at all on the boot volume, or if you repeatedly have the "out of space" issue. Please read first why it's sometimes required to have a /boot partition though: (help.ubuntu.com/community/DiskSpace) –  svandragt Jul 10 at 8:26
    
@svandragt, there basically is no reason left to need a /boot partition these days. About the only one left is if your bios is broken and can't see the whole disk, and any machine made in the last decade doesn't have such a limitation. Other legacy cases such as using raid or LVM are now handled properly by grub2. –  psusi Jul 11 at 1:59
apt-get autoremove

This command is doing the job automatically.

share|improve this answer
2  
As the name suggests, apt-get AUTOremove is an automated operation where the system takes its "best guess" what you are trying to achieve. It should not be used as a substitute for common sense system administration. The problem with this approach: If you (or an update) removes a package that is part of this dependency list the auto-remove function wants to remove all other packages in the dependency list, leaving you with a system without working desktop (and sometimes even with a completely broken system). –  Rinzwind Nov 5 '12 at 10:09
    
Reference: 1 of many sources for this comment above: linuxquestions.org/questions/debian-26/… –  Rinzwind Nov 5 '12 at 10:10
2  
This will not remove old kernels. –  orkoden Oct 14 '13 at 9:23

I already deleted old kernel packages (linux-headers...)

linux-headers-* aren't kernels. Kernel packages are the ones named linux-image-*. The ones named linux-headers-* are development packages for compiling kernel modules: they don't live in the /boot directory and are not required for general day to day use of your system.

The files you listed in /boot do include several old kernel images (vmlinuz*) and compiled initrd images (initrd.img*) for those kernels, which is an indication that you still have a lot of old kernel packages installed.

You should be able to list your installed kernels with

aptitude search ~ilinux-image

(Note that this will probably return packages that aren't kernels, too).

There is usually no need for more than two kernels to be installed - the one currently in use and the previous one to that (as a fallback). So you can start removing the older ones, one by one, like this:

sudo apt-get autoremove linux-image-3.2.0-23-generic

Make sure you substitute "3.2.0-23-generic" with the actual kernel version you want to remove! Also, don't remove packages such as linux-image-generic. You have to be really careful not to remove the currently running kernel or you won't be able to boot (Ubuntu may or may not warn you about doing this).

You can find your currently running kernel with:

uname -r
share|improve this answer

I suggest to

  • move some of the huge files in /boot relative to older kernel to some other partition,

  • fix the problem,

  • put back the files in their place,

  • remove old and unused kernel (keeping the newer two is enough)

I do not suggest to increase /boot, but check regularly the space on it and remove old kernel when not needed.

share|improve this answer
2  
You suggest to: fix the problem ? Well he asks how to ... –  WitchCraft Aug 4 '12 at 13:03

In aptitude or synaptic there is a section "old or manually installed packaged". There should be the old linux packages there.

share|improve this answer

For me both apt-get purge and dpkg --remove both failed. So I had to deleted a couple of older kernel images from /boot with rm -f.

share|improve this answer
    
This is not a good way to remove packages. While this answer isn't very specific about why removing them the correct way failed, I'm sure if that information was given (in a separate question of course) we'd be able to try and figure out the cause of the problem. –  neon_overload Aug 29 at 9:55

There's a bash script which I wrote give below that makes the process a bit more user-friendly.

YMMV - it was made for Mint 14. Still learning BASH so it's probably a bit clunky. Use at own risk, but it works for me!

#!/bin/bash

endCol='\e[0m'
bold_red='\e[1;31m'
bold_green='\e[1;32m'
bold_yellow='\e[1;33m'

title_color='\e[0;30;47m'

function show_kernel_info {
clear
current_kernel=$(uname -r)
echo "Current ACTIVE kernel is:"
echo -e "  "$bold_yellow$current_kernel$endCol
echo "This kernel will be TOTALLY EXCLUDED from all actions in this script."
echo "Also, one fallback non-active kernel will be always left untouched."
echo ""
echo "These are the non-active kernels stored in /boot:"
count_of_old_kernels_in_boot=$(ls -o /boot/initrd* | grep -c -v "$current_kernel")
if [ $count_of_old_kernels_in_boot = 0 ]; then
  echo " * No non-active kernels found! *"
else
  ls -o /boot/initrd* | grep -v "$current_kernel"
fi
echo ""
list_of_old_kernels=$(dpkg --list | grep linux-image | awk -F' ' '{ print $2 }' | grep -v "$current_kernel" | grep -v "linux-image-generic")
current_old_kernel=$(dpkg --list | grep linux-image | awk -F' ' '{ print $2 }' | grep -v "$current_kernel" | grep -v "linux-image-generic" | head -n 1)
count_of_old_kernels_installed=$(dpkg --list | grep linux-image | awk -F' ' '{ print $2 }' | grep -v "$current_kernel" | grep -c -v "linux-image-generic")
echo "Listing of all unused kernels still installed in the system (these may not exist in /boot):"
if [ $count_of_old_kernels_installed = 0 ]; then
  echo " * No unused kernel installs found! *"
else
  dpkg --list | grep linux-image | awk -F' ' '{ print $2 }' | grep -v "$current_kernel" | grep -v "linux-image-generic"
fi
echo ""
}

function exit_script {
free_space_after=$(df -BM /boot | tail -n 1 | awk -F' ' '{ print $4 }' | tr -d M)
let freed_space=$free_space_after-$free_space_before
echo ""
echo "Results (in MB)"
echo "---------------"
echo "Free space in /boot before script was run: "$free_space_before
echo "Free space now: "$free_space_after
echo ""
echo "Amount of space freed up = "$freed_space
echo ""
echo "Press any key to exit."
read -s -n 1
echo ""
exit
}

# Main code
echo ""
echo -e $title_color" --------------------------- "$endCol
echo -e $title_color" -   Kernel Cleanup v1.0   - "$endCol
echo -e $title_color" --------------------------- "$endCol
echo ""
echo "Maximise this window for readability."
echo "Press any key to continue."
read -s -n 1
echo ""
echo "This script will remove old unused kernels, but it will prompt you before removing each one."
echo "It will never remove the current running kernel, and will also leave one fallback kernel."
echo "It can also remove source files from /usr/src for each kernel removed."
echo "This is normally safe to do and will free up lots more space."
echo ""
echo "Do you want that done as well? (y/n, enter=yes)"
valid_input=0
while [ "$valid_input" = "0" ]; do
  read -s -n 1 YesNo_input
  if [ "$YesNo_input" = "" ]; then
    YesNo_input="y"
  fi
  case $YesNo_input
  in
    y)
    RemoveSource="y"
    valid_input=1
    ;;

    Y)
    RemoveSource="y"
    valid_input=1
    ;;

    n)
    RemoveSource="n"
    valid_input=1
    ;;

    N)
    RemoveSource="N"
    valid_input=1
    ;;
  esac
done

free_space_before=$(df -h /boot | tail -n 1 | awk -F' ' '{ print $4 }' | tr -d M)
show_kernel_info
while [ $count_of_old_kernels_in_boot -gt 1 ]; do
  # failsafe check if somehow the current kernel is about to be removed!
  if [ "$current_old_kernel" = "$current_kernel" ]; then
    echo -e $bold_red"ERROR!"$endCol" Somehow the current kernel has crept into the removal process!"
    echo "I refuse to do that! Aborting script."
    exit_script
  fi
  # failsafe check if somehow a linux-image-generic entry is about to be removed
  if [ "$current_old_kernel" = "linux-image-generic" ]; then
    echo -e $bold_red"ERROR!"$endCol" Somehow one of the linux-image-generic entries has crept into the removal process!"
    echo "I refuse to do that! Aborting script."
    exit_script
  fi
  echo "Command about to be executed is:"
  echo "  $ sudo apt-get purge \"$current_old_kernel\""
  check_in_boot=$(echo $current_old_kernel | sed 's/linux-image/initrd.img/g')
  if [ -e /boot/$check_in_boot ]; then
    echo -e $bold_yellow"Note:"$endCol" This kernel exists in /boot but it NON-active, so it's OK to remove."
  else
    echo -e $bold_green"Totally safe to remove:"$endCol" This kernel does NOT exist in /boot."
  fi
  echo ""
  echo "Are you sure you want to remove this kernel?"
  echo "(*upper case* Y=yes / any other key will exit the script)"
  read -s -n 1 yes_no
  echo ""
  # Only entering a single upper case Y will work!
  if [ "$yes_no" != "Y" ]; then
    echo "Aborting script."
    exit_script
  fi
  echo "Removing kernel "$current_old_kernel"..."
  sleep 1
  sudo apt-get -y purge $current_old_kernel
  if [ "$RemoveSource" = "y" ]; then
    current_old_source=$(echo $current_old_kernel | sed 's/linux-image/linux-headers/g')
    current_old_source=$(echo $current_old_source | sed 's/-generic//g')
    current_old_source=$(echo $current_old_source | sed 's/-pae//g')
    sudo apt-get -y purge $current_old_source
  fi
  show_kernel_info
done

if [ $count_of_old_kernels_in_boot = 0 ]; then
  echo -e $bold_red"There are no NON-active kernels to remove!"$endCol
else
  echo -e $bold_red"There is only one NON-active kernel left in /boot!"$endCol
  echo "This script will not remove the last non-active kernel so that you have at least one backup kernel."
fi
echo "Aborting script."
exit_script
share|improve this answer

protected by Community May 4 at 15:22

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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