Last time i installed a Linux Update i had again problems - this time something about linux-firmware with out of space error - a bit confusing cause it shouldn't be related to /boot and on / was enough space left. I'm using a LVM partition, so i have a separate /boot with unfortunately only 512MB, so i can have max. 3x Kernels with 2x Kernels installed aprox. 170MB left (so not a real puffer for 3x). If i use now the software-center for updates i often face out-of-space-errors, cause it don't remove older unused kernels and with my terminal funcsave (update && upgrade && autoremove) i'm mostly fine but it's still not safe cause it first install a 3rd kernel and only after that uninstall the oldest. So i'm looking for an intelligent and hopefully easy fix so if there's a new kernel update available i don't want to have any backup-kernel and only my live kernel installed, so i never reached 3x kernel at a time. My only idea was to create a anacron-script or chaining the update-alias just remove any other initrd, vmlinux, config from /boot when there is a newer kernel (with a good hope that hopefully grub-update worked and i'm booted on the newest kernel)
I would make a full system backup then following Brave A.I.:
Linux Firmware Out of Space
The “Linux-Firmware Out of Space Error” typically occurs when the /boot partition is full or nearly full, preventing the installation or upgrade of the Linux kernel and firmware images. Here are some steps to help resolve this issue:
Check disk space usage: Use the df -h command to verify the available space on the /boot partition. This will help identify if the issue is indeed related to a full or nearly full /boot partition.
$ df -h
Filesystem Size Used Avail Use% Mounted on
/boot 237M 235M 0 100% /boot
In this example, the /boot partition is 100% full, indicating the root cause of the error.
Remove unnecessary kernel images: Run the following command to list all installed kernel images:
$ apt list linux-image*
This will show you a list of installed kernel images. Identify any older kernel versions that are no longer needed and remove them using apt purge:
$ sudo apt purge linux-image-<version>
Replace <version> with the actual kernel version you want to remove.
Free up space on the /boot partition: If removing kernel images doesn’t free up enough space, consider deleting unnecessary files or data on the /boot partition. Be cautious when doing so, as this may affect system functionality.
Extend the /boot partition (optional): If the /boot partition is too small, consider extending it. This may require re-partitioning or resizing the disk, which can be complex and potentially data-destructive. It’s recommended to seek professional assistance or use a backup and restore process if you’re unsure.
Update firmware and kernel images: Once you’ve freed up sufficient space on the /boot partition, try updating the firmware and kernel images again using apt update and apt full-upgrade.
Additional Tips:
Regularly monitor disk space usage and consider implementing disk space quotas or automated cleanup tasks to prevent similar issues in the future.
If you’re experiencing issues with firmware updates, ensure that your system’s firmware is up-to-date and compatible with your hardware.
For systems with limited disk space, consider using a more spacious storage device or configuring your system to use a separate partition for firmware and kernel images.
By following these steps, you should be able to resolve the “Linux-Firmware Out of Space Error” and ensure your system can properly update and maintain its firmware and kernel images.
That would be a manual routine but my desire is to create an fail-proof automatic routine, so i don't need to fix it by myself again and again. And tinkering with /boot blocks on a disk without free space in between is riscy.
Can i uninstall the booted kernel during runtime? So just saying i'm booted on 6.8.0-45 and my function is (as pseudo-code) update && upgrade && if 2x initrd then rm initrd-6.8.0-45 && update-grub fi && autoremove should that work?, is it safe? and how do i force it cause it probably would complain? So i delete them by script from /boot via rm and apt remove them (linux-image & linux-hwe) later, if not cleaned by itself.
Edit: I'm mostly concerned about the /boot disk space and if i uninstall a kernel via rm with all parts like config, initrd and vmlinuz i have free disk space and a probably dead package still installed that hopefully got deleted by apt autoremove. Still not sure about that, but even if i got some leftover packages "installed", it's no big deal for a running system. It would be bad, if my grub.cfg point to an non-existing kernel or if a deletion of initrd and vmlinuz during runtime on the same version brick the live session. That thoughts made me look for a unknown maybe better solution than my idea of tempering
Disclaimer - im not in the need of a solution anymore but i'm still curious about my question below that occur during development. I'll post my script that worked for me later below and mark it as answered.
Optimization-Question about WIldcards from previous script-version, that wasn't succesful. In the below Code i tried to use Wildcards especially at the end to accommodate that some packages end with the Version and other has a "-generic" added to the end. In my earlier version the for-loop works but only for packages like linux-hwe-*tools-$version*, so wheres no -generic added and * stands for nothing. But in the other case it doesn't work. So i'm curious if it's wrong to use a wildcard at the end and it was something else or if that's wrong.
for package in linux-hwe-*tools-$version* linux-modules-$version* linux-modules-extra-$version* linux-headers-$version* linux-hwe-*headers-$version*; do
I would not use the wildcard in that manner. It is broad and using it for versions could supply any version. Using it for the HWE kernel could match any package name that contains "linux-hwe-", followed by anything before "tools".
You can echo your current version, then echo available version, then use dkpg --compare-versions to select a higher version only.
My Solution as Anacron-Job:
This script limit my active kernel to 1 on the long run, so i'll have maximal 2x Kernel active during session after installing the newest. With 512MiB it was always very close to limit with 3x Kernels back to back and so i'm out of danger. If someone with separated /boot-partition (not under /) like with LVM is interested as well - i share my bash-script. As reminder you need cron and anacron installed and it will remove older kernels only after successfully booting with the newest.
touch clear_kernel #follow cron-pattern without .sh
chmod 755 clear_kernel #rwxr-xr-x
chown root:root clear_kernel #follow patterns with root as owner
sudo nano clear_kernel #paste code from below
sudo mv clear_kernel /etc/cron.daily/ #you don't need to adjust config from anacron
#!/bin/bash
# bash-script for limiting the kernel to latest, ensuring no older Backup is active
# extract bootet kernel like 6.8.0-40
current_version=$(uname -r| awk -F'-' '{print $1"-"$2}')
# list all Kernel-(Images, Modules, HWE)
kernels=$(dpkg --list | grep -E "linux-(image|modules|modules-extra|hwe)" | awk '{print $2}' | sort -V)
# remove older kernel that are older than current with this for-loop
for kernel in $kernels; do
# extract Versionnumber from package
kernel_version=$(echo $kernel | grep -oP "\d+\.\d+\.\d+-\d+")
# if package don't include version-number and is for generic use, skip it
if [ -z $kernel_version ]; then
continue
fi
# limit that only versions older than current is deleted and not any newer new installed one
if dpkg --compare-versions $kernel_version lt $current_version; then
sudo apt purge -y $kernel
fi
done
# clean remaining headers and tools from older unused kernels
headers_and_tools=$(dpkg --list | grep -E "linux-(headers|tools)" | grep -P "\d+\.\d+\.\d+-\d+" | awk '{print $2}')
for item in $headers_and_tools; do
# extract version number form package name
item_version=$(echo $item | grep -oP "\d+\.\d+\.\d+-\d+")
# skip generic packages without version number
if [ -z $item_version ]; then
continue
fi
# only delete packages if they are odler than current bootet kernel-version
if dpkg --compare-versions $item_version lt $current_version; then
sudo apt purge -y $item
fi
done