Comment 31 for bug 1097570

Revision history for this message
Colin Watson (cjwatson) wrote : Re: [Bug 1097570] Re: grub2-signed can not find the right device when there are two filesystems containing the file '.disk/info'.

On Thu, Dec 12, 2013 at 11:24:31AM -0000, Bin Li wrote:
> @Collin,

My given name only has one "l", FYI.

> And a question, is there a way to check the $prefix's value before
> search?

I'm afraid the signed image business makes this very tedious. The
simplest method would probably be to take debian/build-efi-images from
the grub2 source package, extend its skeleton grub.cfg to print the
prefix and sleep for a while as the first thing it does, put the
resulting gcdx64.efi on a modified CD image, make sure you're in setup
mode if you're on a system with UEFI Secure Boot so that you don't have
to sign the image, and try booting it.

> And the $prefix was set by grub-mkimage with '-p' parameter?

Sort of. We pass a partial prefix using "-p /boot/grub". The effect of
this is to instruct the GRUB kernel to look for the device from which it
was loaded (on EFI, this uses the Loaded Image Protocol); if it finds
that device, it will set the prefix to (that-device)/boot/grub,
otherwise it will leave it unset.

An unset prefix at the stage you describe in comment #21 would imply
that GRUB entirely failed to get the loaded image location, or possibly
that it failed to determine a GRUB drive name from it. A nonexistent
prefix would perhaps imply that it picked the wrong GRUB drive.

If you're going to be building custom images anyway to diagnose this,
then it might be worth simply modifying GRUB to insert some grub_printf
and grub_millisleep calls so that we can see what it's doing when trying
to discover the loaded image location. Something like this:

=== modified file 'grub-core/kern/efi/init.c'
--- grub-core/kern/efi/init.c 2010-09-08 12:53:47 +0000
+++ grub-core/kern/efi/init.c 2013-12-12 12:06:24 +0000
@@ -68,10 +68,16 @@ grub_efi_set_prefix (void)

   if ((!device || device[0] == ',' || !device[0]) || !path)
     image = grub_efi_get_loaded_image (grub_efi_image_handle);
+ grub_printf ("image: %p\n", image);
+ grub_millisleep (1000);
   if (image)
     {
       if (!device)
- device = grub_efidisk_get_device_name (image->device_handle);
+ {
+ device = grub_efidisk_get_device_name (image->device_handle);
+ grub_printf ("device: %s\n", device);
+ grub_millisleep (1000);
+ }
       else if (device[0] == ',' || !device[0])
  {
    /* We have a partition, but still need to fill in the drive. */
@@ -113,6 +119,8 @@ grub_efi_set_prefix (void)
       prefix = grub_xasprintf ("(%s)%s", device, path);
       if (prefix)
  {
+ grub_printf ("setting prefix: %s\n", prefix);
+ grub_millisleep (1000);
    grub_env_set ("prefix", prefix);
    grub_free (prefix);
  }

I do think we should investigate this in a separate bug report, though;
and I'd like to know whether the fix currently in precise-proposed at
least improves things for Shih-Yuan Lee in the same way that the fix in
saucy did (comment #13).