Topic: Removing a specific kernel
I know that there have been a few posts already in regards to getting rid of unused kernels, but I thought I'd give my solution just out of boredom's sake! This isn't geared towards efficiency, as there are intended speed bumps to ease my paranoia of just shooting around two commands and calling it done. I use the testing branch so I know I will be using this in the future and many around here use liquorix so perhaps it will be helpful to someone else as well.
Couple of side notes:
*Checks to see if you are UID 0, as I don't like sudo (not sure how this will effect you guys).
*Removes the kernel with aptitude rather than apt-get, also because of personal preference.
#!/usr/bin/perl
use strict;
use warnings;
my @kernel_list;
my $count = 1;
my ($index, $choice);
#End script if not running as root
if($< != 0){ die "Are you running as root...?\n" }
print "**Input is not validated, please enter carefully!**\n";
#Find list of installed kernels
chomp( @kernel_list = `dpkg --list | grep linux-image | awk '{print \$2}'` );
print "\nThe following kernels have been detected:\n";
map{ print "\t$count.\) $_\n"; $count++; } @kernel_list;
#Find/validate selection
print "\nEnter *numeric* selection to be marked for removal: ";
chomp( $index = <STDIN> );
$index -= 1;
print "\nThe kernel '$kernel_list[$index]' will be removed.\n".
"Is this correct? [Y/n]: ";
chomp( $choice = <STDIN> );
if( $choice eq "Y" ){
print "Invoking aptitude...\n";
sleep(1);
system("aptitude purge $kernel_list[$index]");
}
else{
die "Exiting, nothing has changed.\n";
}