1

I have removed several deprecated 3.16 kernels, however one is still showing up in GRUB and Ubuntu is booting using that kernel. When I run dpkg -l | grep linux-image-3.16.0-51-generic the image is not listed. When I run sudo update-grub it finds the Kernel in /boot and adds it to the list of Kernels to run.

Can I just delete this file? How do I remove this kernel, so that Ubuntu runs under 3.13?

ls /boot screenshot:

ls /boot

dpkg -l | grep screeshot:

dpkg -l

  • 1
    Use the command dpkg -S /boot/vmlinuz-3.16.0-51-generic instead. – jdwolf Jan 11 '18 at 15:08
  • Here's the output: dpkg-query: no path found matching pattern /boot/vmlinuz-3.16.0-51-generic – Ben Payne Jan 11 '18 at 15:26
  • Use the GRUB menu to boot into a 3.13 kernel before trying to remove the last 3.16 kernel. – user535733 Jan 11 '18 at 16:22
  • Thanks. I've done that already several times. When I attempt to delete the image it errors out with 'Unable to locate package <header>'. – Ben Payne Jan 11 '18 at 17:28
0

Remove them with sudo purge-old-kernels (from byobu package), not but hand.
And execute sudo apt-get autoremove afterwards for removing obsolete packages (headers and images).

FIY, you can save this script anywhere and run as root:

$ cat `which purge-old-kernels`

#!/bin/sh
#
#    purge-old-kernels - remove old kernel packages
#    Copyright (C) 2012 Dustin Kirkland <kirkland@ubuntu.com>
#
#    Authors: Dustin Kirkland <kirkland@ubuntu.com>
#             Kees Cook <kees@ubuntu.com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, version 3 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Ensure we're running as root
if [ "$(id -u)" != 0 ]; then
    echo "ERROR: This script must run as root.  Hint..." 1>&2
    echo "  sudo $0 $@" 1>&2
    exit 1
fi

# NOTE: This script will ALWAYS keep the currently running kernel
# NOTE: Default is to keep 2 more, user overrides with --keep N
KEEP=2
# NOTE: Any unrecognized option will be passed straight through to apt
APT_OPTS=
while [ ! -z "$1" ]; do
    case "$1" in
        --keep)
            # User specified the number of kernels to keep
            KEEP="$2"
            shift 2
        ;;
        *)
            APT_OPTS="$APT_OPTS $1"
            shift 1
        ;;
    esac
done

# Build our list of kernel packages to purge
CANDIDATES=$(ls -tr /boot/vmlinuz-* | head -n -${KEEP} | grep -v "$(uname -r)$" | cut -d- -f2- | awk '{print "linux-image-" $0 " linux-headers-" $0}' )
for c in $CANDIDATES; do
    dpkg-query -s "$c" >/dev/null 2>&1 && PURGE="$PURGE $c"
done

if [ -z "$PURGE" ]; then
    echo "No kernels are eligible for removal"
    exit 0
fi

apt $APT_OPTS remove --purge $PURGE
  • Tried..didn't realize it required another package that I don't have. When I ran the command 'sudo purge-old-kernels' I get 'command not found'. Is there another way to do this? – Ben Payne Jan 12 '18 at 3:10
  • It seems that you are not familiar with apt-get. You should install byobu package with sudo apt-get install byobu. – N0rbert Jan 12 '18 at 9:01
  • I should have clarified. I don't want to install an additional package just to handle this one instance. There should be a way to clear this out without needing an additional package. – Ben Payne Jan 12 '18 at 14:35
  • OK, you can save contents of this script to location where you want and use it from here. – N0rbert Jan 12 '18 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.