After installing a new Linux kernel, old kernels are not automatically deleted. They remain in your disk (/boot partition). You have to delete them manually. Why?
The main reason is to save disk space, which occupied by old kernels. Some systems may become unusable if not enough disk space is available in /boot partition. However, disk space is not a problem in modern systems.
An other reason is to clean up Grub boot menu. In Ubuntu, Grub boot menu is hidden by default. You can display it by pressing “SHIFT” continuously at boot time. More details in this post.
You will never delete your current kernel, of course. It is recommended to keep at least one or two older kernels, so you can boot your system in an emergency situation (hardware or software compatibility issues with the current kernel).
After removing old kernels, new grub boot menu will be available in next reboot.
In a healthy Debian system, each time you install a package or update your system, you will be prompted that old kernels (if any) can ber removed. You will get the message “The following packages were automatically installed and are no longer required”. This message is no specific for kernel, but for any package which no longer required in your system:
In this case you may use:
apt-get autoremove
This would be enough to remove old kernels from your system. But, below, it is described a completed and more safe approach.
Get current status
First things first. Which is your current kernel?
Use the command
uname -r
or
uname -mrs
or
uname -a
Method A (recommended for Debian users)
Get list of installed kernels (and headers)
dpkg --list | grep linux-image
Do the same for kernel headers:
dpkg --list | grep linux-headers
As root, remove old kernels one by one, using:
apt-get --purge remove linux-image-XXX
Finally, as root, update grub:
update-grub2
and reboot:
systemctl reboot
Method B – purge-old-kernels (recommended for Ubuntu users)
purge-old-kernels
is a simple bash script, which
uses apt remove --purge
command to remove old
kernels.
It will be available in your system after installing package
byobu. byobu is a handy terminal multiplexer (more info
here). There is no need to use byobu
.
Just install it. So:
sudo apt-get install byobu
Note: in older releases you might need to to install bikeshed.
Using man page:
man purge-old-kernels
you get the answer of what purge-old-kernels
can do
for you.
This program will remove old kernel and header packages from the system, freeing disk space. It will never remove the currently running kernel. By default, it will keep at least the latest 2 kernels, but the user can override that value using the –keep parameter.
Here is an example:
sudo purge-old-kernels --keep 3 -qy
(-y, –yes, –assume-yes Automatic yes to
prompts.
-q, –quiet produces output suitable for logging,
omitting progress indicators).
the result is
Reading package lists...
Building dependency tree...
Reading state information...
The following package was automatically installed and is no longer required:
linux-image-extra-4.4.0-42-generic
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
linux-headers-4.4.0-21-generic* linux-headers-4.4.0-34-generic*
linux-headers-4.4.0-36-generic* linux-headers-4.4.0-38-generic*
linux-image-4.4.0-21-generic* linux-image-4.4.0-34-generic*
linux-image-4.4.0-36-generic* linux-image-4.4.0-38-generic*
linux-image-extra-4.4.0-34-generic* linux-image-extra-4.4.0-36-generic*
linux-image-extra-4.4.0-38-generic*
0 upgraded, 0 newly installed, 11 to remove and 0 not upgraded.
After this operation, 738 MB disk space will be freed.
(Reading database ... 393355 files and directories currently installed.)
Removing linux-headers-4.4.0-21-generic (4.4.0-21.37) ...
Removing linux-headers-4.4.0-34-generic (4.4.0-34.53) ...
Removing linux-headers-4.4.0-36-generic (4.4.0-36.55) ...
Removing linux-headers-4.4.0-38-generic (4.4.0-38.57) ...
Removing linux-image-4.4.0-21-generic (4.4.0-21.37) ...
Examining /etc/kernel/prerm.d.
run-parts: executing /etc/kernel/prerm.d/dkms 4.4.0-21-generic /boot/vmlinuz-4.4.0-21-generic
dkms: removing: bbswitch 0.8 (4.4.0-21-generic) (x86_64)
-------- Uninstall Beginning --------
Module: bbswitch
Version: 0.8
Kernel: 4.4.0-21-generic (x86_64)
-------------------------------------
Status: Before uninstall, this module version was ACTIVE on this kernel.
bbswitch.ko:
- Uninstallation
- Deleting from: /lib/modules/4.4.0-21-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.
depmod....
DKMS: uninstall completed.
dkms: removing: nvidia-361 361.42 (4.4.0-21-generic) (x86_64)
-------- Uninstall Beginning --------
Module: nvidia-361
Version: 361.42
Kernel: 4.4.0-21-generic (x86_64)
-------------------------------------
Status: Before uninstall, this module version was ACTIVE on this kernel.
nvidia_361.ko:
- Uninstallation
- Deleting from: /lib/modules/4.4.0-21-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.
nvidia_361_modeset.ko:
- Uninstallation
- Deleting from: /lib/modules/4.4.0-21-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.
nvidia_361_uvm.ko:
- Uninstallation
- Deleting from: /lib/modules/4.4.0-21-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.
depmod....
DKMS: uninstall completed.
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-21-generic /boot/vmlinuz-4.4.0-21-generic
update-initramfs: Deleting /boot/initrd.img-4.4.0-21-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-21-generic /boot/vmlinuz-4.4.0-21-generic
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.4.0-45-generic
Found initrd image: /boot/initrd.img-4.4.0-45-generic
Found linux image: /boot/vmlinuz-4.4.0-43-generic
Found initrd image: /boot/initrd.img-4.4.0-43-generic
Found linux image: /boot/vmlinuz-4.4.0-42-generic
Found initrd image: /boot/initrd.img-4.4.0-42-generic
Found linux image: /boot/vmlinuz-4.4.0-38-generic
Found initrd image: /boot/initrd.img-4.4.0-38-generic
Found linux image: /boot/vmlinuz-4.4.0-36-generic
Found initrd image: /boot/initrd.img-4.4.0-36-generic
Found linux image: /boot/vmlinuz-4.4.0-34-generic
Found initrd image: /boot/initrd.img-4.4.0-34-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
done
Purging configuration files for linux-image-4.4.0-21-generic (4.4.0-21.37) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-21-generic /boot/vmlinuz-4.4.0-21-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-21-generic /boot/vmlinuz-4.4.0-21-generic
Removing linux-image-extra-4.4.0-34-generic (4.4.0-34.53) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-34-generic /boot/vmlinuz-4.4.0-34-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-34-generic /boot/vmlinuz-4.4.0-34-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-34-generic /boot/vmlinuz-4.4.0-34-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-34-generic
run-parts: executing /etc/kernel/postinst.d/pm-utils 4.4.0-34-generic /boot/vmlinuz-4.4.0-34-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-34-generic /boot/vmlinuz-4.4.0-34-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-34-generic /boot/vmlinuz-4.4.0-34-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-34-generic /boot/vmlinuz-4.4.0-34-generic
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.4.0-45-generic
Found initrd image: /boot/initrd.img-4.4.0-45-generic
Found linux image: /boot/vmlinuz-4.4.0-43-generic
Found initrd image: /boot/initrd.img-4.4.0-43-generic
Found linux image: /boot/vmlinuz-4.4.0-42-generic
Found initrd image: /boot/initrd.img-4.4.0-42-generic
Found linux image: /boot/vmlinuz-4.4.0-38-generic
Found initrd image: /boot/initrd.img-4.4.0-38-generic
Found linux image: /boot/vmlinuz-4.4.0-36-generic
Found initrd image: /boot/initrd.img-4.4.0-36-generic
Found linux image: /boot/vmlinuz-4.4.0-34-generic
Found initrd image: /boot/initrd.img-4.4.0-34-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
done
Purging configuration files for linux-image-extra-4.4.0-34-generic (4.4.0-34.53) ...
Removing linux-image-4.4.0-34-generic (4.4.0-34.53) ...
Examining /etc/kernel/prerm.d.
run-parts: executing /etc/kernel/prerm.d/dkms 4.4.0-34-generic /boot/vmlinuz-4.4.0-34-generic
dkms: removing: bbswitch 0.8 (4.4.0-34-generic) (x86_64)
-------- Uninstall Beginning --------
Module: bbswitch
Version: 0.8
Kernel: 4.4.0-34-generic (x86_64)
-------------------------------------
Status: Before uninstall, this module version was ACTIVE on this kernel.
bbswitch.ko:
- Uninstallation
- Deleting from: /lib/modules/4.4.0-34-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.
depmod....
DKMS: uninstall completed.
dkms: removing: nvidia-361 361.42 (4.4.0-34-generic) (x86_64)
-------- Uninstall Beginning --------
Module: nvidia-361
Version: 361.42
Kernel: 4.4.0-34-generic (x86_64)
-------------------------------------
Status: Before uninstall, this module version was ACTIVE on this kernel.
nvidia_361.ko:
- Uninstallation
- Deleting from: /lib/modules/4.4.0-34-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.
nvidia_361_modeset.ko:
- Uninstallation
- Deleting from: /lib/modules/4.4.0-34-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.
nvidia_361_uvm.ko:
- Uninstallation
- Deleting from: /lib/modules/4.4.0-34-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.
depmod....
DKMS: uninstall completed.
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-34-generic /boot/vmlinuz-4.4.0-34-generic
update-initramfs: Deleting /boot/initrd.img-4.4.0-34-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-34-generic /boot/vmlinuz-4.4.0-34-generic
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.4.0-45-generic
Found initrd image: /boot/initrd.img-4.4.0-45-generic
Found linux image: /boot/vmlinuz-4.4.0-43-generic
Found initrd image: /boot/initrd.img-4.4.0-43-generic
Found linux image: /boot/vmlinuz-4.4.0-42-generic
Found initrd image: /boot/initrd.img-4.4.0-42-generic
Found linux image: /boot/vmlinuz-4.4.0-38-generic
Found initrd image: /boot/initrd.img-4.4.0-38-generic
Found linux image: /boot/vmlinuz-4.4.0-36-generic
Found initrd image: /boot/initrd.img-4.4.0-36-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
done
Purging configuration files for linux-image-4.4.0-34-generic (4.4.0-34.53) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-34-generic /boot/vmlinuz-4.4.0-34-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-34-generic /boot/vmlinuz-4.4.0-34-generic
Removing linux-image-extra-4.4.0-36-generic (4.4.0-36.55) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-36-generic
run-parts: executing /etc/kernel/postinst.d/pm-utils 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.4.0-45-generic
Found initrd image: /boot/initrd.img-4.4.0-45-generic
Found linux image: /boot/vmlinuz-4.4.0-43-generic
Found initrd image: /boot/initrd.img-4.4.0-43-generic
Found linux image: /boot/vmlinuz-4.4.0-42-generic
Found initrd image: /boot/initrd.img-4.4.0-42-generic
Found linux image: /boot/vmlinuz-4.4.0-38-generic
Found initrd image: /boot/initrd.img-4.4.0-38-generic
Found linux image: /boot/vmlinuz-4.4.0-36-generic
Found initrd image: /boot/initrd.img-4.4.0-36-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
done
Purging configuration files for linux-image-extra-4.4.0-36-generic (4.4.0-36.55) ...
Removing linux-image-4.4.0-36-generic (4.4.0-36.55) ...
Examining /etc/kernel/prerm.d.
run-parts: executing /etc/kernel/prerm.d/dkms 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
dkms: removing: bbswitch 0.8 (4.4.0-36-generic) (x86_64)
-------- Uninstall Beginning --------
Module: bbswitch
Version: 0.8
Kernel: 4.4.0-36-generic (x86_64)
-------------------------------------
Status: Before uninstall, this module version was ACTIVE on this kernel.
bbswitch.ko:
- Uninstallation
- Deleting from: /lib/modules/4.4.0-36-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.
depmod....
DKMS: uninstall completed.
dkms: removing: nvidia-361 361.42 (4.4.0-36-generic) (x86_64)
-------- Uninstall Beginning --------
Module: nvidia-361
Version: 361.42
Kernel: 4.4.0-36-generic (x86_64)
-------------------------------------
Status: Before uninstall, this module version was ACTIVE on this kernel.
nvidia_361.ko:
- Uninstallation
- Deleting from: /lib/modules/4.4.0-36-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.
nvidia_361_modeset.ko:
- Uninstallation
- Deleting from: /lib/modules/4.4.0-36-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.
nvidia_361_uvm.ko:
- Uninstallation
- Deleting from: /lib/modules/4.4.0-36-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.
depmod....
DKMS: uninstall completed.
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
update-initramfs: Deleting /boot/initrd.img-4.4.0-36-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.4.0-45-generic
Found initrd image: /boot/initrd.img-4.4.0-45-generic
Found linux image: /boot/vmlinuz-4.4.0-43-generic
Found initrd image: /boot/initrd.img-4.4.0-43-generic
Found linux image: /boot/vmlinuz-4.4.0-42-generic
Found initrd image: /boot/initrd.img-4.4.0-42-generic
Found linux image: /boot/vmlinuz-4.4.0-38-generic
Found initrd image: /boot/initrd.img-4.4.0-38-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
done
Purging configuration files for linux-image-4.4.0-36-generic (4.4.0-36.55) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-36-generic /boot/vmlinuz-4.4.0-36-generic
Removing linux-image-extra-4.4.0-38-generic (4.4.0-38.57) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-38-generic
run-parts: executing /etc/kernel/postinst.d/pm-utils 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.4.0-45-generic
Found initrd image: /boot/initrd.img-4.4.0-45-generic
Found linux image: /boot/vmlinuz-4.4.0-43-generic
Found initrd image: /boot/initrd.img-4.4.0-43-generic
Found linux image: /boot/vmlinuz-4.4.0-42-generic
Found initrd image: /boot/initrd.img-4.4.0-42-generic
Found linux image: /boot/vmlinuz-4.4.0-38-generic
Found initrd image: /boot/initrd.img-4.4.0-38-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
done
Purging configuration files for linux-image-extra-4.4.0-38-generic (4.4.0-38.57) ...
Removing linux-image-4.4.0-38-generic (4.4.0-38.57) ...
Examining /etc/kernel/prerm.d.
run-parts: executing /etc/kernel/prerm.d/dkms 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
dkms: removing: bbswitch 0.8 (4.4.0-38-generic) (x86_64)
-------- Uninstall Beginning --------
Module: bbswitch
Version: 0.8
Kernel: 4.4.0-38-generic (x86_64)
-------------------------------------
Status: Before uninstall, this module version was ACTIVE on this kernel.
bbswitch.ko:
- Uninstallation
- Deleting from: /lib/modules/4.4.0-38-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.
depmod....
DKMS: uninstall completed.
dkms: removing: nvidia-361 361.42 (4.4.0-38-generic) (x86_64)
-------- Uninstall Beginning --------
Module: nvidia-361
Version: 361.42
Kernel: 4.4.0-38-generic (x86_64)
-------------------------------------
Status: Before uninstall, this module version was ACTIVE on this kernel.
nvidia_361.ko:
- Uninstallation
- Deleting from: /lib/modules/4.4.0-38-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.
nvidia_361_modeset.ko:
- Uninstallation
- Deleting from: /lib/modules/4.4.0-38-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.
nvidia_361_uvm.ko:
- Uninstallation
- Deleting from: /lib/modules/4.4.0-38-generic/updates/dkms/
- Original module
- No original module was found for this module on this kernel.
- Use the dkms install command to reinstall any previous module version.
depmod....
DKMS: uninstall completed.
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
update-initramfs: Deleting /boot/initrd.img-4.4.0-38-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.4.0-45-generic
Found initrd image: /boot/initrd.img-4.4.0-45-generic
Found linux image: /boot/vmlinuz-4.4.0-43-generic
Found initrd image: /boot/initrd.img-4.4.0-43-generic
Found linux image: /boot/vmlinuz-4.4.0-42-generic
Found initrd image: /boot/initrd.img-4.4.0-42-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
done
Purging configuration files for linux-image-4.4.0-38-generic (4.4.0-38.57) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
Other Methods
Graphical tools
In order to remove old kernels (one by one) you may use Synaptic package manager or some type of computer “cleaners” or “janitors” as Ubuntu tweak etc. It is not recommended, IMHO.
Configure unattended-upgrades
Using your favorite editor
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
find this
// Do automatic removal of new unused dependencies after the upgrade
// (equivalent to apt-get autoremove)
//Unattended-Upgrade::Remove-Unused-Dependencies "false";
change line
//Unattended-Upgrade::Remove-Unused-Dependencies "false";
to
Unattended-Upgrade::Remove-Unused-Dependencies "true";
All the above steps are equivalent with
sudo dpkg-reconfigure unattended-upgrades
This is not specific for kernels. You force automatic removal of new unused dependencies for any package in your system.
Again, not recommended, IMHO.
Conclusion
Debian users
- Get list of kernels:
dpkg --list | grep linux-image
- Remove old kernels one by one:
apt-get --purge remove linux-image-XXX
- Update grub:
update-grub2
Reboot:systemctl reboot
Ubuntu users
- Install byobu:
sudo apt-get install byobu
- Run periodically:
sudo purge-old-kernels --keep 3
Entrepreneur | Full-stack developer | Founder of MediSign Ltd. I have over 15 years of professional experience designing and developing web applications. I am also very experienced in managing (web) projects.