Dpkg remove linux image

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.

Читайте также:  Linux посмотреть какая сетевая карта

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.

Источник

How To Remove Old Linux Kernel Images (Ubuntu)

Use dpkg to list all the kernels installed.

# dpkg --list | grep linux-headersdpkg --list | grep linux-image# Outputii linux-image-3.13.0-100-generic 3.13.0-100.147 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMPii linux-image-3.13.0-103-generic 3.13.0-103.150 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP. ii linux-image-extra-3.13.0-100-generic 3.13.0-100.147 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMPii linux-image-extra-3.13.0-103-generic 3.13.0-103.150 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP. 
dpkg --list | egrep -i 'linux-image|linux-headers' | awk '< print $2 >'
linux-headers-5.4.0-62 linux-headers-5.4.0-62-generic linux-headers-5.4.0-65 linux-headers-5.4.0-65-generic linux-headers-generic linux-image-5.4.0-58-generic linux-image-5.4.0-62-generic linux-image-5.4.0-65-generic linux-image-generic

Check you current kernel (usually the one with the highest version number) to make sure you don’t remove them accidentally.

uname -r # Output: 4.4.0-87-generic

Location of linux kernels

It’s not necessary to find out the location of the kernels as we won’t be deleting them directly using rm , but just in case you are curious.

linux-headers is stored at /usr/src .

cd /usr/srcsudo du -sh *# Output95M linux-headers-3.13.0-10015M linux-headers-3.13.0-100-generic95M linux-headers-3.13.0-10315M linux-headers-3.13.0-103-generic. 106M linux-headers-4.4.0-8315M linux-headers-4.4.0-83-generic106M linux-headers-4.4.0-8715M linux-headers-4.4.0-87-generic. 

To find out location of a particular kernel package, use dpkg —listfiles .

dpkg --listfiles linux-image-3.13.0-103-generic# Output. /usr/share/doc/linux-image-3.13.0-103-generic. /lib/modules/3.13.0-103-generic. /lib/firmware/3.13.0-103-generic. 

Remove kernel

I would recommend to keep at least 3 latest versions of kernels including the current version ( uname -r ).

Читайте также:  Linux create filesystem in file

apt-get

Use sudo apt-get purge linux-image-x.x.x-x to remove a specific version of the kernel.

sudo apt-get purge linux-image-3.13.0-100# OutputReading package lists. DoneBuilding dependency tree Reading state information. DoneNote, selecting 'linux-image-3.13.0-100-generic' for regex 'linux-image-3.13.0-100'Note, selecting 'linux-image-3.13.0-100-lowlatency' for regex 'linux-image-3.13.0-100'Package 'linux-image-3.13.0-100-lowlatency' is not installed, so not removedThe following packages will be REMOVED: linux-image-3.13.0-100-generic* linux-image-extra-3.13.0-100-generic*0 upgraded, 0 newly installed, 2 to remove and 8 not upgraded.After this operation, 195 MB disk space will be freed.

You can remove linux-headers as well using sudo apt-get purge linux-headers-x.x.x-x

sudo apt-get purge linux-headers-3.13.0-100# OutputReading package lists. DoneBuilding dependency tree Reading state information. DoneThe following packages will be REMOVED: linux-headers-3.13.0-100* linux-headers-3.13.0-100-generic*0 upgraded, 0 newly installed, 2 to remove and 7 not upgraded.After this operation, 76.9 MB disk space will be freed.Do you want to continue? [Y/n] Y(Reading database . 475653 files and directories currently installed.)Removing linux-headers-3.13.0-100-generic (3.13.0-100.147) . Removing linux-headers-3.13.0-100 (3.13.0-100.147) . 

Though there are commands to remove a range of linux kernels, I would like to play safe to avoid accidental removal.

GUI

If you prefer GUI, you can try sypnatic or Ubuntu Tweak .

Update on 2017-08-03 : Ubuntu Tweak is no longer maintained since 2016-05-02.

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

Travelopy — discover travel places in Malaysia, Singapore, Taiwan, Japan.

Источник

Оцените статью
Adblock
detector