Remove Old Linux Kernels

Post Reply
User avatar
Eli
Senior Expert Member
Reactions: 185
Posts: 5455
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#1

Removing old kernels is easy to do on a system with enough free space in the root partition or separate boot partition. You can remove them manually, or configure unattended-upgrades to do it automatically. If you receive or have received an error from a package management tool, such as

  1. Error Could not scan some of the folders contained in "/boot"
  2. Error opening directory ‘/boot/lost+found’: Permission denied


or the message

  1. The upgrade needs a total of 97.4 M free space on disk '/boot'. Please free at least an additional 33.8 M of disk space on '/boot'. You can remove old kernels using 'sudo apt autoremove', and you could also set COMPRESS=xz in /etc/initramfs-tools/initramfs.conf to reduce the size of your initramfs.


during software upgrade, manually removing old kernels may not work until such problems are fixed, see RemoveOldKernels.

Such errors as these are usually caused by old kernels and other files that eat a lot of space.

To free your system space, you can empty Trash as follows:

  1. sudo -i
  2. sudo rm -rf ~/.local/share/Trash/*


This may not be enough to give your system a sufficient space for proper functioning, you need to remove old kernels if any - or at least the ones you don't want (they can greatly impair system performance such as causing slow boot). Use

$uname -r to find out the newest kernel.

You can get the list of kernels and all kernel-related packages by

$apt list --installed | grep linux

You will see an output similar to this

  1. console-setup-linux/xenial-updates,xenial-updates,now 1.108ubuntu15.4 all [installed,automatic]
  2. libselinux1/xenial,now 2.4-3build2 amd64 [installed]
  3. libselinux1-dev/xenial,now 2.4-3build2 amd64 [installed]
  4. linux-base/xenial-security,xenial-security,xenial-updates,xenial-updates,now 4.5ubuntu1~16.04.1 all [installed,automatic]
  5. linux-firmware/now 1.157.19 all [installed,upgradable to: 1.157.20]
  6. linux-generic/now 4.4.0.127.133 amd64 [installed,upgradable to: 4.4.0.132.138]
  7. linux-headers-3.13.0-110/now 3.13.0-110.157 all [installed,local]
  8. linux-headers-3.13.0-128/now 3.13.0-128.177 all [installed,local]
  9. linux-headers-3.13.0-133/now 3.13.0-133.182 all [installed,local]
  10. linux-headers-3.13.0-147/now 3.13.0-147.196 all [installed,local]
  11. linux-headers-4.4.0-124/xenial-security,xenial-security,xenial-updates,xenial-updates,now 4.4.0-124.148 all [installed,automatic]
  12. linux-headers-4.4.0-124-generic/xenial-security,xenial-updates,now 4.4.0-124.148 amd64 [installed,automatic]
  13. linux-headers-4.4.0-125/now 4.4.0-125.150 all [installed,local]
  14. linux-headers-4.4.0-125-generic/now 4.4.0-125.150 amd64 [installed,local]
  15. linux-headers-4.4.0-127/xenial-security,xenial-security,xenial-updates,xenial-updates,now 4.4.0-127.153 all [installed,automatic]
  16. linux-headers-4.4.0-127-generic/xenial-security,xenial-updates,now 4.4.0-127.153 amd64 [installed,automatic]
  17. linux-headers-generic/now 4.4.0.127.133 amd64 [installed,upgradable to: 4.4.0.132.138]
  18. linux-image-4.4.0-124-generic/xenial-security,xenial-updates,now 4.4.0-124.148 amd64 [installed,automatic]
  19. linux-image-4.4.0-125-generic/now 4.4.0-125.150 amd64 [installed,local]
  20. linux-image-4.4.0-127-generic/xenial-security,xenial-updates,now 4.4.0-127.153 amd64 [installed,automatic]
  21. linux-image-extra-4.4.0-124-generic/xenial-security,xenial-updates,now 4.4.0-124.148 amd64 [installed,automatic]
  22. linux-image-extra-4.4.0-125-generic/now 4.4.0-125.150 amd64 [installed,local]
  23. linux-image-extra-4.4.0-127-generic/xenial-security,xenial-updates,now 4.4.0-127.153 amd64 [installed,automatic]
  24. linux-image-generic/now 4.4.0.127.133 amd64 [installed,upgradable to: 4.4.0.132.138]
  25. linux-libc-dev/now 4.4.0-127.153 amd64 [installed,upgradable to: 4.4.0-132.158]
  26. linux-sound-base/xenial,xenial,now 1.0.25+dfsg-0ubuntu5 all [installed]
  27. pptp-linux/xenial,now 1.8.0-1 amd64 [installed]
  28. syslinux/xenial,now 3:6.03+dfsg-11ubuntu1 amd64 [installed]
  29. syslinux-common/xenial,xenial,now 3:6.03+dfsg-11ubuntu1 all [installed]
  30. syslinux-legacy/xenial,now 2:3.63+dfsg-2ubuntu8 amd64 [installed]
  31. util-linux/xenial-updates,now 2.27.1-6ubuntu3.6 amd64 [installed]


If you know how to identify the old kernels and their related packages, you can use apt-get command or Synaptic Package Manager to remove them.

Using apt-get, you can remove old kernels with a simple autoremove --purge command in a Terminal:

$sudo apt-get autoremove --purge

An alternative is to use a handy tool to purge old kernels which is shipped with the byobu package on Ubuntu 16.04 or higher.

  1. sudo apt-get install byobu
  2. sudo purge-old-kernels

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Return to “Linux and Unix Based Operating Systems”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 0 guests