Apt upgrade stuck generating grub configuration file?

Just did sudo apt update followed by sudo apt upgrade in a terminal and am now stuck with a progress bar at 98% for the last hour or so, apparently stuck at generating a new grub config file? The last lines look like this:

...
Processing triggers for linux-image-4.18.0-21-generic (4.18.0-21.22~18.04.1) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-4.18.0-21-generic
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.18.0-21-generic
Found initrd image: /boot/initrd.img-4.18.0-21-generic
Found linux image: /boot/vmlinuz-4.18.0-20-generic
Found initrd image: /boot/initrd.img-4.18.0-20-generic
Found linux image: /boot/vmlinuz-4.18.0-17-generic
Found initrd image: /boot/initrd.img-4.18.0-17-generic

Progress: [ 98%] [#########################################################################################################################...]

I went and had a look in /boot/grub and found what appear to be the old grub config file and the new and as yet not renamed config file:

:/boot/grub$ ls -laF
--snip--
-r--r--r-- 1 root root 9184 May 21 08:57 grub.cfg
-rw------- 1 root root 9808 Jun 4 11:18 grub.cfg.new
--snip--

Suggestions welcome. I'd fear killing the process and then not being able to boot. Does anyone know why this happens? Thanks for any help.

Just bumping this. apt-get upgrade is still stuck at 98% from yesterday. I'll have to reboot it eventually. Does any one have any guidance on how I can be sure I'll end up with a bootable system?

Well after using ps aux | grep 'apt upgrade' and ps aux | grep dpkg to try to find and kill the hung processes involved, I tried dpkg --configure --pending which would also hang while generating the grub config file:

sudo dpkg --configure --pending
Setting up linux-image-4.18.0-21-generic (4.18.0-21.22~18.04.1) ...
Processing triggers for linux-image-4.18.0-21-generic (4.18.0-21.22~18.04.1) ...
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-4.18.0-21-generic
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.18.0-21-generic
Found initrd image: /boot/initrd.img-4.18.0-21-generic
Found linux image: /boot/vmlinuz-4.18.0-20-generic
Found initrd image: /boot/initrd.img-4.18.0-20-generic
Found linux image: /boot/vmlinuz-4.18.0-17-generic
Found initrd image: /boot/initrd.img-4.18.0-17-generic

[... hang forever]

The file /boot/grub/grub.cfg.new would get a new timestamp but whatever process required to replace the existing file /boot/grub/grub.cfg would never complete. So I finally just crossed fingers and rebooted. It took forever but I was eventually able to log in normally and then dpkg --configure --pending worked to completion and subsequent reboots are quick and uneventful. Hope this helps someone.

1 Like

vi /etc/default/grub

GRUB_DISABLE_OS_PROBER=true