X
Business

The rEFInd boot loader for UEFI Systems: A life (and sanity) saver

Setting up multi-boot on UEFI-based systems has turned out to be quite an ordeal. Here is what I have learned so far.
Written by J.A. Watson, Contributor

I have been struggling for quite some time now to set up multi-boot support on a new HP Pavilion dm1-4310ez sub-notebook that came preloaded with Windows 8, UEFI, and gpt disk partitioning.

frustrateditguy-200
Multi-boot support: Not for the faint-hearted.

During that time I have slowly (much too slowly) learned a lot about booting UEFI systems. Thanks to some very helpful comments and advice from Adam Williamson at Fedora, some excellent documents written by Roderick W Smith, a lot of trial and error, and rebooting-adjusting-testing-rebooting ad infinitum (or more accurately ad nauseum), I'm finally starting to make some progress.

Note: I am going to ignore the issue of Secure Boot here. I don't want to talk about it, it is not relevant to this discussion, so if you really feel compelled to start yet another flame war about it, well, feel free to do so but I will ignore those comments.

Warning: The following description is very compressed; if you need to really understand this, you will have to dig out a lot more detail elsewhere. My concern here is with the mechanics, not the theory. Or, put another way, I don't really feel like I fully understand everything I know about this yet. It is extremely important to keep in mind that changing the configuration of the boot manager and/or boot loader on your computer can very easily render it unbootable. So if you are going to try this, the usual advice about "make sure you have good backups" is not even enough. I would advise only trying this on a system where you don't mind having to wipe it out completely and reload from scratch. I have done that several times during this process, and now that I have the SSD loaded and configured to the point that I don't really want to lose it all again, when I decide to try something completely new or particularly risky, I swap out the SSD for an old SATA drive first. After making whatever tests, if I have learned something useful I swap the SSD back in again and apply it to that. As a result of this I am very appreciative of how easy it is to swap the disk drive in the dm1-4310. Thanks very much for that, HP.

OK. Concentrate on mechanics, don't wander off into theory or philosophy. That is the mantra. Here we go.

Multi-boot

With traditional BIOS systems (most people will think of this as pre-Windows 8 systems, although this is not really true; EFI BIOS systems have been slowly increasing), when you bought a PC preloaded with Windows, it booted Windows. Duh.

If you tried hard enough, and you learned about either BCDedit or easyBCD, you could configure it to multi-boot, giving you a list of available operating systems to choose from. If you installed Linux, you typically replaced the Windows bootloader with either Grub or Lilo, which preformed pretty much the same function, presenting a list of available operating systems to choose from. This all happened more or less "automatically;" when you installed Linux it set up and configured Grub for you, and when you rebooted after installation you got a list showing Linux and Windows to choose from.

When I tried doing exactly the same thing on this system with UEFI BIOS, the Linux installation worked just fine...but when I rebooted, it still just started Windows. No multi-boot, no menu, no indication that anything else had been changed; it just booted exactly the same way that it had originally. I then found that I could press the hot key for "boot selection" or "operating system selection" (usually F9 on HP, ESC on Samsung, F12 on Acer and Fujitsu), and I would get a list where I could choose to boot either Windows or Linux.

At least this worked, but it had several serious disadvantages. First, I couldn't find a way to get it to boot to this menu by default; I had to press the hot key, and I had to do it quickly. If I was too slow, it booted Windows and I had to reboot and try again. Second, the presentation of the list is very simple, to be charitable. Ugly is a better description of it. Third, the list contained a lot of stuff that was irrelevant to me, so I had to figure out by trial and error, and then remember, what was "real" and what wasn't. At this point I could at least get either Linux or Windows booted, but this was clearly not an acceptable situation.

At this point I have to say that there seems to be a lot of difference in the flexibility, configurability, and general support of UEFI BIOS implementations between manufacturers. I have only tried this on one HP system so far, and based on my experience and what I have heard from other people with other systems, I believe/hope/wish/assume that this is a particularly difficult one to deal with, it can/should be considerably easier on some others. Jumping forward, based on what I know now, I can say that the problem at this point was that the boot manager was still pointing to the Windows bootloader. What I was doing by pressing F9 was interrupting the boot manager, and getting it to show me the list of what it knew about. If I could have changed the boot manager configuration so that it started the UEFI Grub bootloader, it would then have been more like I expected after installing Linux on a traditional BIOS system. But I didn't know that, and even now that I do know it, I can't find a way to change that on this HP system. Read on...

OK, so I figured that if the HP wasn't going to let me boot Grub, I would try to live with the Windows bootloader. Ugh. I searched for information online, I used BCDedit first, and then easyBCD, to read and modify the boot list. At this point I noticed that the list it was showing was not the same as the list presented when I interrupted the boot process with F9, but I still didn't understand the significance of that. Although I managed to add entries to the boot list, and the Windows bootloader would then present a list to choose from, I could never get it to actually boot anything from that list other than Windows 8. I still don't know what I was doing wrong, or how/what/where should be added to that list, but I finally gave up. I assumed that I was stuck with the sub-optimal F9 boot selection procedure.

A light goes on

Then I learned about the Linux efibootmgr utility. It would give me a list of the boot manager configuration--and I saw that this was different from the list that the Windows programs were showing me. This was where the light finally started to come on. Most importantly for me at this stage, I saw that the list included entries for the Linux EFI systems I had installed! Hooray! In fact, this list actually did correspond to what the boot manager showed when I pressed F9, so I figured if I could change it somehow, I might get where I wanted to be.

Unfortunately, I couldn't change it very much--in fact, at first nothing that I did worked at all. I couldn't change the boot order, I couldn't change the path of the default boot item, and I couldn't even delete an item from the list. All of these things seemed to work when I tried them and then checked the list again right away, but then I would reboot, and everything went back to the way it was before.

There were several times during this that my HP almost became a UFO. Finally, when I was desperately changing pretty much anything and everything I could, just to see if I might stumble across something, I did...I found that I could set the "Next Boot" item to one of the Linux Grub entries, and sure enough, when I rebooted it would boot Grub. Hooray again! There is some tiny glimmer of light at the end of the tunnel! But not much, unfortunately. No matter what else I tried, I couldn't permanently change it to boot Grub. Grr.

Enter rEFind

Then I came across the rEFInd program. The documentation looked good, and gave me a lot more information about what was really happening and why during the EFI boot process. I already had Fedora 18 installed, so I went to Sourceforge and downloaded the refind.rpm package, installed that and crossed my fingers...

At this point, the windows of my house were starting to look like very inviting launching points for this computer.

Rebooted...and still got nothing but Windows. At this point, the windows of my house were starting to look like very inviting launching points for this computer...sigh.

The rEFInd documentation mentions that some systems, particularly HP systems, don't allow the boot manager configuration to be changed to anything other than the default bootmgfw.efi program. Well, I learned long ago that when faced with such inflexibility, the simple solution is to just give it what it wants--and the rEFInd documentation suggests about the same thing.

Move the EFI/Microsoft/Boot directory out of the way (rename it), move the refind directory to that name, and rename refind.efi to bootmgfw.efi. Cross fingers, cross toes, touch wood, do several superstitious dances around the chair and desk, then reboot, and... yes! Yes! It boots rEFInd! Hooray! Whee! Whoopie!!!! At this point my partner was shaking her head, and thinking that I have taken leave of what little sense I had left.

The rEFInd boot screen is pretty nice. It is very clever about finding whatever might be bootable on your disk, and it presents a list of graphic buttons you can click to choose what you want to boot. It even makes a good effort at figuring out exactly what things are, and shows appropriate graphics on the buttons when it can.

So on my system, the Windows, Fedora, Ubuntu, and openSuSE logos were there along with a number of other Linux "penguin" logos, and some generic "unknown" items. Selecting one of the Linux icons would boot Grub from that distribution, and selecting the Windows icon booted Windows 8. Oh. Uh oh. Wait a minute...

After booting Windows 8, the next time I rebooted I was back to the same old Windows-only boot. When I went back and checked the EFI partition, I was amazed to find that the Boot directory I had set up with refind in it was gone, and the original Windows boot setup was there again!!!! Apparently there is something in the Windows boot processing that checks this, and if it finds changes that it doesn't like, it restores everything from a backup copy.

I'm assuming this is an HP-specific trick, because the backup copy appears to be under EFI/HP/Boot, but I'm not sure, and I suppose other manufacturers could do it too. Perhaps it is even "required" for Windows 8 certification; who knows?

Anyway, my next attempt was to leave the contents of EFI/Microsoft/Boot intact as far as possible, and just copy/rename the refind stuff in there as well. There are no name conflicts between the contents of the two directories, so this isn't difficult, and the only thing I had to rename was bootmgfx.efi itself. Once that was done, it was back to booting rEFInd again, and this time when I booted Windows, it left everything intact, so subsequent boots still went to rEFInd. Finally. I would celebrate again at this point, but I was just too tired. I have since booted numerous times, and this seems to be stable.

At this point I realized that rEFInd itself was not the key to what I had accomplished. The information I got from its documentation, and from running it and seeing how it worked and how it was configured, led me to the point where I could create a working alternative to the original Windows boot manager/boot loader setup. But that alternative is not unique to rEFInd; I can just as well copy one of the grubx64.efi programs and rename it to bootmgfw.efi, make sure the associated grub.cfg file is in the same directory, and it will happily boot into Grub.

The difference is, rEFInd will automatically find and successfully boot just about anything and everything possible on the disk, but the EFI Grub programs that are included with Fedora and Ubuntu are not as flexible. In fact, I have only been able to get the Fedora version to boot Fedora itself, even though grub2-config finds other operating systems and adds them to the grub.cfg file, attempting to boot them fails. Adam Williamson told me this is "by design," because selecting other operating systems to boot should be handled by the boot manager, not by Grub, so that's fine by me. The Ubuntu version is more successful; I can boot other Linux distributions including those that do not have their own EFI boot capability, but I haven't been able to boot Windows from it.

Besides, rEFInd itself really is a beauty, and it works exceptionally well. As I said, in the simplest case all you have to do is install it and get it to boot (OK, that might not be terribly simple, but it is the necessary first step), and then it will automatically find, list, and boot just about anything you have on the disk. This includes Linux distributions both with and without EFI boot capability and various versions of Windows.

If anything, it can be somewhat over-aggressive, giving you lots of duplicate icons for the same Linux installation, because it will find and list the EFI shim and EFI grub files plus however many Linux images you have in the /boot directories of the disk partitions. If that is not enough (or more likely is too much), you can customize the refind.conf file to limit where it looks and/or what it looks for, or you can even go so far as to disable searching entirely and create a manual configuration.

Looking back, with the knowledge that I have now from going through this whole process, I can see that setting up dual-boot Windows and Linux system could have, and probably should have, been a lot easier if one or more of the following had happened:

  • If it had been possible to permanently change the default boot loader: I'm pretty sure that Fedora and/or Ubuntu tried to do this when they were installed, so that after installation I would have gotten Grub instead of Windows. Likewise, I tried to do this myself, albeit fairly late in the process, and it didn't work

  • If I had been able to figure out how to add another item to the Windows boot loader menu, either manually or with easyBCD, I would have "settled" for that, and at least I would have had something that worked

  • If HP, Microsoft, or whoever else got involved, didn't suddenly detect that something had changed on the EFI boot partition and decide that no one could possibly want to boot anything other than Windows, so they just wiped everything that had been done up to that point and restored the original EFI boot configuration.

Some of these things may be handled "better" or "correctly," or at least in a more "user-friendly" way on other systems, with other EFI BIOS implementations and other boot sequences.

In my opinion the long-term solution for this is going to have to be a lot more automation, with the Linux installer figuring out what needs to be done to get some kind of flexible boot manager installed and configured, whether it be rEFInd, Grub, eLilo, or whatever.

But that isn't going to happen anytime soon, I suspect, and before it can happen there is going to have to be a lot more progress made in the configurability of the EFI boot process, and the standardisation or at least conformity of changing that configuration. As things are today, it is a royal pain in the rear when one kind of computer does it one way, another does it differently, and some don't allow much changing at all.

As I said at the beginning, I still feel like I don't understand everything I know about this very well. Anyone who can add more constructive information and experience, please do so in the comments. I am posting this despite my misgivings about lack of understanding in hopes of providing useful information to others who are struggling with the same thing, so more information is always welcome.

Editorial standards