Ubuntu: How to remove or purge a kernel package manually to resolve a stuck APT/DPKG installation?


I have faced lately some cases where the asker had a APT removal operation stuck due some kernel script errors.

Sometimes is easy to fix the root cause.

But in some other rare cases, it is hard or long path to go with debugging. Specially with non boot-able system or only recovery shell available.

I will add some cases here:

I have already used a dirty solution as explained my answer below. I would ask for a cleaner workaround to manually remove a kernel package as DPKG do?


This is not a clean solution as it does not update the some generated kernel settings/files.(It skips all post-/pre- scripts & dpkg triggers)

  1. Check the installed files using

     dpkg -L linux-image-...  
  2. Remove them manually

  3. Remove generated RAMDisk

    sudo rm /boot/initrd.img-...  
  4. Backup /var/lib/dpkg/status them open it and change its status to deinstall

  5. Update grub menu

    sudo update-grub  

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