Skip to content

Instantly share code, notes, and snippets.

@reflexdemon
Last active March 13, 2020 14:56
Show Gist options
  • Save reflexdemon/42751c787d4b90a50bef4643d091e03e to your computer and use it in GitHub Desktop.
Save reflexdemon/42751c787d4b90a50bef4643d091e03e to your computer and use it in GitHub Desktop.
recover /boot space

I recently was trying to boot my old linux mint laptop and got a error message that my /boot was full. I did google for the solution and finally found a way to claim the space by removing old and unused space by just using the below script.

#!/usr/bin/env bash

OLDCONF=$(dpkg -l|grep "^rc"|awk '{print $2}')
CURKERNEL=$(uname -r|sed 's/-*[a-z]//g'|sed 's/-386//g')
LINUXPKG="linux-(image|headers|ubuntu-modules|restricted-modules)"
METALINUXPKG="linux-(image|headers|restricted-modules)-(generic|i386|server|common|rt|xen)"
OLDKERNELS=$(dpkg -l|awk '{print $2}'|grep -E $LINUXPKG |grep -vE $METALINUXPKG|grep -v $CURKERNEL)
YELLOW="\033[1;33m"
RED="\033[0;31m"
ENDCOLOR="\033[0m"
sudo apt-get purge $OLDKERNELS

Just put this in a file say, cleanup_kernal.sh and runas root. That is it! Enjoy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment