Removing Older Kernels (SOLVED)
Posted: Wed Apr 13, 2011 1:04 pm
I checked Google for info on removing older kernels from Debian systems. Most of what I found was dated material. Two recent entries included:
http://stoilis.wordpress.com/2010/06/18 ... ributions/ which showcased the following script to remove old kernels.
#!/bin/bash -x
CURRENT_KERNEL=`uname -r | awk -F- ‘{print $1}’`
cd /boot
NUMBER_OF_INSTALLED_KERNELS=`ls vmlinuz* | grep -v $CURRENT_KERNEL | wc -l`
if [ "$NUMBER_OF_INSTALLED_KERNELS" -lt "2" ]
then
echo “Nothing to do. Exiting.”
exit
fi
INSTALLED_KERNELS=`ls vmlinuz* | grep -v $CURRENT_KERNEL | head -n $(($INSTALLED_KERNELS-1))`
echo $INSTALLED_KERNELS
for a in $INSTALLED_KERNELS
do
a=”`echo $a | awk -F- ‘{print $2″-”$3}’`”
if [ "$KERNELS_TO_REMOVE" == "" ]
then
KERNELS_TO_REMOVE=$a
else
KERNELS_TO_REMOVE=”$KERNELS_TO_REMOVE|$a”
fi
done
apt-get remove -y –purge `dpkg -l | awk ‘{print $2}’ | egrep “$KERNELS_TO_REMOVE”`
The second site: http://www.unixmen.com/linux-tutorials/ ... ed-systems
showcased this code:
sudo apt-get remove $(dpkg -l|egrep '^ii linux-(im|he)'|awk '{print $2}'|grep -v `uname -r`)
Has anyone tried either of these methods and do they work? Are there other methods?
http://stoilis.wordpress.com/2010/06/18 ... ributions/ which showcased the following script to remove old kernels.
#!/bin/bash -x
CURRENT_KERNEL=`uname -r | awk -F- ‘{print $1}’`
cd /boot
NUMBER_OF_INSTALLED_KERNELS=`ls vmlinuz* | grep -v $CURRENT_KERNEL | wc -l`
if [ "$NUMBER_OF_INSTALLED_KERNELS" -lt "2" ]
then
echo “Nothing to do. Exiting.”
exit
fi
INSTALLED_KERNELS=`ls vmlinuz* | grep -v $CURRENT_KERNEL | head -n $(($INSTALLED_KERNELS-1))`
echo $INSTALLED_KERNELS
for a in $INSTALLED_KERNELS
do
a=”`echo $a | awk -F- ‘{print $2″-”$3}’`”
if [ "$KERNELS_TO_REMOVE" == "" ]
then
KERNELS_TO_REMOVE=$a
else
KERNELS_TO_REMOVE=”$KERNELS_TO_REMOVE|$a”
fi
done
apt-get remove -y –purge `dpkg -l | awk ‘{print $2}’ | egrep “$KERNELS_TO_REMOVE”`
The second site: http://www.unixmen.com/linux-tutorials/ ... ed-systems
showcased this code:
sudo apt-get remove $(dpkg -l|egrep '^ii linux-(im|he)'|awk '{print $2}'|grep -v `uname -r`)
Has anyone tried either of these methods and do they work? Are there other methods?