Reset Search
 

 

Article

HOW TO Remove Older Kernel Packages From An Appliance To Free Disk Space Or Recover From Out of Disk Space

« Go Back

Information

 
TitleHOW TO Remove Older Kernel Packages From An Appliance To Free Disk Space Or Recover From Out of Disk Space
Objective
  • To purge obsolete kernel packages from boot partition to reserve space for future kernel upgrades or to recover from an out of disk space condition.
Environment
  • Extreme Management Center (XMC, formerly Netsight)
  • Extreme Control (NAC)
  • Extreme Analytics (formerly purView)
  • Ubuntu
Procedure
  • Determine the amount of disk space free in the /boot partition:
root@xmc:~$ df -h /boot
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 472M 157M 291M 36% /boot
  • If the amount of available space is less than 140M proceed with INSUFFICIENT DISK SPACE; otherwise proceed with SUFFICIENT DISK SPACE.

INSUFFICIENT DISK SPACE IN /boot
 
Identity and purge the oldest kernel installed.
  1. Identity the kernel currently active on the system. This is NOT to be removed.
root@xmc:~$ uname -r 
4.15.0-43-generic
  1. Identify the oldest kernel image as a candidate for removal.
root@xmc:~$ dpkg --list | grep linux-image-[0-9] | awk '{print $2}' | sort -V | head -n -2
linux-image-4.4.0-165-generic
  1. Forcibly purge the candidate kernel from the system to free space, substituting the version and build numbers respectively from step 2 above:
root@xmc:~$ dpkg --purge --force-all linux-image-4.4.0-165-generic
root@xmc:~$ rm /var/lib/initramfs-tools/4.4.0-165-generic
root@xmc:~$ dpkg --purge --force-all linux-modules-4.4.0-165-generic
root@xmc:~$ dpkg --purge --force-all linux-modules-extra-4.4.0-165-generic
root@xmc:~$ rm /boot/initrd.img-4.4.0-165-generic
  1. [optional] Remove any lingering initramfs profiles for non-existent kernels by comparing the installed kernels with the contents of the initramfs-tools sub-directory. Remove (rm) any files that do not match the first list:
root@xmc:~$ dpkg --list | grep linux-image-[0-9] | awk '{print $2}' | sort -V
linux-image-4.4.0-165-generic
linux-image-4.15.0-43-generic
linux-image-4.15.0-65-generic
root@xmc:~$ ls -al /var/lib/initramfs-tools/
total 20
drwxr-xr-x  2 root root 4096 Oct  9 10:21 ./
drwxr-xr-x 47 root root 4096 Sep 17 12:08 ../
-rw-r--r--  1 root root   77 Oct  9 10:26 4.15.0-43-generic
-rw-r--r--  1 root root   77 Oct  9 10:23 4.15.0-65-generic
-rw-r--r--  1 root root   77 Oct  9 10:28 4.4.0-165-generic
-rw-r--r--  1 root root   77 Oct  9 10:28 4.4.0-83-generic
root@xmc:~$ rm /var/lib/initramfs-tools/4.4.0-83-generic
  1. Update initramfs (initrd images) and the grub boot loader:
root@xmc:~$ export BOOT_PART_SIZE=`df /boot | grep /boot | awk '{ print $4 }'`
root@xmc:~$ echo "/boot size is currently $BOOT_PART_SIZE kB"
root@xmc:~$ sed -i 's/COMPRESS=gzip/COMPRESS=xz/' /etc/initramfs-tools/initramfs.conf
root@xmc:~$ update-initramfs -u -k all
root@xmc:~$ export BOOT_PART_SIZE=`df /boot | grep /boot | awk '{ print $4 }'`
root@xmc:~$ echo "/boot size is now $BOOT_PART_SIZE kB"
root@xmc:~$ update-grub


SUFFICIENT DISK SPACE IN /boot (aka housekeeping)
  1. Use steps 1 and 2 above to identify the candidate versions for removal.
  2. Use apt-get to gracefully remove the kernel packages:
root@xmc:~$ apt-get remove linux-image-4.4.0-165-generic
root@xmc:~$ apt-get remove linux-modules-extra-4.4.0-165-generic
  1. Update initramfs (initrd images) and the grub boot loader as noted above in step 5.
Additional notes

Feedback

 

Was this article helpful?


   

Feedback

Please tell us how we can make this article more useful.

Characters Remaining: 255