Notes on UEFI, Windows and linux

This isn’t really a tutorial, but I’ll categorize it that way.

UEFI firmware, as a replacement to the traditional BIOS, is relatively new on the scene.  And people have been having problems finding ways to adapt to it.  The biggest problems have been with running both Windows 8 and linux on the same UEFI box.

My own experience is with a Dell Inspiron 660.  I have seen reports on the net of a variety of problems, some of which might depend on the BIOS/UEFI firmware version (that is, they might depend on the particular computer).

A quick overview

I’ll start with a quick overview of how UEFI works.

A UEFI system has a special partition, called an EFI partition.  It is often referred to as the ESP (EFI System Partition) or the SEP (System EFI Partition).  The design intention appears to be that there should be a single EFI partition to be shared by all operating systems.  Each system creates a directory in that partition, where it installs the software that loads the system.

It is possible to have more than one EFI partition, though how well that is supported will depend on the computer firmware (which I will call the BIOS).  If you have two or more hard drives installed, then you could have an EFI partition on each drive, again depending on how well that is supported by the BIOS.

The Dell BIOS on my box seems to work well with multiple EFI partitions.

When a system is installed, it installs its loader in the EFI partition, and it adds an entry to the firmware boot menu (known as NVRAM).  When the computer is booted, the first entry in NVRAM is used to select which operating system to boot.  Some computers have an option to select other boot entries.  On my Dell box, I can hit F12 during bootup, to be given a choice of systems to boot.

Using grub2-efi

There are a variety of options for booting linux with UEFI.  The most flexible is to use grub2-efi.  In that case, there is a menu that you will see while booting, that offers to boot your linux system, other linux systems, or Windows.

Problems that have arisen

Here are some of the problems that people have seen:

1: The grub menu does not have a boot entry for Windows

I ran into that problem with my install of an opensuse 12.3 release candidate.  As far as I know, it was only a problem when the linux install was booting from a different EFI partition than the Windows install.  This was fixed in opensuse by the time of the final 12.3 release, and the fixes should have been passed upstream.  So this problem should go away with newer linux installs.

2: The grub menu item for Windows does not work

This turned out to be a problem that I saw with opensuse 12.3 (the final release).  The WIndows menu entry would work as long as I disabled secure-boot in the BIOS.  But it did not work with secure-boot enabled.  This problem only arose if the linux install used a different EFI partition from the Windows install.

This problem has been fixed in opensuse 12.3.  But you would have to have installed the latest system updates to have that fix.  Again, I assume that the fix has been passed upstream, so should soon start appearing in other distros.

3: Windows deletes the linux boot menu

A problem often reported, is that Windows deletes the ability to boot linux, and forces itself as the only bootable operating system.  I also ran into this problem.  However, it is not entirely the fault of Windows.

Here is what I see happen:

  • when I install linux, or reinstall grub2-efi, the linux/grub boot entry is added to the NVRAM menu, where it is the first item on the menu;
  • on the next reboot, the BIOS/UEFI firmware deletes all but the first NVRAM entry for that EFI partition.  It seems to allow only one boot entry per EFI partition.  Since the linux entry is first, the Windows entry is the one deleted by the BIOS.
  • when Windows is next booted, it notices that its entry is missing from NVRAM.  So it puts its entry back, and that makes it the first entry.
  • On  the next boot, the BIOS/UEFI firmware deletes all but the first entry from NVRAM, leaving only the Windows entry.

I was relatively fortunate with this problem.  I had added a second hard drive for linux, and had created an EFI partition on that drive.  So I had linux booting with the EFI partition on the second hard drive, and Windows booting with the EFI partition on the first drive.  In this case, the BIOS kept both entries, and everything worked fine.  I only ran into the problem when I experimented with a second linux install, this time using the EFI partition on the first drive.

4: You cannot have two system with the same name

At one time, I had two systems called “opensuse”.  They were using different EFI partitions, so I had not expected a conflict.  But this confused the UEFI firmware.  The solution was to name one of them “opensuse” and the other “opensuse_alt”.  I’ll probably change the name of the second of those to “opensuse_beta” when pre-release test versions of opensuse 13.1 appear.

5: You cannot boot an unsigned kernel in secure-boot mode

This is not actually a surprise.  I did run into it with opensuse Tumbleweed.  The newer Tumbleweed kernels are unsigned or signed with an unapproved key.  So they do not boot in secure-boot mode.  With luck, the grub menu will have an option to boot with a kernel that is signed.  However, after the last Tumbleweed update, that signed kernel was deleted and I could not get into the system until I disable secure-boot.

Workarounds

I have managed to work around the various problem.  Here, I will discuss what I have done, and which problems it solves.

(a) Using a second EFI partition

If I use a different EFI partition for the linux install, that avoids deleting the Windows boot entry, and in turn that avoids having Windows reinstall its boot entry only to see the linux entry deleted.

I have tested this where the second EFI partition is on the second hard drive.  I have also tested it with the second EFI partition on the first drive.  It works either way, at least with my Dell BIOS.  However, I have heard reports that it might not work with other BIOS versions.

I’ll note that Fedora is using this method.  If you install Fedora 18 on a UEFI box, it will want to create an additional EFI partition to be used by Fedora.

This solves problem 3 above, though it might make problems 1 and 2 more likely to arise.

For me, it did not completely solve the problem.  I had one linux install using the EFI partition on the second drive, and one using the EFI partition on the first drive.  If I reinstall grub2-efi for the second install, then its grub entry displaces the Windows entry.  Windows puts its entry back where it is first.  So I have to get into the BIOS to switch the boot order back to what I want.

(b) Using efibootmgr

When running linux, booted via UEFI, there is a tool “efibootmgr” available.  It turns out to be very useful.  And note that it must be run as the root user.

For reference, entry 0 in NVRAM is Windows, and entry 2 is opensuse.  In normal (preferred) use, the boot order is 2,0.  That is, the UEFI firmware will first boot entry 2 (opensuse).

When I was seeing problem 2 above, I could use:

# efibootmgr -n 0

to force the next boot to be from entry 0 (Windows).  I could also get to Windows by hitting F12 during the boot sequence, and selecting Windows there.  But sometimes using “efibootmgr” was a convenient workaround.

More recently, I have used “efibootmgr” as a workaround for the problem mention above in the discussion of workaround (a).  When my second linux install gets a new kernel, it updates grub.  And this causes its entry to become first.  Since I am using the same EFI partition as Windows for that linux install, the result will be that the Windows NVRAM entry will be deleted.  And, in the chain of events described for problem 3, Windows will then reinsert itself as the first entry and cut me off from access to the grub menu.  I can fix that by changing the preference order for the firmware menu with

# efibootmgr -o 2,0

which sets entry 2 to be first.  If I do that before reboot, it prevents the Windows entry from being deleted.  If I do that after reboot (and after Windows has reinstalled its entry), then it fixes the order.

If you have completely lost an entry to boot linux, you can put it back with “efibootmgr”.  You will need to know the path.  For example, with my primary linux entry booting from the EFI partition on the second hard drive, I can restore that entry by booting a rescue disk (in UEFI boot mode), and running:

# efibootmgr -c -d /dev/sdb -p 1 -L opensuse-secureboot -l '\EFI\opensuse\shim.efi'

That creates (the “-c” option) and NVRAM entry.  The “-d” option gives the disk, and the “-p” option gives the partition number on that disk for the EFI partition to use.  The “-L” option is the label to use for the entry, and the “-l” option is the path to the boot loader (with Windows notation for path).  Incidentally, “efibootmgr -v” will tell you the paths currently being used.

When I first had a problem of no boot entry for opensuse, I did not know about “efibootmgr”.  So I did a rescue-boot and reinstalled grub2-efi.  It would have been much easier, had I known about “efibootmgr”.  However, I have since tested this method, and it does work.

Note that there is a man page documenting the “efibootmgr” command.

(c) BCDEDIT tricks

It turns out that you can use BCDEDIT in Windows to solve some problems.  I found out about this with some web references, such as this for ubuntu.  In Windows, I used the command

bcdedit /set {bootmgr} path \EFI\opensuse_alt\shim.efi

Windows obligingly changed its own NVRAM boot entry to use the indicated grub2-efi boot loader.  So now, if I use the Windows entry from the BIOS boot menu, that will actually bring up a grub menu.  I can still select Windows from that grub menu, so I can still get into Windows.

As a result, the opensuse entry in NVRAM now boots the linux that I installed using the EFI partition on the second drive.  And the Windows entry now boots the grub menu for the second linux install (using the same EFI partition as Windows).

Now, if for some reason the Windows NVRAM entry is deleted, and Windows puts it back, then it will put back an entry that gets me a grub menu.  And note that I have tested this sequence of events.

This is not a completely desirable solution, because it is misleading for the Windows boot entry to start grub.  But it is better than being locked out.

(d) Use a signed kernel in the first boot after a kernel update

I have mentioned the problem I had with Tumbleweed.  A new kernel was installed.  And then the only signed kernel was deleted.  As a result, I could not boot Tumbleweed in secure-boot mode until I reinstalled that kernel.

I have not tested the solution that I suggest.  It looks as if I should have booted to the signed kernel in the first boot after the new kernel install.  The information about multiple kernel versions is that the two newest and the current kernel will be retained.  So I booted to the signed kernel (3.7.10-1.4) before installing the new kernel, expecting it to be retained.  However, it seems that all kernels are kept until the next boot, so it is the running kernel for the next boot that will be retained.

After installing the new kernel, I wanted to test it.  So I disabled secure boot, and booted to that kernel.  And that was my mistake.  I should have booted once to the secure (signed) kernel to allow the old kernel cleanup to proceed.  And only after that, should I have booted the new unsigned kernel.

Summary

It looks as if there are reasonable workarounds for most of the problems I have seen with UEFI.

Advertisements

Tags: , ,

About Neil Rickert

Retired mathematician and computer scientist who dabbles in cognitive science.

22 responses to “Notes on UEFI, Windows and linux”

  1. nicecurelom says :

    Thanks so much for this. I was having a devil of a time installing Ubuntu on a Windows 8 machine with UEFI/ SecureBoot.

    I had to end up spoofing the windows efi file with a GRUB efi to trick the Sony BIOS into giving GRUB precedence! Insanity.

    Like

    • L T says :

      I’ll leave a tip that worked for me to install Ubuntu-GNOME 13.10 beta 1 booting into GRUB directly. This is on a Toshiba Satellite P50 laptop. I had to run the following command in Windows 8.1 RTM:

      bcdboot C:\Windows /l en-us /addlast

      The P50’s BIOS does not have an EFI shell, so it’s not like I could tinker with the settings there, and even though I could change efibootmgr boot order settings under Ubuntu, they would not stick at all. (For that neither attempting to set Ubuntu as default under EasyBCD not bcdedit worked under Windows either!)

      The “addlast” switch is the magical one that enabled GRUB to start on boot, instead of the Windows Boot Loader. Thought I’d point this point for any one else that has the same issue as UEFI becomes more popular

      Liked by 1 person

      • Neil Rickert says :

        Thanks. I’m always interested in tricks for other hardware.

        Like

      • mdmower says :

        Your /addlast suggestion is the only way I was able to make Windows stop taking precedence. I played with efibootmgr to no end, trying to change the BootOrder. But, after booting to Windows, I was guaranteed to boot directly to Windows without seeing Grub2 on the next boot. After running bcdboot with the /addlast option, I now always get the Grub2 bootloader. Thank you!

        Liked by 2 people

  2. Rob says :

    Hi Neil. Had a whole host of problems with grub on my toshiba satellite. Quick question (which may well show my naivety as I’m a new user of Linux and only ever used windows previous to this endeavour) Once you’ve downloaded and set up grub, is there any kind of command that allows you just to uninstall it?
    Had a dual boot with ubuntu, got rid of ubuntu to try put bio-linux on in its place. Get a black screen now on boot with the title Grub 2.02 beta.

    Only get to windows via the HDD recovery.

    Its a brand new laptop with EFI boot loader
    Much appreciate any advice
    Rob

    Like

    • Neil Rickert says :

      With EFI, there should not be a problem. The usual problem with EFI, is that only Windows can boot.

      “How to remove grub” is usually a problem for non-EFI (legacy booting).

      Is there any possibility that you changed your BIOS settings to legacy booting? If that happened, try changing it back to UEFI booting. That might cause problems with linux, but should be okay with Windows.

      If that is not what happened, then can you boot a linux CD or DVD in UEFI mode, get to a command line, and run:

      sudo efibootmgr -v
      

      and maybe post the output.

      Like

      • Rob says :

        Hi i think that was the problem. I booted linux with a disc in CSM mode. I took your advice and tried booting linux to get a terminal, in CSM mode, tried the sudo efibootmgr -v command and it said it didn’t recognise the command.
        I then shut it down, switched it back to EFI and the grub had gone. Gonna try a dual boot again with a USB this time. Think that was the problem. Thanks for your time.
        Just hope i can get it to boot from a USB
        Thanks again
        Rob

        Like

  3. bilal says :

    Hello, This thread seems very useful and i hope will help solving my problem.

    While installing ubuntu14.04 along side win8, i think ubuntu has overwritten win8 parition. or at least something went wrong as i can not log in to win8 neither i see any option at startup. the system boots into ubuntu. I want my win8 drive at least as it has very important data. here is the output from efitbootmgr -v command

    sudo efitbootmgr -v
    
    BootCurrent: 0002
    Timeout: 0 seconds
    BootOrder: 3002,2001,2002
    Boot0000* USB Hard Drive -         USB DISK Pro    BIOS(7,500,18).......................................................................
    Boot0001* USB Hard Drive (UEFI) - USB DISK Pro    ACPI(a0341d0,0)PCI(14,0)USB(0,0)HD(1,20,1cdefe0,000c9913)RC
    Boot0002* Ubuntu    HD(1,800,100000,d10db5b8-3647-6440-acb2-1a238a7a2a20)File(\EFI\ubuntu\grubx64.efi)RC
    Boot0003* Notebook Hard Drive    BIOS(2,0,18).......................................................................
    Boot2001* USB Drive (UEFI)    RC
    Boot3002* EFI Internal Hard Disk or Solid State Disk    RC
    

    Please some one help me.

    thanks

    Like

    • Neil Rickert says :

      That does not look good.

      Check your partitioning. That might give hints as to whether Windows still exists on your disk. Can you provide the output from:

      sudo parted -l
      

      That will at least get us some information on your current partitioning.

      Like

      • bilal says :

        Thanks very much for your reply
        sudo parted -1 gave
        parted: invalid option — ‘1’

        sudo parted -l (i assumed small L) gave the following
        sudo parted -l
        Model: ATA Hitachi HTS54505 (scsi)
        Disk /dev/sda: 500GB
        Sector size (logical/physical): 512B/4096B
        Partition Table: gpt
        
        Number  Start   End    Size    File system     Name  Flags
         1      1049kB  538MB  537MB   fat32                 msftdata
         2      538MB   496GB  495GB   ext4                  msftdata
         3      496GB   500GB  4189MB  linux-swap(v1)
        

        (added “pre” tags for better readability – nr)

        Like

  4. bilal says :

    Sadly i don’t have any backup 😦

    Like

    • Hope says :

      You can try to recover the data by means of specialized software that scans the hard drive. Search on Google and pray the gods of computing.

      Like

      • bilal says :

        Thanks very much. i did the same, making bootable SystemrescueCD and then using testdisk with photorec recovery tool. But that worked like you go to super market for buying some stuff and they through the whole market at you. Photorec recovered many many files changing their names with no directory structure at all. I think one should put one rule before themselves, TAKING REGULAR BACKUPS.
        thank you all

        Like

  5. Nehal J Wani says :

    This is how I got OpenSuse to dual boot with Windows 8 in UEFI Mode:

    Like

  6. Jawisr says :

    Thanks! I made a new FAT32 partition in my second HD and set mount point /boot/efi on it. Now grub does not detect windows, but I can choose which system to boot through F11 when the BIOS boots.

    Like

    • Neil Rickert says :

      Interesting. Which distro are you using?

      When I first installed opensuse 12.3, I had that problem. I was using an EFI partition on the second disk for linux, and there was no boot entry for Windows in the grub menu. I had to use F12 during boot to get to Windows. (I think that was actually a release candidate for opensuse 12.3, back in early 2013).

      I reported that as a bug. It was quickly fixed. As far as I know, the changes were pushed back upstream to the grub-efi developers. So I’m guessing that your distro is using an older release of grub.

      I’m currently on opensuse 13.2, and according to the package manager I am using grub-efi version 2.02-beta2. So maybe the fix has not been officially released.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: