grub fails to add boot entries if python3-apt is missing

Bug #2048953 reported by Dalton Durst
36
This bug affects 5 people
Affects Status Importance Assigned to Milestone
grub2 (Ubuntu)
Fix Released
Medium
Unassigned

Bug Description

In mantic and noble, when update-grub is run without python3-apt installed, the following output is generated:

    Sourcing file `/etc/default/grub'
    Generating grub configuration file ...
    Traceback (most recent call last):
    File "/usr/lib/grub/grub-sort-version", line 4, in <module>
        import apt_pkg
    ModuleNotFoundError: No module named 'apt_pkg'
    Traceback (most recent call last):
    File "/usr/lib/grub/grub-sort-version", line 4, in <module>
        import apt_pkg
    ModuleNotFoundError: No module named 'apt_pkg'
    Traceback (most recent call last):
    File "/usr/lib/grub/grub-sort-version", line 4, in <module>
        import apt_pkg
    ModuleNotFoundError: No module named 'apt_pkg'
    Adding boot menu entry for UEFI Firmware Settings ...
    done

When this occurs, no Linux boot options are added to the GRUB config.

grub-sort-version was added to the grub-common binary package in 2.12~rc1-10ubuntu2. It is a python script which sorts the kernel versions via Debian rules using apt_pkg. The grub package was updated to depend on python3 so this script could run. However, the script also depends on python3-apt.

Either grub-sort-version should be changed not to depend on python3-apt (or fail gracefully when it's missing) or python3-apt should be added to the dependencies of grub-common.

Related branches

affects: grub (Ubuntu) → grub2 (Ubuntu)
Simon Quigley (tsimonq2)
tags: added: rls-nn-incoming
Revision history for this message
Julian Andres Klode (juliank) wrote :

The whole thing is a bit annoying but it was nicer than forking dpkg --compare-versions for each pair. I'm not sure how you ended up with a system without python3-apt, it should be pulled in via ubuntu-minimal->uuntu-advantage-tools already and you can't just go remove those packages and still pretend you have a supported system.

Changed in grub2 (Ubuntu):
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
Mate Kukri (mkukri) wrote :

Can anyone think of a good reason for GRUB to be installed on a system without python3-apt?

If no such scenario comes up, I'll add python3-apt to grub-common's Deopends: in the next upload.

tags: added: foundations-todo
Revision history for this message
Dalton Durst (universalsuperbox) wrote :

Hi Julian, Mate,

I think adding python3-apt to the Depends of grub-common is a good solution. This issue is not urgent and is easily worked around, so waiting for the next upload is absolutely fine. Thank you!

As for how I got a system into this state... It never had python3-apt installed. I built the system by running 'debootstrap --variant=minbase noble noble http://archive.ubuntu.com/ubuntu gutsy' and added exactly the packages I needed. I won't pretend that I've created a system that I can go to libera.chat #ubuntu and ask for help with, but as in Debian, the only packages that a binary control file can assume as installed are those in the 'Priority: Required' set. I think it is worth keeping that usecase available, and if you say that I need to do more work to keep it that way I'm fine with putting in the effort.

tags: removed: rls-nn-incoming
Revision history for this message
Mate Kukri (mkukri) wrote :

This will be resolved by 2.12 final, but quick fix to unblock https://bugs.launchpad.net/cloud-images/+bug/2052743

Revision history for this message
Mate Kukri (mkukri) wrote :
Changed in grub2 (Ubuntu):
status: Triaged → Fix Committed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package grub2 - 2.12~rc1-12ubuntu5

---------------
grub2 (2.12~rc1-12ubuntu5) noble; urgency=medium

  * d/control: Add python3-apt to Depends of grub-common (LP: #2048953)

 -- Mate Kukri <email address hidden> Fri, 09 Feb 2024 13:23:36 +0000

Changed in grub2 (Ubuntu):
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.