Tuesday, September 22, 2015

Remove all Ubuntu/Debian old kernel

After along time used, your Ubuntu/Debian /boot directory now full with many kernel version and you decide to clear all the old kernel just keep lasted version.

Here's the solution:
  1. Reboot your linux to make lasted kernel active
  2. Remove all the old kernel with command:
sudo dpkg -l 'linux-*-generic' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge

Check your /boot to make sure only one kernel (lasted) is there