Purging old Kernels from Ubuntu

I have often ran into the trouble of not enough space in my /boot directory when I am processing updates. For others who have run into this issue here is how to purge old kernels from your system and grub configuration.

 

While updating servers you may run into an error like this

Errors were encountered while processing:

 /var/cache/apt/archives/linux-image-3.8.0-39-generic_3.8.0-39.58~precise1_i386.deb

 /var/cache/apt/archives/linux-image-3.8.0-42-generic_3.8.0-42.62~precise1_i386.deb

E: Sub-process /usr/bin/dpkg returned an error code (1)

Usually this means the /boot partition is full of old kernels you can check by doing:

#> df -h

Filesystem                    Size  Used Avail Use% Mounted on

/dev/mapper/backups–vg-root  133G   35G   92G  28% /

udev                          747M  4.0K  747M   1% /dev

tmpfs                         151M  452K  151M   1% /run

none                          5.0M     0  5.0M   0% /run/lock

none                          755M   68K  755M   1% /run/shm

/dev/sda1                     228M  227M     0 100% /boot

/dev/sdb1                     826G  181G  603G  24% /amhold

Notice /boot is 100% full

Step 1

#> uname -r (do not delete this kernel this is the running kernel)

Step 2

#> dpkg –list | grep linux-image

Step 3

#> apt-get purge linux-image-x.x.x.x-generic (replace the x with the kernel number)

Repeat with all old kernels I usually leave the one right before the latest

Step 4 (this removes any files associated with the old kernels so basically cleanup)

#> apt-get autoremove

Step 5

#> update-grub2

This entry was posted in Linux How-To. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *