Skip to content

Instantly share code, notes, and snippets.

@zoonderkins
Created June 11, 2020 03:50
Show Gist options
  • Save zoonderkins/6bac823f9ac0294176ec03133389a184 to your computer and use it in GitHub Desktop.
Save zoonderkins/6bac823f9ac0294176ec03133389a184 to your computer and use it in GitHub Desktop.
Debian manually remove unsed kernel images

Install newest linux images

lsb_release -a
apt -y install linux-image-5.6.0-2-amd64 linux-headers-5.6.0-2-common

Remove unsed kernel images on Debian

Step 1 – Boot into new kernel

First, boot into newly installed kernel. Verify this with the following command:

uname -mrs
uname -a

Sample outputs:

Linux server1 3.13.0-68-generic #111-Ubuntu SMP Fri Nov 6 18:17:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

To list all installed Linux kernel images, type the following dpkg command: dpkg --list | egrep -i --color 'linux-image|linux-headers'

Step 2 – Delete unwanted and unused kernel images

You can remove kernel images one by one using the following apt-get command or apt command syntax: apt-get --purge remove linux-image-3.13.0-67-generic

Understanding package states in Ubuntu and Debian Linux

Consider the following example: dpkg --list | grep linux-image

Sample outputs:

rc  linux-image-3.13.0-62-generic        3.13.0-62.102                         amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc  linux-image-3.13.0-63-generic        3.13.0-63.103                         amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc  linux-image-3.13.0-65-generic        3.13.0-65.106                         amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc  linux-image-3.13.0-66-generic        3.13.0-66.108                         amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc  linux-image-3.13.0-67-generic        3.13.0-67.110                         amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
ii  linux-image-3.13.0-68-generic        3.13.0-68.111                         amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc  linux-image-extra-3.13.0-62-generic  3.13.0-62.102                         amd64        Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
rc  linux-image-extra-3.13.0-63-generic  3.13.0-63.103                         amd64        Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
rc  linux-image-extra-3.13.0-65-generic  3.13.0-65.106                         amd64        Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
rc  linux-image-extra-3.13.0-66-generic  3.13.0-66.108                         amd64        Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
rc  linux-image-extra-3.13.0-67-generic  3.13.0-67.110                         amd64        Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii  linux-image-extra-3.13.0-68-generic  3.13.0-68.111                         amd64        Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii  linux-image-generic                  3.13.0.68.74                          amd64        Generic Linux kernel image

The first column indicates package flags like rc, ii. So, what do the various dpkg flags like ‘ii’ ‘rc’ mean?

    rc: It means package is in remove/deinstall state and only config file exists.
    ii: It means package is in install state and it is 100% installed on the system.

You can remove all linux-image packages in rc state using the following command:

# x=$(dpkg --list | grep -i linux-image | grep ^rc| awk '{ print $2}')
# echo "$x"
# apt-get --purge remove $x

References:

  1. https://www.cyberciti.biz/faq/debian-ubuntu-linux-delete-old-kernel-images-command/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment