# Dry run to check
bash remove-old-kernels.sh
# Run
bash remove-old-kernels.sh exec
# Which kernel are you using?
uname -r
# Which kernels are installed ?
dpkg --list | egrep 'linux-image|linux-headers'
ii
– indicates packages that are currently installediU
– package has been unpacked and will be used next rebootrc
– package already removed, but the configuration files are still present
autoremove
alone remove older kernels only, but any package that is not needed as a dependency of other packages along with its configuration files.
# Will autoremove every packages that qualify for it
apt-get autoremove --purge
# Remove all configuration files that are still present despite the removed package
dpkg --list | egrep 'linux-image|linux-headers' | grep rc | awk '{print $2}' | xargs apt purge -y
# Remove and purge one particular package
# Be careful not to remove your current kernel !
yes | apt purge "linux-image-XXXXX"
autoremove
will only remove packages that are automatically installed. If you ever updated or added a kernel package manually autoremove will not remove it. If you ever "held" a kernel version autoremove will not remove it. If you're wondering why Ubuntu is filling up your boot partition with kernels you no longer use it's likely one of these two reasons.
# Unhold all packages
dpkg --get-selections | grep hold | awk '{ print $1, "install" }' | dpkg --set-selections
# Mark all "manually installed" kernel packages as "automatically installed"
for f in $(apt-mark showmanual | grep linux-); do
apt-mark auto $f
done
# Remove all packages that are no longer needed
apt-get -y autoremove --purge
/boot/firmware
could get full after an Ubuntu (for RPi) upgrade. Solution above still apply but there is also linux-firmware-*
to consider.
# list "firmware" packages
dpkg --list | grep "firmware"
# Show where files are installed. To confirm they are well in /boot/firmware
package=linux-firmware-raspi
dpkg -L $package
# or to see which $file belongs to wich package (could be a long execution time)
dpkg -S $file
Find heavy files in /boot/firmware
:
find /boot/firmware -size +8M -exec ls -lgd {} \;
Sometime you will find some *.bak
files. If everything works well, then remove them.
rm -rf /boot/firmware/*.bak
Best, do not install Ubuntu on a RPi. This is a bad distribution.
Dive into Ubuntu community documentation to remove old kernel