How can I reinstall grub on dual boot EFI partition?

Hi guys!
I started using linux some years ago, but I’m not a guru yet (eheheheh :P) and I’m a new user to opensuse
I successfully installed opensuse 13.1 on my Samsung Laptop together with pre-installed OEM Windows 8.0 (now upgraded to 8.1) on the same disk, with secure boot enabled.

Everything works fine, but sometimes Grub2 doesn’t load anymore at boot, and Windows starts automatically, so I can’t start OpenSuse anymore. I’m still wondering what causes this strange behavior… this time as far as I can remember what I did before, was applying windows updates, and using the Hibernate function often, on Windows and Linux.

However, I can correct this:

  • I boot from the OpenSuse installation DVD and choose to update my system.
  • After the update setup has finished and rebooted, Windows is no more available at boot
  • To let OpenSuse starts automatically, I must temporarily disable the secure boot feature from bios (i don’t know why)
  • Now I can run Yast, open the boot loader configuration, and click Ok without doing any changes.
  • Reboot (this time with secure boot enabled).
    Now grub is back as before, and everything is working fine… till next time!

Now, my questions are:

  1. Can any windows automatic updates replace grub with default windows 8 loader (it sounds strange to me)? Can the hibernate feature?
  2. Is there a better and “elegant” way to reinstall grub2 on dual boot EFI partition, using my original grub configuration?

Thank you in advance for your help, and sorry if my english is not perfect :slight_smile:

There is a EFI/boot partition this is what boots on a EFI system. It is formatted FAT and there should be directories for each OS that is to boot. So forget anything you ever learned about grub and MBR booting since they no longer apply in EFI based systems

In Windows try turning off fast boot. This is a method that does not actually shut down the OS but does a kind of hibernate. Some EFI implementations seem to want to boot only Windows. Some are OK.

There is a trick which I’ll let others explain of putting the openSUSE files in the Windows part of the efi/boot to trick it to always boot to grub

Hi
I don’t boot into windows much, so I use the efibootmgr next option to ensure only openSUSE or SLED boots first rather than resorting to the bcdedit or /Boot options. On my HP systems I just press the F9 key and select to boot openSUSE/SLED after a windows boot. I also ensure when using Windows to do a full shutdown.

Use the advance search of the forum for the keyword bcdedit, this may work for your UEFI implementation.

It is more likely that Windows is just changing the boot order, so that Windows booting comes first.

When running linux, either the installed version or the installer disk, use the following commands as root:


# efibootmgr -v
# fdisk -l /dev/sda

