Skip to content

Instantly share code, notes, and snippets.

@jmcaffee
Created March 2, 2016 15:18
Show Gist options
  • Save jmcaffee/9e0cb289b7d0fa896060 to your computer and use it in GitHub Desktop.
Save jmcaffee/9e0cb289b7d0fa896060 to your computer and use it in GitHub Desktop.
Generate a list of old kernels to purge after installing a new kernel
#!/usr/bin/env bash
# See [Ubuntu Forums](http://ubuntuforums.org/showthread.php?t=2240697) and
# [Mark McB](http://markmcb.com/2013/02/04/cleanup-unused-linux-kernels-in-ubuntu/)
# for details.
#
# CAUTION!
# Make sure you've rebooted your system if you've just installed a new kernel
# (so the new kernel is in effect).
#
# Run the following command to see how much space is being taken by your boot partition:
#
# du -h /boot --max-depth=0
#
# Run this script to generate a list of kernels to remove.
# Verify it doesn't contain linux-libc-dev (build tools) and then purge old kernels
# with
#
# create-kernels-to-clean-list | xargs sudo apt-get -y purge
#
# Find out how much space is being taken now...
#
# du -h /boot --max-depth=0
#
#dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d;/linux-libc/d'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment