Howto: Free disk space when /boot is full

Updated . Posted . Visible to the public.

Easy mode

This method will remove automatically installed packages that no other packages depend on any more. This, of course, includes obsolete kernel versions, with the explicit exception of the currently running kernel, the kernel version that was installed on the system before that and, of course, the latest updated version of the kernel. However, it will also remove any and all other packages that have been marked as installed automatically but have no other packages depending on them. This could lead to unexpected removal of packages. So please check the output of sudo apt-get autoremove closely.

One-shot, manual method

sudo apt-get autoremove

Automatically remove unused packages

Edit /etc/apt/apt.conf.d/50unattended-upgrades and un-comment the line Unattended-Upgrade::Remove-Unused-Dependencies "true";.

Hard mode (for old Ubuntus)

uname -r prints currently used kernel version. You should not remove the current kernel, linux-image-generic and linux-image.

sudo apt-get clean
dpkg --list |  grep 'ii  linux-image' |  awk '{ print $2 }' | sort -V
uname -r
sudo apt-get purge linux-image-x.y.z-generic
sudo apt-get autoremove

Removing multiple kernel versions with one command (long and short version):

sudo apt-get purge linux-image-1.2.4-generic
sudo apt-get purge linux-image-1.2.7-generic
sudo apt-get purge linux-image-1.2.8-generic
sudo apt-get purge linux-image-1.2.9-generic
sudo apt-get purge linux-image-1.2.{4,7..9}-generic

Compress initramfs

You might still not have enough space in /boot because even one kernel image alone takes up too much space. Then you can additonally change the compression algorithm for your initramfs, which makes it compress much smaller. This has an effect on boot time because it takes slightly longer to decompress. Should you do this change because of a do-release-upgrade (distribution upgrade), then this will likely be changed to another algorithm with the upgrade.

sudo vim /etc/initramfs-tools/initramfs.conf

Change the line with COMPRESS to the following:

COMPRESS=lzma

Afterwards rebuild your kernel image:

sudo update-initramfs -u -k all

After this it makes sense to do a reboot.

Check size of /boot

To check what takes up the space in /boot

df -h | grep boot
ls -lha /boot

Sources for more information when necessary

Geordi

We have a tool, called geordi Show archive.org snapshot , which helps you to remove old kernels (available in geordi < 1.7.0). You need to run this command as root.

# rvm
gem install geordi
rvmsudo geordi purge-kernels
# rbenv
sudo gem install geordi
sudo geordi purge-kernels
Last edit
Simon Hofmann
Keywords
delete, remove, old, kernel, versions, boot, partition
License
Source code in this card is licensed under the MIT License.
Posted by Emanuel to makandra dev (2016-12-05 09:12)