I did something silly with a build/modprobe/make while running on my latest installed kernel. Now that kernel will not boot. I am currently running on a previous kernel.

How can I clean this up? I would like to just get back to the "stock" latest kernel that is in the apt repo.

Edit: I should note.... I was trying to install flashcache (https://github.com/facebook/flashcache/)

I tried to do

sudo apt-get install --reinstall linux-image-generic linux-image

That didn't fix it; so I tried the "recovery mode" option and see a kernel panic around the loading of the flashcache module.... I must need to delete something, somewhere...

enter image description here

4 Answers 4


I do not know if you have network access but if you have then do:

sudo apt-get install --reinstall linux-image-generic linux-image
  • 1
    That does something... but when I reboot I have the same problem. Black screen. Feb 10, 2013 at 0:11
  • 9
    In my case I also had to specify the linux image version, e.g. sudo apt-get install --reinstall linux-image-generic linux-image-3.19.0-26-generic.
    – George
    Sep 7, 2016 at 14:01
  • no package found named linux-image. But the other one did the thing. Mar 15, 2022 at 2:44

Simply boot to a previous kernel version and type the following, just replace ## with the kernel version you are trying to boot into.

sudo update-initramfs -u -k 3.2.0-##-generic-pae 

Just replace ## with the kernel version you are trying to boot into.

Follow that with a hello to Grub, and reboot.

sudo update-grub
sudo reboot now

Now you should no longer see a kernel panic when booting into the new kernel.

  • 7
    Or sudo update-initramfs -u -k $(uname -r) :)
    – c24w
    Aug 16, 2019 at 14:12
  • I can't thank you enough for that update-initramfs command. If anyone else is having this kind of issue with the latest installed kernel, boot into grub, then into recovery mode of the previous kernel, and execute this command by passing the latest kernel version to fix it. Worked like a charm!
    – mj3c
    Apr 13, 2020 at 16:26
  • I broke my system with SysRq+B when it hung for several minutes while shutting down for a reboot. After that it would only let me cold boot and any reboot would fail with "Out of memory, press any key to continue" message before boot, followed by a kernel panic. Rebuilding initramfs seems to have worked!
    – Lampe2020
    Jun 21 at 19:47

I have a problem with VGA drivers, and thouse solution is not fix my problem.

The main solution which help, its to remove manulaly and install from the outset

// remove modules
sudo rm -rf /lib/modules/4.13.0-3*

remove headers
sudo rm -rf /usr/src/linux-headers-4.13.0-3*

// clear boot
sudo rm -rf /boot/initrd.img-4.13.0-3*
sudo rm -rf /boot/vmlinuz-4.13.0-3*
sudo rm -rf /boot/System.map-4.13.0-3*
sudo rm -rf /boot/config-4.13.0-3*

// refresh grub. I reboot after update grub, but maybe is not important
sudo update-grub

//check the lastes version of linux images
sudo apt-cache search linux-image |grep 4.14

# linux-image-4.14.0-1003-azure-edge - Linux kernel image for version 4.14.0 on 64 bit x86 SMP
# linux-image-extra-4.14.0-1003-azure-edge - Linux kernel extra modules for version 4.14.0 on 64 bit x86 SMP
# linux-image-4.14.0-1004-azure-edge - Linux kernel image for version 4.14.0 on 64 bit x86 SMP
# linux-image-extra-4.14.0-1004-azure-edge - Linux kernel extra modules for version 4.14.0 on 64 bit x86 SMP

// install the lastes verion
sudo apt-get install linux-image-4.14.0-1004-azure-edge linux-headers-4.14.0-1004-azure-edge linux-image-extra-4.14.0-1004-azure-edge 

// restart pc
sudo reboot now
  • 2023 - do NOT do this. Manually ripping out modules and images like this will leave your system in a horrible inconsistent state, causing apt (+dpkg +apt-get) to be incredibly huffy and unhelpful after that. Instead try booting into the older kernel, then running apt remove linux-image-****, replacing the target with whatever your problematic kernel is. AFTER doing that, you can consider trying some of the above if you are still stuck.
    – demaniak
    Jun 5 at 12:13

To do this you need to list the latest ubuntu kernel and reinstall it. Here's a 1 liner

apt install --reinstall `dpkg -l|grep linux-image|grep -v image-generic|cut -d ' ' -f 3|sort -V|tail -1`

if that fails and you want diagnostics you can use this script


# Check if the script is run as root
if [ "$(id -u)" != "0" ]; then
    echo "This script must be run as root. Please use 'sudo' to execute it."
    exit 1

# Get the latest non-generic linux-image package name
latest_package=$(dpkg -l | grep linux-image | grep -v image-generic | cut -d ' ' -f 3 | sort -V | tail -1)

# Check if a package name was found
if [ -z "$latest_package" ]; then
    echo "No valid linux-image package found for reinstallation."
    exit 1

# Reinstall the latest package
echo "Reinstalling the latest linux-image package: $latest_package"
apt install --reinstall "$latest_package"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .