Skip to content

Commit b64e86c

Browse files
bfieldstorvalds
authored andcommitted
scripts: add "prune-kernel" script to clean up old kernel images
Long ago, Dave Jones complained about CONFIG_LOCALVERSION_AUTO: "I don't use the auto config, because I end up filling up /boot unless I go through and clean them out by hand every time I install a new one (which I do probably a dozen or so times a day). Is there some easy way to prune old builds I'm missing?" To which Bruce replied: "I run this by hand every now and then. I'm probably doing it all wrong" And if he is running it wrong, then so am I - because I've been using this script ever since. It is true that CONFIG_LOCALVERSION_AUTO easily ends up filling your /boot partition if you don't clean up old versions regularly, and this script helps make that easier. Checked with Bruce to see that it's fine to add this to the kernel scripts. Maybe people will come up with enhancements, but more importantly, this way I won't misplace this script whenever I install a new machine and start doing custom kernels for it. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 765bdb4 commit b64e86c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

scripts/prune-kernel

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# because I use CONFIG_LOCALVERSION_AUTO, not the same version again and
4+
# again, /boot and /lib/modules/ eventually fill up.
5+
# Dumb script to purge that stuff:
6+
7+
for f in "$@"
8+
do
9+
if rpm -qf "/lib/modules/$f" >/dev/null; then
10+
echo "keeping $f (installed from rpm)"
11+
elif [ $(uname -r) = "$f" ]; then
12+
echo "keeping $f (running kernel) "
13+
else
14+
echo "removing $f"
15+
rm -f "/boot/initramfs-$f.img" "/boot/System.map-$f"
16+
rm -f "/boot/vmlinuz-$f" "/boot/config-$f"
17+
rm -rf "/lib/modules/$f"
18+
new-kernel-pkg --remove $f
19+
fi
20+
done

0 commit comments

Comments
 (0)