Tuesday, January 24, 2012

Cleaning the boot partition in Ubuntu

Today I found a pop up message on one of my Ubuntu machines that said the boot partition was low on space. I did a search on the web for a cleaning solution for the boot partition and found this page:


Basically it is proposed a script for removing all unused Linux kernel headers, images and modules:

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

I found some flaws in this script so I came with this one trying to improve it:

dpkg -l 'linux-*' | \
# We only need the second column of the installed linux-* packages list
awk '/^ii/ { print $2 } ' | \
# Take out the packages with the number of the running kernel 
grep -v $(uname -r | sed 's/\([0-9.-]\+\)-[^0-9]\+/\1/') | \
# The -v force me into this extra line
grep '[0-9]' | \
xargs sudo apt-get -y purge

Later I'll try to improve it a little bit more.

No comments: