- Удаление старых ядер в Debian и Ubuntu
- How to remove old kernels from Debian 11
- Linux kernel
- What are the functions of a Linux kernel
- How to check current version of kernel on Debian 11
- How to list the installed kernels on Debian 11
- How to remove old kernels from Debian 11
- Conclusion
- About the author
- Sharqa Hameed
- How to Delete Old Unused Kernels in Debian and Ubuntu
- Remove Old Unused Kernels on Debian and Ubuntu
Удаление старых ядер в Debian и Ubuntu
Иногда, при установке обновлений на сервер, можно столкнуться с проблемой нехватки места на /boot разделе. В Debian и Ubuntu есть два разных способа решения возникшей ситуации.
Первый способ — универсальный, ручной. Подходит для систем, куда установка новых пакетов не возможна, либо где пакет byobu для установки не доступен. Выводим список установленных ядер, а затем с помощью пакетного менеджера удаляем лишнее:
# dpkg --list | grep linux-image # apt-get --purge remove linux-image-XXXX
При необходимости, обновляем конфиг GRUB:
Разумеется, ручное удаление файлов с помощью rm из /boot так же возможно, но прибегать к такому способу стоит только в самом крайнем случае.
Второй способ — с помощью утилиты purge-old-kernels из пакета byobu. Устанавливаем пакет, и удаляем все старые ядра, оставив только новое (либо несколько, если это важно):
# apt-get install byobu # purge-old-kernels --keep 3
Пакет byobu доступен для установки и в Ubuntu, и в Debian (в 9 во всяком случае) прямо из репозиториев. Если вы заметили, что на сервере /boot раздел имеет небольшой размер, имеет смысл озадачиться установкой этой утилиты заранее.
Кроме того, в man purge-old-kernels для Ubuntu 17.10 можно найти следующее дополнение:
This utility is now deprecated. The functionality it used to provide should be integrated into apt(8).
Т. е. в этой версии Ubuntu уже можно использовать apt для удаления старых ядер. Например:
How to remove old kernels from Debian 11
Old kernels are not immediately removed after installing a new Linux kernel. On your Debian 11, the old kernels exist in the “/boot” partition. However, you can manually delete these unused and old kernels from your system. This operation will free up disk space formerly occupied by old kernels. Some systems may become useless if the “/boot” partition does not have adequate disk space.
With this post, we will assist you in removing old kernels, which can cause future problems related to the installation of programs and packages. Before moving ahead, let’s understand some basic concepts about a Linux kernel.
Linux kernel
The Linux kernel serves as an interface between the programs and computer hardware. It is an essential part of the Linux operating system. It communicates between the processes and hardware, allowing the system to utilize resources efficiently.
What are the functions of a Linux kernel
The kernel performs these four functions:
- Management of memory: It keeps track of how much memory is being utilized to store what and where it is stored.
- Security and system call: Processes in your system, request services to the Linux kernel.
- Management of processes: It also determines which processes, when, and how long they can use the CPU.
- Device drivers: It acts as a medium interface between the hardware and the processes for communication.
Occasionally, distributions release or update a new kernel version that either addresses a bug or is the most recent version issued by the Kernel team. Debian 11 loads the new kernel when we install the latest version. As time passes, you may end up having many kernel versions, all of which take up space on your hard drive and may create future difficulties.
Now, let’s check out the method of removing the old kernel on Debian 11.
How to check current version of kernel on Debian 11
Before moving ahead to the procedure of removing old kernels from our system, we will check out our current version of the Debian kernel. To do so, we will utilize the “uname” command.
In Linux-based systems such as Debian, the “uname” command is utilized for viewing the information related to the system hardware and operating system. It also retrieves the details about the system architecture and kernel. In the “uname” command, the “-r” option is added to check the version of the kernel which we are using:
You can also execute the “uname” command with the combination of “-mrs” options to get the machine name, kernel name, and its release:
Here “x86_64” indicates that the system is booted from the 64-bit kernel:
With the “-a” option, the “uname” command reveals all of the information related to the system:
How to list the installed kernels on Debian 11
After knowing the current version of the kernel, now we will execute the below-given command for getting the list of the installed kernel on Debian:
Here, the “dpkg” command with the “–list” option will extract the list of the packages installed on your Debian system. With the help of pipe operator “|” we will pass the list as input to the “grep” command. The “grep” command will look for the “linux-image” in the installed packages list. After that, it will print the output to the Debian terminal screen as follows:
How to remove old kernels from Debian 11
We have upgraded our system from Debian 10 buster to Debian 11 Bullseye and from the above-given, output you can see that the Debian 10 old kernel “linux-image-4.19.0-17-amd64” still resides on our system.
To remove old and unwanted “linux-image-4.19.0-17-amd64” kernel from Debian 11, we will execute the “remove” command with the “–purge” option. The “–purge” option will delete the specified kernel along with its configuration files:
After removing the old kernel, it’s time to update the “grub2” configuration:
Now, reboot your Debian 11 system:
That’s how you remove old kernels from a Debian system.
Conclusion
After some time, the Linux developers team releases an update or a new kernel. All Linux-based systems such as Debian 11 keep old kernel images to be booted if a newer kernel fails. However, you can free up space held by the old kernel images. In this post, we have shown you the method of removing old kernels from your Debian 11.
About the author
Sharqa Hameed
I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.
How to Delete Old Unused Kernels in Debian and Ubuntu
In our last article, we’ve explained how to delete old unused kernels in CentOS/RHEL/Fedora. In this article, we will explain how to delete old unused kernels in Debian and Ubuntu systems, but before moving further, you may want to install the latest version in order to take advantage of: security fixes, new kernel functions, updated drivers and so much more.
To upgrade your kernel to latest version in Ubuntu and Debian, follow this guide:
Important: It is advisable to keep at least one or two old kernels to fall back to in case there is a problem with an update.
To find out the current version of Linux kernel running on your system, use the following command.
$ uname -sr Linux 4.12.0-041200-generic
To list all installed kernels on your system, issue this command.
$ dpkg -l | grep linux-image | awk '' linux-image-4.12.0-041200-generic linux-image-4.8.0-22-generic linux-image-extra-4.8.0-22-generic linux-image-generic
Remove Old Unused Kernels on Debian and Ubuntu
Run the commands below to remove a particular linux-image along with its configuration files, then update grub2 configuration, and lastly reboot the system.
$ sudo apt remove --purge linux-image-4.4.0-21-generic $ sudo update-grub2 $ sudo reboot
[sudo] password for tecmint: Reading package lists. Done Building dependency tree Reading state information. Done The following additional packages will be installed: linux-generic linux-headers-4.8.0-59 linux-headers-4.8.0-59-generic linux-headers-generic linux-image-4.8.0-59-generic linux-image-extra-4.8.0-59-generic linux-image-generic Suggested packages: fdutils linux-doc-4.8.0 | linux-source-4.8.0 linux-tools Recommended packages: thermald The following packages will be REMOVED: linux-image-4.8.0-22-generic* linux-image-extra-4.8.0-22-generic* The following NEW packages will be installed: linux-headers-4.8.0-59 linux-headers-4.8.0-59-generic linux-image-4.8.0-59-generic linux-image-extra-4.8.0-59-generic The following packages will be upgraded: linux-generic linux-headers-generic linux-image-generic 3 upgraded, 4 newly installed, 2 to remove and 182 not upgraded. Need to get 72.0 MB of archives. After this operation, 81.7 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 linux-headers-4.8.0-59 all 4.8.0-59.64 [10.2 MB] Get:2 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 linux-headers-4.8.0-59-generic amd64 4.8.0-59.64 [811 kB] Get:3 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 linux-generic amd64 4.8.0.59.72 [1,782 B] Get:4 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 linux-headers-generic amd64 4.8.0.59.72 [2,320 B] Get:5 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 linux-image-4.8.0-59-generic amd64 4.8.0-59.64 [23.6 MB] Get:6 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 linux-image-extra-4.8.0-59-generic amd64 4.8.0-59.64 [37.4 MB] Get:7 http://us.archive.ubuntu.com/ubuntu yakkety-updates/main amd64 linux-image-generic amd64 4.8.0.59.72 [2,348 B] Fetched 72.0 MB in 7min 12s (167 kB/s) Selecting previously unselected package linux-headers-4.8.0-59. (Reading database . 104895 files and directories currently installed.) Preparing to unpack . /0-linux-headers-4.8.0-59_4.8.0-59.64_all.deb . Unpacking linux-headers-4.8.0-59 (4.8.0-59.64) . Selecting previously unselected package linux-headers-4.8.0-59-generic. Preparing to unpack . /1-linux-headers-4.8.0-59-generic_4.8.0-59.64_amd64.deb . Unpacking linux-headers-4.8.0-59-generic (4.8.0-59.64) . Preparing to unpack . /2-linux-generic_4.8.0.59.72_amd64.deb . Unpacking linux-generic (4.8.0.59.72) over (4.8.0.22.31) . Preparing to unpack . /3-linux-headers-generic_4.8.0.59.72_amd64.deb . Unpacking linux-headers-generic (4.8.0.59.72) over (4.8.0.22.31) . Selecting previously unselected package linux-image-4.8.0-59-generic. Preparing to unpack . /4-linux-image-4.8.0-59-generic_4.8.0-59.64_amd64.deb . Done. Removing linux-image-4.8.0-22-generic (4.8.0-22.24) . Examining /etc/kernel/postrm.d . run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.8.0-22-generic /boot/vmlinuz-4.8.0-22-generic update-initramfs: Deleting /boot/initrd.img-4.8.0-22-generic run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.8.0-22-generic /boot/vmlinuz-4.8.0-22-generic Generating grub configuration file . Found linux image: /boot/vmlinuz-4.12.0-041200-generic Found initrd image: /boot/initrd.img-4.12.0-041200-generic Found linux image: /boot/vmlinuz-4.8.0-59-generic done .
Although this method works just fine, it is more reliable and efficient to use a handy script called “byobu” that combines all the commands above into a single program with useful options such as specifying number of kernels to keep on the system.
Install byobu script package which provides a program called purge-old-kernels used for removing old kernels and header packages from the system.
Then remove old kernels like so (the command below allows 2 kernels to be kept on the system).
$ sudo purge-old-kernels --keep 2
You may also like to read these following related articles on Linux kernel.
In this article, we have described how to remove old unused kernel images on Ubuntu and Debian systems. You can share any thoughts via the feedback from below.