1

I am trying to remove old kernels in an encrypted system. I am getting kernels marked for purge, but installed after my efforts.

I start with removing leftover temporary files from previous kernel updates

$ sudo rm -rv ${TMPDIR:-/var/tmp}/mkinitramfs-*

My current version number is 4.4.0-127-generic

Here is my list currently after several attempts. I'm trying to keep 127 (my current version, and 124)

$ dpkg -l | tail -n +6 | grep -E 'linux-image-[0-9]+'
pi  linux-image-4.4.0-112-generic              4.4.0-112.135                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
pi  linux-image-4.4.0-116-generic              4.4.0-116.140                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
pi  linux-image-4.4.0-119-generic              4.4.0-119.143                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
pi  linux-image-4.4.0-121-generic              4.4.0-121.145                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-122-generic              4.4.0-122.146                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-124-generic              4.4.0-124.148                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP
ii  linux-image-4.4.0-127-generic              4.4.0-127.153                                amd64        Linux kernel image for version 4.4.0 on 64 bit x86 SMP

So, say I try to remove 4.4.0-119

I free space in boot by removing initrd.img file

$ sudo update-initramfs -d -k 4.4.0-119-generic
update-initramfs: Deleting /boot/initrd.img-4.4.0-119-generic

I try purging the kernal

$ sudo dpkg --purge linux-image-4.4.0-119-generic linux-image-extra-4.4.0-119-generic

dpkg: dependency problems prevent removal of linux-image-4.4.0-119-generic:
 linux-signed-image-4.4.0-119-generic depends on linux-image-4.4.0-119-generic (= 4.4.0-119.143).

dpkg: error processing package linux-image-4.4.0-119-generic (--purge):
 dependency problems - not removing
(Reading database ... 513541 files and directories currently installed.)
Removing linux-image-extra-4.4.0-119-generic (4.4.0-119.143) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-119-generic /boot/vmlinuz-4.4.0-119-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-119-generic /boot/vmlinuz-4.4.0-119-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-119-generic /boot/vmlinuz-4.4.0-119-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-119-generic
run-parts: executing /etc/kernel/postinst.d/pm-utils 4.4.0-119-generic /boot/vmlinuz-4.4.0-119-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-119-generic /boot/vmlinuz-4.4.0-119-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-119-generic /boot/vmlinuz-4.4.0-119-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-119-generic /boot/vmlinuz-4.4.0-119-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-127-generic
Found initrd image: /boot/initrd.img-4.4.0-127-generic
Found linux image: /boot/vmlinuz-4.4.0-124-generic
Found initrd image: /boot/initrd.img-4.4.0-124-generic
Found linux image: /boot/vmlinuz-4.4.0-122-generic
Found initrd image: /boot/initrd.img-4.4.0-122-generic
Found linux image: /boot/vmlinuz-4.4.0-121-generic
Found initrd image: /boot/initrd.img-4.4.0-121-generic
Found linux image: /boot/vmlinuz-4.4.0-119-generic
Found initrd image: /boot/initrd.img-4.4.0-119-generic
Found linux image: /boot/vmlinuz-4.4.0-116-generic
Found initrd image: /boot/initrd.img-4.4.0-116-generic
Found linux image: /boot/vmlinuz-4.4.0-112-generic
done
Purging configuration files for linux-image-extra-4.4.0-119-generic (4.4.0-119.143) ...
Errors were encountered while processing:
 linux-image-4.4.0-119-generic

Doing this changes the status of the kernel to pi. This is the method I used previously to remove old kernels. I'm not sure what changed here.

  • have you tried purging from apt: sudo apt purge linux-image-4.4.0-119-generic linux-image-extra-4.4.0-119-generic – Broadsworde May 31 '18 at 17:12
  • No, thank you. That worked great. – Chad May 31 '18 at 17:15
  • And thank you for the edits. I realized after the fact what a nightmare that looked. – Chad May 31 '18 at 17:19
  • I had followed the commands in this answer under the section for "Safely Removing Old Kernels" previously. It suggested purging from dpkg. help.ubuntu.com/community/RemoveOldKernels – Chad May 31 '18 at 17:24
  • Read the error message carefully: dpkg is telling you exactly what the problem is - there is another package you must remove first. Apt resolves these dependencies and removes in the correct order, dpkg does not - you must manually remove in the correct order. – user535733 May 31 '18 at 17:26
1

Look at the error message you are getting:

dpkg: dependency problems prevent removal of linux-image-4.4.0-119-generic:
 linux-signed-image-4.4.0-119-generic depends on linux-image-4.4.0-119-generic (= 4.4.0-119.143).

It tells you that after removal of these package the package linux-signed-image-4.4.0-119-generic would have an unmet dependency. So the solution to your problem should be to also remove this package as it belongs to the kernel you are trying to remove.

Try this command:

$ sudo dpkg --purge linux-image-4.4.0-119-generic linux-image-extra-4.4.0-119-generic linux-signed-image-4.4.0-119-generic
0

Try removing from apt:

sudo apt remove --purge linux-image-4.4.0-119-generic linux-image-extra-4.4.0-119-generic

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.