Ubuntu /boot/ filling up, old kernels issue help

Don
Joined
21 Oct 2002
Posts
46,744
Location
Parts Unknown
Hi,


I have a Ubuntu 18.04.3 LTS install (which has been upgraded from around 12.04. /boot/ keeps filling up and shows old kernels

dpkg -l | grep linux-image

Shows..

1lp6xcv.png

How do I go about fixing this? I assume I need to take out the grub entries, then remove the files.

Cheers
 

Attachments

  • upload_2019-10-10_14-47-31.png
    upload_2019-10-10_14-47-31.png
    124.5 KB · Views: 1

SMN

SMN

Soldato
Joined
2 Nov 2008
Posts
2,502
Location
The ether
apt autoremove ? Always did the trick for me in previous versions, no grub editing needed.
I've found ubuntu generally does a rubbish job at cleaning up /boot, i regularly have to manually remove old kernels from /boot before running 'apt-get -f install' or the 'dpkg reconfigure' command (i forget the syntax).

OP, if 'apt autoremove' fails, you can do an ls in /boot and find the old kernels and delete them all except the one your on now (uname -r) and potentially another, just for safety. Then run 'apt-get update' and follow the trail :)
 
Associate
Joined
5 Sep 2013
Posts
17
This just prompted me to tidy up a couple of machines, here's what I came up with:

Code:
dpkg -l | grep 'ii  linux-image\|ii  linux-headers\|ii  linux-modules\|ii  linux-tools' | cut -d ' ' -f3 | grep -v `uname -r | cut -d '-' -f1-2` | grep '[0-9]' > oldKernels && sudo apt remove `cat oldKernels`

List available packages (dpkg -l)
Filter down to the target packages, that are also installed (grep 'ii linux-image\|ii linux-headers\|ii linux-modules\|ii linux-tools')
Chop the line up and just get the package name (cut -d ' ' -f3)
Filter out the packages for the currently running kernel (grep -v `uname -r | cut -d '-' -f1-2`)
Filter down to packages containing numbers to exclude linux-image-generic etc (grep '[0-9]')

Finally redirect the list of packages to a file and uninstall them.
This worked for me, but check the list of packages carefully before pressing y!
 
Soldato
Joined
10 Oct 2005
Posts
8,706
Location
Nottingham
apt autoremove works just fine for me on both Ubuntu 16.x and 18.x

Or on CentOS something like package-cleanup assuming your max number of installed kernels is set higher than you actually want (fix that as well)
 
Don
OP
Joined
21 Oct 2002
Posts
46,744
Location
Parts Unknown
Was going around in circles.

Ended up just doing this.

I found that it is far easier to abandon the small partition and move /boot to the root. This also prevents any out of space issues in the future.

First move your data from the boot partition to root (run as sudo -s):

cp -a /boot /boot2
umount /boot
rmdir /boot
mv /boot2 /boot

Remove (or comment) the /boot entry in /etc/fstab:

vim /etc/fstab

Update grub and make sure everything is correct:

update-grub

apt should now be able to upgrade without problems.

This leaves an unused 200mb partition (which you could use for something else if you find it worth the trouble).
 
Back
Top Bottom