7

Apt is failing to upgrade or install new packages after a seeming partial kernel upgrade. I've tried apt-get purge -f linux-image-extra-3.19.0-22-generic which fails with a very similar error message. The machine also crashes on boot into the newest kernel version (default in grub), but previous versions work fine.

$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be REMOVED:
  linux-image-3.19.0-22-generic linux-image-extra-3.19.0-22-generic
The following packages will be upgraded:
  linux-cloud-tools-common
1 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
2 not fully installed or removed.
Need to get 0 B/24.3 kB of archives.
After this operation, 208 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 453815 files and directories currently installed.)
Removing linux-image-extra-3.19.0-22-generic (3.19.0-22.22) ...
depmod: FATAL: could not load /boot/System.map-3.19.0-22-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
run-parts: executing /etc/kernel/postinst.d/dkms 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
update-initramfs: Generating /boot/initrd.img-3.19.0-22-generic
grep: /boot/config-3.19.0-22-generic: No such file or directory
depmod: WARNING: could not open /tmp/mkinitramfs_6gldfB/lib/modules/3.19.0-22-generic/modules.order: No such file or directory
depmod: WARNING: could not open /tmp/mkinitramfs_6gldfB/lib/modules/3.19.0-22-generic/modules.builtin: No such file or directory
run-parts: executing /etc/kernel/postinst.d/pm-utils 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
Generating grub configuration file ...
ERROR: cannot determine partition label for rootfs /dev/sda9
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 1
dpkg: error processing package linux-image-extra-3.19.0-22-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Removing linux-image-3.19.0-22-generic (3.19.0-22.22) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
update-initramfs: Deleting /boot/initrd.img-3.19.0-22-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
Generating grub configuration file ...
ERROR: cannot determine partition label for rootfs /dev/sda9
run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 1
Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-3.19.0-22-generic.postrm line 328.
dpkg: error processing package linux-image-3.19.0-22-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Errors were encountered while processing:
 linux-image-extra-3.19.0-22-generic
 linux-image-3.19.0-22-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

I need to get apt working again and into a state where it can install future kernels. Properly purging the 3.19.0-22 kernel would be nice but unnecessary. Feel free to ask for more information, and thanks in advance

--Edits--

0x450's answer works for any non-kernel related packages. Kernel and grub updates return apt and dpkg to a broken state. I have noticed this recurring error message:

Generating grub configuration file ... ERROR: cannot determine partition label for rootfs /dev/sda9

Could this be an issue related to grub configuration files?


sudo apt-get install --reinstall linux-image-extra-3.19.0-22-generic results in a very similar error (which can be viewed here)

sudo dpkg --configure -a creates this error

sudo apt-get purge linux-image-extra-3.19.0-22-generic creates this error

David
  • 121
  • 1
  • 9
  • How about sudo apt-get install --reinstall linux-image-extra-3.19.0-22-generic, and then a removal afterwards? – noleti Jul 23 '15 at 04:21
  • It returns a similar error (http://pastebin.com/Pw0AyGVk). I'll also put the link to the log in the original post – David Jul 23 '15 at 05:13
  • Purging the kernel properly would be nice, but getting apt working is far more important. I can boot from other kernels just fine. – David Jul 23 '15 at 20:31
  • Just to clarify, apt needs to be able to install new kernels in the future as well. I don't particularly care about 3.19.0-22 – David Jul 24 '15 at 23:34

5 Answers5

12

I struggled with the exact same problem but the broken kernel packages were version 3.13.0.57.

Inspect the problem:

Check the dpkg status of the packages:

dpkg --status linux-image-3.19.0-22-generic
dpkg --status linux-image-extra-3.19.0-22-generic

If the output states that the packages are in bad state, i.e. half installed or not fully installed, this means that they have broken apt-get and dpkg respectively.

The solution:

The entries of the infected kernel packages must be deleted manually from the status file of dpkg in order apt-get and dpkg itself to function normally once again. The steps are as follows:

  1. Make sure to create a back up of the status file just in case if something goes wrong.

    sudo cp /var/lib/dpkg/status /var/lib/dpkg/status.backup

  2. Open /var/lib/dpkg/status with your preferred text editor and search and delete ONLY the references of the broken packages. You must not delete anything else!

  3. Run sudo apt-get update and sudo apt-get upgrade to make sure that everything is fixed.

  4. This step is optional since the packages are no longer tracked from the package managers but if you want you can free some disk space by deleting them. You can safely remove manually all of the entries of the broken kernel packages in /boot and in /usr/src but be VERY CAREFUL. Make sure to touch only the files/folders, which correspond to the 3.19.0-22 version in your case.

0x450
  • 598
  • 4
  • 22
  • Tell me if this has fixed your problem. Also please let me know if you have used boot repair recently because I have suspicions that it causes this problem, or at least in my case it was the causer. – 0x450 Jul 24 '15 at 07:31
  • Thanks a lot. This works for all installs except ones that install anything kernel related. When things don't work I've noticed the recurring error Generating grub configuration file ... ERROR: cannot determine partition label for rootfs /dev/sda9. Any Ideas on how to fix this? – David Jul 24 '15 at 21:00
  • What you want to say is that the solution I proposed did not work on the kernel packages? When exactly did this error message appear - I mean after which command/action? – 0x450 Jul 25 '15 at 10:13
  • It seems to have always been there, even in the original error messages In my question. I just noticed that it seems to be everywhere. – David Jul 25 '15 at 22:13
  • 1
    Sir, @0x450, you just saved the day. Thank you! – Fennec Apr 10 '17 at 12:30
1

Root cause

The root problem seems to be that /boot/System.map-3.19.0-22-generic is missing, which prevents reconfiguration/removal of the packet.

Suggested Solutions

My initial suggestion was sudo apt-get install --reinstall linux-image-extra-3.19.0-22-generic

As this apparently fails ("cannot configure half-installed"), I would suggest to do this a bit more forceful, e.g. with the following options

sudo dpkg --remove --force-remove-reinstreq linux-image-extra-3.19.0-22-generic

That suggestion is based on this answer.

Alternative: Manual repair?

Alternatively, you can also try to manually repair that file? Maybe it is unpacked by apt-get while trying to reinstall? It's a bit hard for me to replicate on my system right now

noleti
  • 4,053
  • 27
  • 25
0

I think you should run

sudo dpkg --configure -a

followed by what has already been mentioned:

sudo apt-get purge linux-image-extra-3.19.0-22-generic
JEL
  • 176
  • 7
0

It turns out the issue was caused by grub-mkconfig crashing with the error message Generating grub configuration file ... ERROR: cannot determine partition label for rootfs /dev/sda9 (sda9 held my fs root).

Apt crashed because when it tried to install new kernels it ran grub-mkconfig to add them to the boot menu. It wasn't actually a problem with apt but with grub.

I fixed it by reinstalling ubuntu and using ext3 instead of ext4 for the partition containing my file system root. My home directory is still in its own ext4 partition though, so it doesn't appear to be affected.

0x450's answer works well as a temporary fix so that one can use apt again. It doesn't fix the root problem though.

David
  • 121
  • 1
  • 9
  • How did you reinstall Ubuntu? Could you share commands? Or do you mean you wiped the entire system out? ): Thanks – Jorge Orpinel Pérez Aug 24 '16 at 08:13
  • I used an install image, then wiped the root partition and told it to use the existing /home partition. I don't remember any of the commands I used any more, I fixed the issue well over a year ago – David Aug 25 '16 at 03:26
-1

You could use remove instead of purge, and then upgrade the kernel, and enter this in the terminal:

 sudo apt-get -f remove linux-image-extra-3.19.0-22-generic

and then delete sources.list file, and enter settings and update and hatch all of the chanoical list and close it again.

and then reinstall the latest kernel, and enter this in the terminal:

sudo apt-get install linux-amd64_ linux-efi
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install aptitude
sudo aptitude linux-efi

and it might work fine this way.

Michael
  • 2,499
  • 5
  • 19
  • 24