Post the output here. Use code tags (you can generate them with the “#” button in the edit window).

When there are future problems, you should be able to use the “efibootmgr” command to restore the booting to grub. Once you post that output, we can try to work out the exact command that you need. That will be a lot easier than what you have been doing.

It is also possible that your BIOS has a boot key you can use during boot. For my EFI box, it is F12. When I hit that, during boot, I get a BIOS boot menu. You might be able to get back into opensuse that way. At least it is worth trying.

[QUOTE=nrickert;2636837]


# efibootmgr -v
# fdisk -l /dev/sda

Hi
That should be gdisk not fdisk… :wink:


efibootmgr -v
gdisk -l /dev/sda

“fdisk” probably works too. Try it.

My guess is that this fact is responsible for much of your problems. I have been dual-booting for a while now, and I’ve never experienced what you describe - and I apply all security fixes and most of the feature upgrades as they are released. For many of my computers, without even testing first (well - they are the test rotfl!).

Even over at Microsoft they say that keeping fast-boot and hibernation active while dual-booting is dangerous (that’s the actual word used by their support people). And they, of course, only talk about dual-booting Windows OS-es. So Windows 8 even destroys other Windows OS-es. However, things doesn’t change much if you switch Windows for other OS-es though, although Non-Windows OS-es may be more polite in how co-installed OS-es are treated.

I think that you, in order to resolve your problem permanently, need to disable fast-boot and hibernation (in Windows) and hibernation (in Linux). The Windows-side disable is particularly important, since NTFS is accessible from Linux. If you make use of that, NTFS is in an undefined state while hibernated (fast-boot is a type of hibernation too), and you may corrupt NTFS if writing to it, or your results from reading NTFS may be unreliable. On top of that, Windows 8 also manipulates the EFI boot-order when hibernating.

If disabling Linux hibernation is as important, others should comment - I have not used it due to the above. Chances are that Linux only “corrupts” its own file system (as viewed from outside of Linux) and doesn’t hamper the boot situation as Windows 8.x does, and Windows cannot natively access a Linux file system anyway (but I bet someone somewhere has made a plug-in that enables such access). However, if you have multiple Linux installations, you probably will want to make sure that any Linux session makes a clean shutdown so you can access file system across OS-es as you wish.

For a way to disable Windows 8 properly, you can see my how-to here: How to: Dual-boot (preinstalled) Windows 8 and Linux - UEFI etc. - Forums Feedback - openSUSE Forums. If you need more that that, you should follow the advices from malcolmlewis and nrickert and take it from there (traditionally gdisk has been the tool to map out GPT disks, but since 13.1 fdisk also has GPT support. They call it “experimental support”, so it will probably change somewhat in future releases. Both tools are included in 13.1).

Good luck!

dayfinger

Thank you to everybody! :slight_smile:

My laptop doesn’t have a boot key, I can access boot options from setup.
Fast boot has been always disabled.

I think hibernation has an importart role in this… but I’m not sure, I need to do more tests using your advices :wink:
Months ago, I read something about using UUID, instead of mount points, to let grub handle correctly hibernation between different systems.
However, I guess using UUID won’t also help to access NTFS partition from linux, isn’t it?
So maybe hibernation should be avoided on both OS :frowning:

Could it really change boot order on its own even if I will not use hibernation in future? :\

Below is the output of commands I ran (fdisk wasn’t useful):

efibootmgr -v


BootCurrent: 0001
Timeout: 0 seconds
BootOrder: 0001,0002,0000
Boot0000*   Windows Boot Manager    Vendor(99e275e7-75a0-4b37-a2e6-c5385e6c00cb,)WINDOWS.........x...B.C.D.O.B.J.E.C.T.=.{.9.d.e.a.8.6.2.c.-.5.c.d.d.-.4.e.7.0.-.a.c.c.1.-.f.3.2.b.3.4.4.d.4.7.9.5.}....................
Boot0001* opensuse      HD(2,fa000,96000,97287ad7-892c-49ee-ac22-8cf741104997)File(\EFI\opensuse\grubx64.efi)
Boot0002*   Windows Boot Manager    HD(2,fa000,96000,97287ad7-892c-49ee-ac22-8cf741104997)File(\EFI\Microsoft\Boot\bootmgfw.efi)WINDOWS.........x...B.C.D.O.B.J.E.C.T.=.{.9.d.e.a.8.6.2.c.-.5.c.d.d.-.4.e.7.0.-.a.c.c.1.-.f.3.2.b.3.4.4.d.4.7.9.5.}...e................

fdisk -l /dev/sda


Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0xd4739049

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1  4294967295  2147483647+  ee  GPT
Partition 1 does not start on physical sector boundary.

gdisk -l /dev/sda


GPT fdisk (gdisk) version 0.8.7

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 976773168 sectors, 465.8 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): C6738160-9539-41DF-BA9C-E75B787E8561
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 976773134
Partitions will be aligned on 8-sector boundaries
Total free space is 2029 sectors (1014.5 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1023999   499.0 MiB   2700  Basic data partition
   2         1024000         1638399   300.0 MiB   EF00  EFI system partition
   3         1638400         1900543   128.0 MiB   0C01  Microsoft reserved part
   4         1900544       793835519   377.6 GiB   0700  Basic data partition
   5       793835520       794552319   350.0 MiB   2700  
   6       929722369       974675968   21.4 GiB    2700  Basic data partition
   7       974675969       976773120   1024.0 MiB  2700  Basic data partition
   8       794552320       802959359   4.0 GiB     8300  primary
   9       802959360       929722367   60.4 GiB    8300  primary

You are correct. The “fdisk” output is not useful. The new “fdisk” tries to emulate “gdisk”, but it apparently fails to recognize that some disks are GPT partitioned. Your disk is one that it fails on.

Intesting. That first entry (Vendor) for Windows is new to me. I have not seen something like that. You can try deleting it with:


# efibootmgr -b 0000 -B

and see if that fixes the problem.

I’ll note that you apparently did not install secure-boot support for opensuse. So you will need to leave secure-boot disabled.

At which state your system was when you made this output? According to it, it should boot openSUSE (in non-secure boot version).
What would be really useful is the same output made when openSUSE does not boot and system goes straight to Windows (you will need to boot from live DVD or installation media to do it).

mmmm… I did it 2 days ago, and as far as I remember, I made that when grub was dual booting correctly, with secure boot activated (fast boot disabled)
Which part of my output tells you it was setted to non-secure boot?

What would be really useful is the same output made when openSUSE does not boot and system goes straight to Windows (you will need to boot from live DVD or installation media to do it).

Ok. I will try to launch efibootmgr -v from a live dvd as soon as windows boot override grub.

I think secure boot was set to active through Yast, I will double check tonight :wink:

When secure boot is active, openSUSE is using shim.efi as bootloader. This is not present in list of EFI boot entries.

Thank you arvidjaar!

This is what I see in the Yast | Boot loader gui… secure boot support seams to be enabled, isn’t it? :\


Yes, from Yast it looks fine. However, the output from


# efibootmgr -v

did not match that. Maybe recheck that.

Ok.
This is what i get using efibootmgr -v in recovery mode, booting from OpenSuse dvd when Windows overrides grub (secureboot enabled in bios):


BootCurrent: 0002
Timeout: 0 seconds
BootOrder: 0002,0001,0000
Boot0000* Windows Boot Manager    Vendor(99e275e7-75a0-4b37-a2e6-c5385e6c00cb,)WINDOWS.........x...B.C.D.O.B.J.E.C.T.=.{.9.d.e.a.8.6.2.c.-.5.c.d.d.-.4.e.7.0.-.a.c.c.1.-.f.3.2.b.3.4.4.d.4.7.9.5.}....................
Boot0001* Windows Boot Manager    HD(2,fa000,96000,97287ad7-892c-49ee-ac22-8cf741104997)File(\EFI\Microsoft\Boot\bootmgfw.efi)
Boot0002* UEFI: TSSTcorpCD/DVDW SH-S182MSB03    ACPI(a0341d0,0)PCI(1d,0)USB(1,0)USB(2,0)CD-ROM(1,3ad,22108b)AMBO

Here I used the “upgrade an existing installation” option, from the opensuse dvd.
After upgrading, I had to temporarily disable secureboot in bios, boot OpenSuse from grub, and confirmed the old boot configuration in yast (as in previous pictures).
This is what I got (this time shim.efi is present with opensuse-secureboot):


BootCurrent: 0005
Timeout: 0 seconds
BootOrder: 0005,0003,0006,0000
Boot0000* Windows Boot Manager  Vendor(99e275e7-75a0-4b37-a2e6-c5385e6c00cb,)WINDOWS.........x...B.C.D.O.B.J.E.C.T.=.{.9.d.e.a.8.6.2.c.-.5.c.d.d.-.4.e.7.0.-.a.c.c.1.-.f.3.2.b.3.4.4.d.4.7.9.5.}....................
Boot0003* opensuse      HD(2,fa000,96000,97287ad7-892c-49ee-ac22-8cf741104997)File(\EFI\opensuse\grubx64.efi)
Boot0005* opensuse-secureboot   HD(2,fa000,96000,97287ad7-892c-49ee-ac22-8cf741104997)File(\EFI\opensuse\shim.efi)
Boot0006* Windows Boot Manager  HD(2,fa000,96000,97287ad7-892c-49ee-ac22-8cf741104997)File(\EFI\Microsoft\Boot\bootmgfw.efi)WINDOWS.........x...B.C.D.O.B.J.E.C.T.=.{.9.d.e.a.8.6.2.c.-.5.c.d.d.-.4.e.7.0.-.a.c.c.1.-.f.3.2.b.3.4.4.d.4.7.9.5.}...e................

Okay. That one does not show anything for opensuse.

That’s the way that it should look, for booting opensuse. You don’t actually need entry “Boot0003”, which only works when secure-boot is disabled. Entry “Boot0005” should work with it enabled or disabled.

If you can boot from the DVD, and get a root shell, then you can put back entry “Boot0005” (though it might have a different number) with:


# efibootmgr -c -p 2 -l '\EFI\opensuse\shim.efi' -L opensuse-secureboot

The “-p 2” specifies that your EFI partition is “/dev/sda2”. You would also need a “-d” option if the EFI partition is on a disk other than “/dev/sda”. The man pages for “efibootmgr” are reasonably good, but it might be hard to read them when you are trying to recover your system.

Just using that command should be easier than reinstalling grub.

If the entry for opensuse-secureboot is already present (in the output of “efibootmgr -v”), then you might only need to use something like:


# efibootmgr -o 5,6,0

to set the boot order.