Need a fix for `dpkg --configure -a` hanging on `update-initramfs`

Ubuntu Version:
Distributor ID: Ubuntu
Description: Ubuntu 24.04.1 LTS
Release: 24.04
Codename: noble

Desktop Environment (if applicable):
GNOME, LXDE, i3

Problem Description:
After some apt-get issues (lock /var/lib/dpkg) I have got to the point, where I was asked to execute

sudo dpkg --configure -a

however it would hang at:

update-initramfs: Generating /boot/initrd.img-6.8.0-52-generic

It is not an issue with the boot partition size since is 20% occupied.

After applying some method listed below seemed to be solved but now I got back to the same point.

Relevant System Information:
ls /boot/

-rw-r--r-- 1 root root   287413 Nov 30 19:21 config-6.8.0-51-generic
-rw-r--r-- 1 root root   287413 Jan 10 18:18 config-6.8.0-52-generic
drwxr-xr-x 3 root root     4096 Jan  1  1970 efi
drwxr-xr-x 6 root root     4096 Dec 21 13:44 grub
lrwxrwxrwx 1 root root       27 Feb  5 06:50 initrd.img -> initrd.img-6.8.0-52-generic
-rw-r--r-- 1 root root        0 Mar 25 12:51 initrd.img-5.15.0-130-generic.new
-rw-r--r-- 2 root root 73488769 Dec 21 12:34 initrd.img-6.8.0-51-generic
-rw-r--r-- 2 root root 73488769 Dec 21 12:34 initrd.img-6.8.0-51-generic.dpkg-bak
-rw-r--r-- 1 root root        0 Mar 25 12:50 initrd.img-6.8.0-51-generic.new
-rw-r--r-- 1 root root 73515958 Apr  3 13:29 initrd.img-6.8.0-52-generic
lrwxrwxrwx 1 root root       27 Feb  5 06:50 initrd.img.old -> initrd.img-6.8.0-51-generic
drwx------ 2 root root    16384 Feb 21  2024 lost+found
-rw-r--r-- 1 root root   142796 Apr  8  2024 memtest86+ia32.bin
-rw-r--r-- 1 root root   143872 Apr  8  2024 memtest86+ia32.efi
-rw-r--r-- 1 root root   147744 Apr  8  2024 memtest86+x64.bin
-rw-r--r-- 1 root root   148992 Apr  8  2024 memtest86+x64.efi
-rw------- 1 root root  9072978 Nov 30 19:21 System.map-6.8.0-51-generic
-rw------- 1 root root  9072978 Jan 10 18:18 System.map-6.8.0-52-generic
drwxr-xr-x 3 root root     4096 Apr  9  2024 UefiBoot
lrwxrwxrwx 1 root root       24 Feb  5 06:50 vmlinuz -> vmlinuz-6.8.0-52-generic
-rw------- 1 root root 14969224 Nov 30 20:09 vmlinuz-6.8.0-51-generic
-rw------- 1 root root 14965128 Jan 10 23:24 vmlinuz-6.8.0-52-generic
lrwxrwxrwx 1 root root       24 Feb  5 06:50 vmlinuz.old -> vmlinuz-6.8.0-51-generic


What I’ve Tried:

:white_check_mark: Solution Overview

Since running update-initramfs manually works, the fix was to bypass the post-install script used by dpkg, allowing it to complete successfully.


:toolbox: Working Solution Steps

1. Manually Run update-initramfs with Swap Off

sudo swapoff /dev/sda3
sudo update-initramfs -v -c -k 6.8.0-52-generic

2. Back Up the Original Post-Install Script

sudo cp /var/lib/dpkg/info/linux-image-6.8.0-52-generic.postinst \
         /var/lib/dpkg/info/linux-image-6.8.0-52-generic.postinst.bak

3. Replace the Script with a No-Op Version

echo -e '#!/bin/sh\nexit 0' | sudo tee /var/lib/dpkg/info/linux-image-6.8.0-52-generic.postinst > /dev/null
sudo chmod +x /var/lib/dpkg/info/linux-image-6.8.0-52-generic.postinst

4. Run dpkg to Complete Configuration

sudo dpkg --configure -a

This now finishes without invoking the problematic logic.

5. Restore the Original Script (Optional, Recommended)

sudo mv /var/lib/dpkg/info/linux-image-6.8.0-52-generic.postinst.bak \
         /var/lib/dpkg/info/linux-image-6.8.0-52-generic.postinst

:white_check_mark: Post-Fix Cleanup

  • Re-enable swap:
sudo swapon /dev/sda3

Regards
Chris

What’s in the logs when the system is hanging?

journalctl -f

1 Like

Your last step:

So your postinst-script has never been run?

I searched for a postinst-script on my system and found ./linux-image-6.11.0-21-generic.postinst:

#!/bin/sh
set -e

version=6.11.0-21-generic
image_path=/boot/vmlinuz-$version

#
# When we install linux-image we have to run kernel postinst.d support to
# generate the initramfs, create links etc.  Should it have an associated
# linux-image-extra package and we install that we also need to run kernel
# postinst.d, to regenerate the initramfs.  If we are installing both at the
# same time, we necessarily trigger kernel postinst.d twice. As this includes
# rebuilding the initramfs and reconfiguring the boot loader this is very time
# consuming.
#
# Similarly for removal when we remove the linux-image-extra package we need to
# run kernel postinst.d handling in order to pare down the initramfs to
# linux-image contents only.  When we remove the linux-image need to remove the
# now redundant initramfs.  If we are removing both at the same time, then
# we will rebuilt the initramfs and then immediatly remove it.
#
# Switches to using a trigger against the linux-image package for all
# postinst.d and postrm.d handling.  On installation postinst.d gets triggered
# twice once by linux-image and once by linux-image-extra.  As triggers are
# non-cumulative we will only run this processing once.  When removing both
# packages we will trigger postinst.d from linux-image-extra and then in
# linux-image postrm.d we effectivly ignore the pending trigger and simply run
# the postrm.d.  This prevents us from rebuilding the initramfs.
#
if [ "$1" = triggered ]; then
    trigger=/usr/lib/linux/triggers/$version
    if [ -f "$trigger" ]; then
	sh "$trigger"
	rm -f "$trigger"
    fi
    exit 0
fi

if [ "$1" != configure ]; then
    exit 0
fi

depmod $version

if [ -f /lib/modules/$version/.fresh-install ]; then
    change=install
else
    change=upgrade
fi
linux-update-symlinks $change $version $image_path
rm -f /lib/modules/$version/.fresh-install

if [ -d /etc/kernel/postinst.d ]; then
    mkdir -p /usr/lib/linux/triggers
    cat - >/usr/lib/linux/triggers/$version <<EOF
DEB_MAINT_PARAMS="$*" run-parts --report --exit-on-error --arg=$version \
      --arg=$image_path /etc/kernel/postinst.d
EOF
    dpkg-trigger --no-await linux-update-$version
fi

exit 0

If I’m understanding this right your postinst-script has never been run and the postinst tasks after installation have never been executed.

I’ve had this issue too. Before doing an upgrade I always take a backup using QT-fsarchiver.

I tried all sorts of shenanigans to rectify this error but finally gave up and restored my backup. I then wait for the updates to be sorted out and then try again.
Life’s too short and I ain’t got much of it left to be messing around with failed kernel/distro updates.

1 Like

Hi, there is nothing special there I guess:

May 05 14:22:59 22805B6 sudo[1255151]:   herman : TTY=pts/8 ; PWD=/home/herman ; USER=root ; COMMAND=/usr/bin/apt-get install libcgal-dev
May 05 14:22:59 22805B6 sudo[1255151]: pam_unix(sudo:session): session opened for user root(uid=0) by herman(uid=1001)

I have also found that linux-image-6.8.0-52-generic was listed when executing
apt-mark showhold command, I have unlock it but still trying to install something stops here:

/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-5.15.0-130-generic

My effort to help, and it’s not a good suggestion for all…

When the process stops at /etc/kernel/postrm.d/initramfs-tools: update-initramfs: Deleting (Just an example) /boot/initrd.img-5.15.0-130-generic , it indicates that the system is attempting to remove an old initramfs image file for the specified kernel version.

This step is part of the cleanup process after removing a kernel package. If the deletion process is hanging or failing, it could be due to insufficient permissions, file system issues, or the file being in use by another process.

Caution you can manually delete the file or check for any errors that might be preventing the deletion. Ensure that the file is not being used by any running processes and that you have the necessary permissions to delete it.

ls /boot|grep initrd.img
initrd.img
initrd.img-6.14.0-13-generic
initrd.img-6.14.0-15-generic
initrd.img.old

Best Offer a new clean stock install. Sorry it’s not what you after.

@1fallen thank you for some clarifications.
I have checked and there was no such fille like /boot/initrd.img-5.15.0-130-generic. What I have found there was a 0 size initrd.img-5.15.0-130-generic.new, which I removed.
after running sudo dpkg --configure -a I get to the same point:

/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-5.15.0-130-generic

Any other hint ?

You can check your file system as suggested by @1fallen

1 Like

Can you show us this please: (No SUDO Please!)

update-initramfs -u -v

I hope you are a good follower of Personal back-ups, I still feel you would be ahead of the game on fresh Install…

After rebooting it started to work. Lets see how far it will go now.

Please let us know how it holds up. :slight_smile:
If more problems and or errors crop up include this please:

ps faux|grep sync

I might have a theory here! (No Promise though)

Sure I will. By the moment thank you for help.

1 Like