So every now and then when working with some system there are times it just works so good you kind of forget about it and in those times when looking back at it it’s already lagging behind the times, getting cluttered with the digital equivalent of dust bunnies? Yeah that happens to me too.

  • Kernel Images (linux-image-*): These are the actual kernel binaries. Each version installed on your system occupies disk space and appears in the GRUB menu.
  • Kernel Headers (linux-headers-*): These files are necessary to build modules, such as drivers, for a specific kernel version. They’re essential for developers or anyone needing to compile specific kernel modules.
  • DKMS (Dynamic Kernel Module Support): Allows kernel modules to be automatically rebuilt when you install a new kernel. This is crucial for maintaining kernel module functionality across updates.
  1. List Installed Kernels

    dpkg --list | grep linux-image # List all installed kernels
    
  2. Identify the Current Kernel

    uname -r # Do not remove this kernel version !! ⚠️
    
  3. Remove Old Kernels Replace version with the kernel version you wish to remove. Avoid removing the current kernel.

    sudo apt remove --purge linux-image-4.7* linux-headers-4.7* # Remove both image and headers
    
  • Never remove the currently active kernel (uname -r).
  • Keep at least one or two previous kernels as a fallback.
  • Consider creating a system backup before removing kernels manually.

Fixing Kernel Installation Issues

Kernel updates can sometimes fail, leaving your system in an inconsistent state. Here are steps to address to fix issues that might arise…

  1. Update and Upgrade Packages Ensure your package lists and installed packages are up to date.

    sudo apt update
    sudo apt upgrade
    
  2. Reinstall Kernel Headers If specific kernel headers are causing issues, try reinstalling them.

    sudo apt reinstall linux-headers-$(uname -r)
    
  3. Manual DKMS Module Rebuild Rebuild and reinstall any problematic DKMS modules.

    sudo dkms build -m module_name -v module_version -k $(uname -r) # Build the module
    sudo dkms install -m module_name -v module_version -k $(uname -r) # Install the module
    
  4. Resolve Dependency Issues Fix broken packages that might be causing kernel issues.

    sudo apt --fix-broken install
    

Quick and Easy: Using apt with a Side of Automation

For those who prefer a set-it-and-forget-it approach:

sudo apt autoremove --purge

This little gem tells your system, “Hey, get rid of the kernels collecting dust, but leave me the latest and greatest, plus a spare, just in case.”

DIY Style: Manual Cleanup

Roll up your sleeves and dive into kernel hell, but be very cautions when playing around here:

dpkg --list | grep linux-image # Spot the old kernels
uname -r # Don't touch this one. It's your system's current heartbeat.
sudo apt remove --purge linux-image-old-kernel-123 linux-headers-old-kernel-123 # Swap 'old-kernel-version' with the actual version numbers, but tread carefully.

Upgrading your distro

The Big Move: Upgrading to a New Release

  1. Update your sources.list to point to the new release. For instance, moving from bullseye to bookworm:
    sudo sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list
    sudo sed -i 's/bullseye/bookworm/g' /etc/apt/sources.list.d/*.list
    
  2. Ensure the terminal sticks to English to avoid any lost-in-translation moments (which surely does happen on macs for some reason).
    export LC_ALL=C
    

Prep Work: Out with the Old, In with the Updated

  1. Spot any Packages you might have set to hold: Check for packages that refused to leave as these might actually cause trouble.

    sudo apt-mark showhold
    

    If any, decide whether to kick them out (sudo apt-mark unhold package_name).

  2. Update and Upgrade

    sudo apt update && sudo apt upgrade
    sudo apt full-upgrade # This will run the full upgrade
    sudo apt autoremove # And finally, out with the old, in with the new
    

After a final sudo apt update && sudo apt upgrade and a nice little reboot, you’re all set with a system that’s not just cleaned up but also upgraded.

So, there you have it—a guide to decluttering those old kernels and giving your system a fresh start.



Buy Me a Coffee