How to solve the "Package failed to install - initramfs-tools" error?

Insufficient boot disk space


Problem

We get the following error message:

Package failed to install: Error while installing package: installed initramfs-tools package post-installation script subprocess returned error exit status 1

Solution

This problem can be caused by the lack of space on the Boot partition (insufficient boot disk space). if that is the case, we need to increase the space by removing unnecessary kernels.

WARNING: the following operations can destroy your system if applied carelessly. You need to understand what you are doing. It is a synthesis of that worked for me to solve some issues I once encountered with one of my systems. It might not work for you.

It was based on the following pages:

How much boot space do we have ?

df -h ; echo ; df -ih
ls -Sl /boot

What are the available Kernels?

dpkg --list 'linux-image*'

Which one is the current Kernel?

uname -a
echo; dpkg -l \ | awk '!/^rc/ && / \ linux-(c|g|h|i|lo|m|si|t)/{print $1,$2,$3,$4 | \ "sort -k3V | column -t"}'; echo -e "\nCurrent kernel : $(uname -mr)"

Delete unnecessary kernels.

Let's assume you want to delete the version 6.2.0-12345.

version=6.2.0-12345 echo $version

Inspect the content of the folder.

ls -la /boot/*$version*

Remove the folder

sudo rm /boot/*$version*

Complete the original upgrade

We can do this because now we have enough space

sudo apt-get install -f

Remove old kernel packages that are no longer needed.

sudo apt-get remove linux-image-$version-tuxedo sudo apt autoremove
— 19 November 2023