Ubuntu: How to remove old kernel in 16.04



Question:

I am using Linux Ubuntu mate-desktop 4.4.0-24-generic #43-Ubuntu SMP Wed Jun 8 19:27:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux.

Just recently I am experiencing problems with updating and specifically with an older kernel - 4.4.0-22 (linux-image-extra-4.4.0-22-generic). It is marked for removal but not being removed. I am not a Linux guru by any means! I need help here to completely remove this older kernel. Here is what I have copied from the terminal.

root@xxxxxxxxxx-desktop:/home/xxxxxxxxxx# apt-get autoremove -f  Reading package lists... Done  Building dependency tree         Reading state information... Done  The following packages will be REMOVED:    linux-image-extra-4.4.0-22-generic  0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded.  6 not fully installed or removed.  After this operation, 162 MB disk space will be freed.  Do you want to continue? [Y/n] y  (Reading database ... 272391 files and directories currently installed.)  Removing linux-image-extra-4.4.0-22-generic (4.4.0-22.40) ...  depmod: FATAL: could not load /boot/System.map-4.4.0-22-generic: No such file or directory  run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-22-.generic /boot/vmlinuz-4.4.0-22-generic  run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-22-generic   ./boot/vmlinuz-4.4.0-22-generic  Error! Your kernel headers for kernel 4.4.0-22-generic cannot be found.  Please install the linux-headers-4.4.0-22-generic package,  or use the --kernelsourcedir option to tell DKMS where it's located  run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic  update-initramfs: Generating /boot/initrd.img-4.4.0-22-generic  WARNING: missing /lib/modules/4.4.0-22-generic  Ensure all necessary drivers are built into the linux image!  depmod: ERROR: could not open directory /lib/modules/4.4.0-22-generic: No such file or directory  depmod: FATAL: could not search modules: No such file or directory  depmod: WARNING: could not open /var/tmp/mkinitramfs_U8szG6/lib/modules/4.4.0-22-generic/modules.order: No such file or directorydepmod: WARNING: .  could not open /var/tmp/mkinitramfs_U8szG6/lib/modules/4.4.0-22-generic/modules.builtin: No such file or directory  /usr/sbin/update-initramfs: 206: /usr/sbin/update-initramfs: cannot create /var/lib/initramfs-tools/4.4.0-22-generic: Directory nonexistent  run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 2  dpkg: error processing package linux-image-extra-4.4.0-22-generic (--remove):   subprocess installed post-removal script returned error exit status 1  Errors were encountered while processing:  linux-image-extra-4.4.0-22-generic  E: Sub-process /usr/bin/dpkg returned an error code (1)  root@xxxxxxxxxx-desktop:/home/xxxxxxxxxx#  

Hope this is enough info to get started.


Solution:1

The linux-image-extra-4.4.0-22-generic package depends on linux-image-4.4.0-22-generic which is also the origin of the missing /boot/System.map-4.4.0-22-generic (this could be considered a bug). So as odd as it may sound you need to install the latter to then be able to remove both:

sudo apt-get install linux-image-4.4.0-22-generic  sudo apt-get remove linux-image-4.4.0-22-generic linux-image-extra-4.4.0-22-generic  

They should have been (auto-)removed together the first time and I have no idea why that didn't happen.


Solution:2

The easiest and most recommended way to remove unused kernels is the Update manager. From the View menu (of the Update manager's main window) select Linux kernels. In the appearing window, select the kernel you want to uninstall. Then everything is done by the Update manager.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »