Old Kernels
Old Kernels¶
Delete Old Kernel Images¶
The procedure is as follows for a Debian or Ubuntu Linux system. You must login as the root user.
WARNING! Deleting the currently running or wrong kernel version can result in an unbootable system. Be careful with all commands and verify them twice before you hit the [Enter] key. The nixCraft or author is not responsible for any damages.
Step 1 – Boot into new kernel¶
First, boot into newly installed kernel. Type the uname command to verify and find Linux kernel version as follows:
Sample outputs:
To list all installed Linux kernel images, type the following dpkg command as follows:
Sample outputs:
rc linux-image-6.1.0-20-amd64 6.1.85-1 amd64 Linux 6.1 for 64-bit PCs (signed)
rc linux-image-6.1.0-21-amd64 6.1.90-1 amd64 Linux 6.1 for 64-bit PCs (signed)
rc linux-image-6.1.0-22-amd64 6.1.94-1 amd64 Linux 6.1 for 64-bit PCs (signed)
rc linux-image-6.1.0-23-amd64 6.1.99-1 amd64 Linux 6.1 for 64-bit PCs (signed)
rc linux-image-6.1.0-25-amd64 6.1.106-3 amd64 Linux 6.1 for 64-bit PCs (signed)
rc linux-image-6.1.0-26-amd64 6.1.112-1 amd64 Linux 6.1 for 64-bit PCs (signed)
rc linux-image-6.1.0-27-amd64 6.1.115-1 amd64 Linux 6.1 for 64-bit PCs (signed)
rc linux-image-6.1.0-28-amd64 6.1.119-1 amd64 Linux 6.1 for 64-bit PCs (signed)
rc linux-image-6.1.0-29-amd64 6.1.123-1 amd64 Linux 6.1 for 64-bit PCs (signed)
ii linux-image-6.1.0-30-amd64 6.1.124-1 amd64 Linux 6.1 for 64-bit PCs (signed)
ii linux-image-6.1.0-31-amd64 6.1.128-1 amd64 Linux 6.1 for 64-bit PCs (signed)
ii linux-image-amd64 6.1.128-1 amd64 Linux for 64-bit PCs (meta-package)
The ‘ii‘ status code means the kernel packages are installed, while the ‘rc‘ code indicates the kernel itself is removed, though configuration files may remain on the hard disk drive.
Step 2 – Delete unwanted and unused kernel images¶
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}')
# Print Linux kernel named before you delete them #
# using the echo/printf command #
echo "$x"
apt-get --purge remove $x
echo "$x"
linux-image-6.1.0-20-amd64
linux-image-6.1.0-21-amd64
linux-image-6.1.0-22-amd64
linux-image-6.1.0-23-amd64
linux-image-6.1.0-25-amd64
linux-image-6.1.0-26-amd64
linux-image-6.1.0-27-amd64
linux-image-6.1.0-28-amd64
linux-image-6.1.0-29-amd64
sudo apt-get --purge remove $x
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
linux-image-6.1.0-20-amd64* linux-image-6.1.0-21-amd64* linux-image-6.1.0-22-amd64* linux-image-6.1.0-23-amd64* linux-image-6.1.0-25-amd64* linux-image-6.1.0-26-amd64* linux-image-6.1.0-27-amd64* linux-image-6.1.0-28-amd64* linux-image-6.1.0-29-amd64*
0 upgraded, 0 newly installed, 9 to remove and 2 not upgraded.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 65662 files and directories currently installed.)
Purging configuration files for linux-image-6.1.0-25-amd64 (6.1.106-3) ...
Purging configuration files for linux-image-6.1.0-20-amd64 (6.1.85-1) ...
Purging configuration files for linux-image-6.1.0-21-amd64 (6.1.90-1) ...
Purging configuration files for linux-image-6.1.0-26-amd64 (6.1.112-1) ...
Purging configuration files for linux-image-6.1.0-22-amd64 (6.1.94-1) ...
Purging configuration files for linux-image-6.1.0-23-amd64 (6.1.99-1) ...
Purging configuration files for linux-image-6.1.0-27-amd64 (6.1.115-1) ...
Purging configuration files for linux-image-6.1.0-28-amd64 (6.1.119-1) ...
Purging configuration files for linux-image-6.1.0-29-amd64 (6.1.123-1) ...