Skip to content

Instantly share code, notes, and snippets.

@dtsdwarak
Last active October 30, 2015 07:47
Show Gist options
  • Save dtsdwarak/f4efc287c552a3d3f9ff to your computer and use it in GitHub Desktop.
Save dtsdwarak/f4efc287c552a3d3f9ff to your computer and use it in GitHub Desktop.
Remove a version of kernel specified. (Run as root)
## Ubuntu/Debian compatible. Run as $ su -c ./remove_kernel.sh
#!/bin/bash
echo "Enter the kernel name : "
read kernel_name
echo "****************************"
echo "Removing $kernel_name kernel"
echo "****************************"
if [ $(uname -r) == $kernel_name ]
then
echo "** ERROR: You are trying to remove the current kernel. Boot into someother kernel and proceed **"
exit 1
fi
rm /boot/vmlinuz-$kernel_name
if [ $? -eq 0 ]; then
echo "DELETED: vmlinuz-$kernel_name"
fi
rm /boot/initrd.img-$kernel_name
if [ $? -eq 0 ]; then
echo "DELETED: initrd.img-$kernel_name"
fi
rm /boot/System.map-$kernel_name
if [ $? -eq 0 ]; then
echo "DELETED: System.map-$kernel_name"
fi
rm /boot/config-$kernel_name
if [ $? -eq 0 ]; then
echo "DELETED: config-$kernel_name"
fi
rm -rf /lib/modules/$kernel_name
if [ $? -eq 0 ]; then
echo "DELETED: /lib/modules/$kernel_name"
fi
update-grub
echo "Grub update complete"
echo "****************************"
echo "REMOVED: $kernel_name kernel"
echo "****************************"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment