Remove Old Kernel Images on Ubuntu

From Bonus Bits
Jump to: navigation, search

Purpose

This article gives the steps to remove old kernel images on Ubuntu.


Environment

  • Ubuntu Desktop 17.10


Remove Installed Kernel Packages

  1. Open Terminal (Ctrl+Alt+T).
  2. List currently running kernel (reboot if a new one has been installed recently and was not rebooted)
    uname -r
    
  3. Take note of the running kernel (Do not remove)
  4. List all kernel images currently installed
    dpkg --list | grep linux-image
    
  5. Take note of all the older kernel images
  6. Remove each old image with apt-get
    sudo apt purge linux-image-4.10.0-19-generic
    
  7. Update the bootloader config GRUB
    sudo update-grub2
    


One-Liner

dpkg --get-selections | grep linux-image | grep -v $(uname -r) | grep -v linux-image-generic | awk -F" " '{print $1}' | xargs -n1 sudo apt -y purge
 sudo apt -y autoremove && sudo update-grub2


Remove apt Downloaded Sources

sudo apt autoremove


Related Articles