Linux

Removing Old Ubuntu Kernels: Free Up Disk Space

In this guide, you'll learn how to safely find and remove old, unused Linux kernel versions in Ubuntu to free up system partition space and keep your system clean.

Updated at February 16, 2026
5-10 min
Easy
FixPedia Team
Применимо к:Ubuntu 20.04 LTSUbuntu 22.04 LTSUbuntu 24.04 LTSDebian-based distributions

Introduction / Why This Is Needed

Each Linux kernel update in Ubuntu installs new linux-image and linux-headers packages. The old versions remain on the disk, occupying 100 to 300 MB each. Over time, they can accumulate gigabytes of "junk" in the /boot partition, leading to "No space left on device" errors when attempting to install updates.

This guide will show you how to safely find and remove obsolete kernel versions, freeing up space while retaining the ability to roll back to a previous stable version.

Prerequisites / Preparation

  1. Administrator privileges: All commands require sudo.
  2. Current kernel: You must know exactly which kernel is currently running. Deleting the active kernel will render the system unusable.
  3. Backup (recommended): Before performing mass package operations, it's wise to create a system snapshot (if you use Timeshift) or at least generate a list of packages to be removed.
  4. Internet: Not required, but may be needed to reinstall the kernel in case of an error.

Step 1: Identify the Current Active Kernel

First, find out which kernel version is currently in use. Open a terminal (Ctrl+Alt+T) and run:

uname -r

The output will look something like: 5.15.0-86-generic. Memorize or write down this version. This kernel must not be deleted.

You can also view the list of all kernels available for booting in the GRUB menu at system startup.

Step 2: View the List of All Installed Kernels

Now let's see which specific kernel and header packages are installed in the system. This will give you the full picture.

dpkg -l 'linux-image-*' | grep ^ii

Or a more readable variant:

apt list --installed 2>/dev/null | grep -E 'linux-image|linux-headers'

In the output, you will see a list of packages, for example:

  • linux-image-5.15.0-86-generic
  • linux-image-5.15.0-85-generic
  • linux-headers-5.15.0-86
  • linux-headers-5.15.0-85

Important: Packages related to your current kernel (from Step 1), and typically one previous one (the newest of the old versions) should be kept for rollback. Delete versions that are clearly obsolete (e.g., 5.15.0-50, 5.15.0-60, etc., if you are already on 86).

Step 3: Safe Automatic Removal via autoremove

The safest and simplest method is to let the system automatically identify unnecessary packages. APT marks packages as "automatically installed" and "no longer needed" when newer versions replace older ones.

Run the command:

sudo apt-get autoremove --purge

What it will do:

  • autoremove — removes packages that are no longer needed as dependencies (including old linux-image-* and linux-headers-* packages if they were automatically installed).
  • --purge — also removes the configuration files of these packages, providing maximum space savings.

Carefully review the list of packages that apt will propose to delete! Ensure that none of them match your current kernel version (uname -r). If the current kernel appears in the list — cancel the operation (Ctrl+C) and proceed to Step 4 for manual removal.

Step 4: Manual Removal of Specific Old Kernels (If Needed)

If autoremove missed some old kernels (e.g., they were installed manually), remove them manually.

  1. Compile a list of versions to remove. For example, you decide to remove kernels 5.15.0-50 and 5.15.0-55.
  2. For each version, execute the purge command:
sudo apt-get purge linux-image-5.15.0-50-generic linux-headers-5.15.0-50 linux-headers-5.15.0-50-generic
sudo apt-get purge linux-image-5.15.0-55-generic linux-headers-5.15.0-55 linux-headers-5.15.0-55-generic

Why purge? A regular remove leaves configs behind, while purge removes everything. For kernels, this is important because configuration files in /boot can occupy dozens of megabytes.

Tip: You can remove multiple versions in a single command by listing them separated by spaces.

Step 5: Update the GRUB Bootloader Configuration

After removing the packages, the kernel files are physically deleted from /boot, but the GRUB bootloader menu may still contain references to them. Update its configuration:

sudo update-grub

This command will scan /boot and generate a new menu containing only the currently installed kernels.

Verification

  1. Check free space on /boot:
    df -h /boot
    

    You should see a significant increase in free space (e.g., from 10% to 40-50%).
  2. Check the list of installed kernels (as in Step 2). Obsolete versions should be gone.
  3. Reboot the system (sudo reboot) and ensure it boots normally with the remaining kernel. At startup, the GRUB menu should show only relevant versions.

Potential Issues

Issue: apt-get autoremove tries to delete the current kernel

Cause: The system incorrectly marked packages, or you accidentally installed a new kernel but haven't rebooted yet. Solution:

  1. Cancel the operation.
  2. Reboot into the new kernel (uname -r will show you are on it).
  3. Run sudo apt-get autoremove again. Now the old kernels will be correctly identified as unnecessary.

Issue: After removing kernels, update-grub doesn't find new kernels

Cause: You may have accidentally deleted all kernels except one, or header packages (linux-headers) are left in an inconsistent state. Solution:

  1. Check that /boot contains files like vmlinuz-<version> and initrd.img-<version>.
  2. Reinstall the latest stable kernel: sudo apt-get install linux-generic.
  3. Run sudo update-grub again.

Issue: Not enough space even for autoremove

Cause: The /boot partition is 100% full, and apt cannot create temporary files to process packages. Solution:

  1. Temporary workaround: Manually delete the oldest kernel files from /boot (e.g., vmlinuz-5.15.0-50-generic, initrd.img-5.15.0-50-generic, config-5.15.0-50, System.map-5.15.0-50). Do this carefully, knowing exactly what you delete!
  2. After freeing up 50-100 MB, run sudo apt-get -f install and then sudo apt-get autoremove --purge to complete the process correctly.

Issue: System fails to boot after kernel removal

Cause: The only working kernel was deleted or GRUB is corrupted. Solution:

  1. Boot into Recovery Mode from the GRUB menu (option "Advanced options for Ubuntu").
  2. Select the fsck option to check the filesystem, then dpkg to repair packages.
  3. If that doesn't work, boot from a LiveCD, mount the root partition, and reinstall GRUB (chroot into the system, then run grub-install and update-grub).
  4. As a last resort, restore the deleted kernel files from a backup or reinstall the kernel using apt-get install.

F.A.Q.

Is it safe to manually remove old kernels?
Can automatic cleanup of old kernels be configured?
How does `apt-get autoremove` differ from `purge`?
What to do if the system fails to boot after removing kernels?

Hints

Identify the current active kernel
View the list of installed kernels
Remove unnecessary kernels via apt autoremove
Manually remove specific old kernels (if needed)
Update the GRUB bootloader configuration
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community