15

20.04.2 on ThinkPad X1 C7:

An update eaves me unable to complete the startup. I end up with initramfs command line, with "gave up waiting for root device" and "/dev/mapper/ubuntu-vg-root doesn't exist" information.

Loading the previous kernel -- 5.8.0-50 from GRUB, which shows 5.8.0-53 as the newest -- seems to be working. But I'm not sure how to remove the newer kernel. Grateful for any help on this.

Thanks.

Dan Gillmor
  • 497
  • 1
  • 4
  • 15

2 Answers2

29

The following steps will remove a given kernel along with its drivers drivers, and lets the package manager know that you don’t want it again if you do an update. You should remove the specific broken kernel and it’s headers, don’t remove the super package linux-generic this is the package that Ubuntu uses to upgrade the kernel and headers when they become available. If you remove it you wont get kernel updates automatically and will have to specifically run apt-get to get them.

  1. Open Terminal (if it’s not already open)
  2. List the available kernels:
    dpkg -l | grep linux-image
    
  3. Remove the kernel(s) you don’t want:
    sudo apt-get purge linux-image-5.8.0-53-generic
    
  4. Remove the headers as well:
    sudo apt-get purge linux-headers-5.8.0-53-generic
    
  5. Reboot

On reboot, hold Shift down during boot and confirm that the broken kernel is not a choice in the grub advanced settings.

Because you haven't removed the linux-generic package itself, Ubuntu will still attempt to get a new kernel when one is available, just not the one you specifically purged.

Thats all there is to it

matigo
  • 24,752
  • 7
  • 50
  • 79
-1

You can also use this script which if you pass a parameter ex "5.15.0-82" will keep the current the kernel and delete all the rest

CURRENT_KERNEL=$(uname -a | cut -d' ' -f3) # keeps the currently running kernel

EXCLUDE=${1:-$CURRENT_KERNEL}

echo "To excude $EXCLUDE" KERNELS=$(dpkg -l | grep linux-image)

for KERNEL in $KERNELS; do if [[ "$KERNEL" == "linux" ]]; then if [[ "$KERNEL" == "$EXCLUDE" ]]; then echo "Skipping $KERNEL" continue fi sudo apt purge -y "$KERNEL" fi done

sudo apt autoremove -y

echo "Available kernes" dpkg -l | grep linux-image