Steps to Remove Old Kernels in Ubuntu (Debian Linux) to Free Space in boot?

Steps to Remove Old Kernels in Ubuntu (Debian Linux) to Free Space in boot?

Ubuntu is one of the most popular flavors of Linux. In this article, I am going to share all the commands you need to delete old kernel files and to free the boot directory space.

To find the disk space for boot directory, run command in terminal as

$ df -h

You can see the used and available space for the boot directory. If you don’t have enough space in boot directory you need to remove old kernels in Ubuntu or any Debian supported Linux system.

Related Read: How to Find Total Size of Directory in Linux?

So let’s begin…

Commands in this article work for all the Linux operating systems having Debian package managers such as Ubuntu, Linux Mint…

Why do you need to delete old kernel files?

While installing any package on Linux, you need some space in the boot directory.

If you are using Ubuntu for a long time, while installing any new application or package in Ubuntu, you might have faced the issue as “not enough space to install package”.

This is because there is no more or enough space to execute the installation of the new package.

If you run the command

cd /boot

in Terminal, you can see multiple kernels.

Usually, the boot directory contains all the files required by the operating system along with kernel files and boot loader.

Despite all the kernels in the boot, there is only one kernel running. To know the currently running kernel, open terminal and run following command.

$ uname -sr

Linux 4.8.0-36-generic

The command uname is helpful to get all the software and hardware related information about the system.

Where option…

  • s represents the name of the kernel
  • r represents the version of the kernel and release level

You can find more detail about this command at

When you boot your Ubuntu system, the current Linux kernel is loaded into memory.

How to find all the Kernal on your Ubuntu system?

To remove old kernels in Ubuntu, you just need a list of old kernels resides in your boot directory.

Run following command in terminal.

$ dpkg -l | grep linux-image | awk ‘{print$2}’



  • dpkg -l: list out all the installed packages on your system
  • grep linux-image: filter the list of files containing string “linux-image”
  • awk: is used to print the second column from the structured list which contains the name of packages.

In the system, dpkg is a package management tool for Debian based Linux system.

Additional kernels are there in case if you want to restore. It comes handy when you go back to the previous kernel.

If your newer kernel is not working properly, you can load the previous stable kernel.

How to remove old kernels in Ubuntu to free memory space in the boot?

You can delete all kernels except currently running one. You must be wide awake not to remove the running kernel.

So, first of all, find the currently running kernel using the command uname -sr mentioned above. Excepting this running kernel, you can delete all other old kernels.

Run command in terminal to delete and remove any particular old kernel.

$ sudo apt remove --purge linux-image-4.10.0-33-generic

After removing, you need to update the grub2 configuration.

$ sudo update-grub2

You can repeat the above two commands to remove other old kernels.

Reboot the system to apply the changes.

$ sudo reboot

To run above commands user needs root privilege. You can run this command using sudo keyword.

Now you can see, the performance of you system has drastically increased. You can also auto-remove all unused packages from your Linux to speed up your system.

The precaution you should take while deleting kernels:

  • Don’t delete currently running kernel.
  • It is recommended and good practice to keep at least one or two old kernels. If you get any problem you can go to the previous kernel.

Once you have deleted old kernels, you can check the memory space in the boot directory. There is free space available. Now you can manage, update or install any package on the Ubuntu system.

Related Read: How to Edit File if there is no vi, vim on Your Linux?

These are all commands you need to run to remove old kernels in Ubuntu or any Debian based Linux system. If you get any issue while running any of the commands, write in a comment. I can help you to get it resolved.


  1. Hi, thanks for writing this guide. I don’t see the date it was written though, and I think it is relevant because it might refer to older versions of Ubuntu. Whilst looking online, I saw other people saying doing a simple sudo apt autoremove suffices for removing old kernels as well.

    1. Hi Nicolae, you can autoremove old kernels as per your mentioned. If you delete any old version, you can not recover it back easily. So if you are not sure if any of the old kernels are useful or not, it is preferred to do it manually.

Leave a Reply

Your email address will not be published. Required fields are marked *