Distro-provided mechanism to clean up old kernels
Tim Edwards
liststuff at fastmail.com.au
Fri Feb 17 10:49:14 UTC 2012
On Fri, Feb 17, 2012, at 07:23 AM, Martin Pitt wrote:
> linux-headers-* is already covered by apt-get autoremove, which is
> good. Perhaps we can mark older kernels as auto-removable as well, so
> that without any other tools you at least have one command to clean
> them up all?
Are you sure about this? I did a test and I don't think that autoremove
removes the linux-headers-*:
$ dpkg -l | awk '/^ii/{print $2}' | grep ^linux
linux-firmware
linux-generic
linux-headers-3.0.0-14
linux-headers-3.0.0-14-generic
linux-headers-3.0.0-15
linux-headers-3.0.0-15-generic
linux-headers-3.0.0-16
linux-headers-3.0.0-16-generic
linux-headers-generic
linux-image-3.0.0-15-generic
linux-image-3.0.0-16-generic
linux-image-generic
linux-libc-dev
linux-sound-base
$ sudo apt-get autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 10 not upgraded.
I'd like to suggest instead the following modifications to the script
that was posted before:
#!/bin/bash
OLDKERNEL=$(ls -tr /boot/vmlinuz-* | head -n -2 | cut -d- -f2- | awk
'{print "linux-image-" $0}')
OLDHEADERS=$(ls -tr /boot/vmlinuz-* | head -n -2 | cut -d- -f2- | sed
's/-generic//g' | awk '{print "linux-headers-" $0}')
if [ -n "$OLDKERNEL" -o -n "$OLDHEADERS" ]; then
sudo apt-get -q remove --purge $OLDKERNEL $OLDHEADERS
fi
(note that this version is not fully automatic as apt will prompt the
user before removing packages)
Tim
More information about the ubuntu-server
mailing list