raspi-user.france
Posts: 15
Joined: Mon Jan 09, 2017 11:31 am

Disk space eaten up by old kernels/modules - remove old kernels

Fri Dec 21, 2018 3:26 pm

I'm running low on disk space on my Raspberry Pi running Raspbian Lite. I searched around and found that most of the disk space is used by old kernel modules (I think). What I see is:

Code: Select all

/lib/modules $ ls -A
4.14.20+     4.14.33-v7+  4.14.44+     4.14.72-v7+  4.14.78+     4.14.81-v7+  4.9.60+     4.9.68-v7+  4.9.76+
4.14.20-v7+  4.14.37+     4.14.44-v7+  4.14.73+     4.14.78-v7+  4.9.53+      4.9.60-v7+  4.9.70+     4.9.76-v7+
4.14.21+     4.14.37-v7+  4.14.48+     4.14.73-v7+  4.14.79+     4.9.53-v7+   4.9.64+     4.9.70-v7+  4.9.77+
4.14.21-v7+  4.14.39+     4.14.48-v7+  4.14.74+     4.14.79-v7+  4.9.56+      4.9.64-v7+  4.9.73+     4.9.77-v7+
4.14.24+     4.14.39-v7+  4.14.54+     4.14.74-v7+  4.14.80+     4.9.56-v7+   4.9.65+     4.9.73-v7+  4.9.79+
4.14.24-v7+  4.14.42+     4.14.54-v7+  4.14.77+     4.14.80-v7+  4.9.57+      4.9.65-v7+  4.9.75+     4.9.79-v7+
4.14.33+     4.14.42-v7+  4.14.72+     4.14.77-v7+  4.14.81+     4.9.57-v7+   4.9.68+     4.9.75-v7+
/lib/modules $ du -hs
3.3G    .
/lib/modules $
Is this normal or am I doing something wrong? I would like to remove all old kernels (except the current one 4.14.81-v7 and maybe one previous one).
I'm anxious to just delete these folders manually with "sudo rm -r ..." as this might break something else (thinking of dependencies). I tried and searched if "apt ..." can be used to get rid of old kernels but also with no luck so far.

Any ideas, hint, comments or background information on what I see regarding my disk usage and how to get rid of the old kernels?

fbe
Posts: 639
Joined: Thu Aug 17, 2017 9:08 pm

Re: Disk space eaten up by old kernels/modules - remove old kernels

Fri Dec 21, 2018 3:58 pm

Don't run rpi-update.

ericcooper
Posts: 140
Joined: Sat Apr 08, 2017 6:23 pm

Re: Disk space eaten up by old kernels/modules - remove old kernels

Fri Dec 21, 2018 5:02 pm

The latest version of the raspberrypi-kernel package in stretch ships the 4.14.79{,-v7+} modules directories. I guess the .80 and .81 versions came from pi-update, which as mentioned you don't need to be using, just apt update and upgrade.

So you can manually remove (rm -r) modules directories older than 4.14.79. There aren't any dependencies on them other than the corresponding kernels themselves, which are probably no longer present (check /boot to be sure).

User avatar
DougieLawson
Posts: 38862
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Disk space eaten up by old kernels/modules - remove old kernels

Fri Dec 21, 2018 5:10 pm

If you must run rpi-update run

PRUNE_MODULES=1 rpi-update

Although the best strategy is NEVER run rpi-update.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

MrEngman
Posts: 4022
Joined: Fri Feb 03, 2012 2:17 pm
Location: Southampton, UK

Re: Disk space eaten up by old kernels/modules - remove old kernels

Fri Dec 21, 2018 5:51 pm

I'm running Raspbian lite on most of my PI and have used sudo rm -r /lib/modules/... to remove old kernel version module directories and haven't noticed any issues.
Simplicity is a prerequisite for reliability. Edsger W. Dijkstra

Please post ALL technical questions on the forum. Please Do Not send private messages.

raspi-user.france
Posts: 15
Joined: Mon Jan 09, 2017 11:31 am

Re: Disk space eaten up by old kernels/modules - remove old kernels

Sat Jan 05, 2019 8:41 am

Thanks for the feedback - I manually removed the old kernels/moduls and it seems to be working fine (and finally giving me back my disk-space)!

One question: what is the purpose of "rpi-update" at all (if one should not use it and it only messes up an installation)?

User avatar
rpdom
Posts: 17022
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Disk space eaten up by old kernels/modules - remove old kernels

Sat Jan 05, 2019 8:56 am

raspi-user.france wrote:
Sat Jan 05, 2019 8:41 am
One question: what is the purpose of "rpi-update" at all (if one should not use it and it only messes up an installation)?
Originally it was the only way to update the kernel, modules and bootloader for the Pi. Now that they have all been packaged up neatly, it is not needed by 99% of users.

Now it is used to get experimental versions of the kernel etc for testing purposes. Some of these kernels will eventually be packaged up and become available via apt-get as normal. Generally if you use rpi-update you should be aware that the resulting updates may not have been fully tested yet and could break your system. You are expected to be able to fix it yourself f that happens.

Return to “Raspberry Pi OS”