# How do I dual boot from FreeBSD 12.3 on UEFI?



## nix1 (Apr 13, 2020)

Hello everybody,
I just installed FreeBSD on a half disk next to windos10, I find incredibly that FreeBSD on UEFI does not yet support dual boot.
I see that a second UEFI area was created before its partitions.
Since I consider productivity a very important thing, is there a practical and fast way to have a double boot worthy of the name, without having to choose from UEFI?
Thank you


----------



## SirDice (Apr 14, 2020)

Are you from the future? Even 12.2 hasn't been released yet. I'm assuming you meant 11.3?



nix1 said:


> I find incredibly that FreeBSD on UEFI does not yet support dual boot.


efibootmgr(8)


----------



## asteriskRoss (Apr 14, 2020)

Hi nix1, I very recently set up on my main machine to dual boot Windows 10 (1809) and FreeBSD 12.1, though using the rEFInd boot manager (rEFInd documents are here) to choose my operating system at boot rather than efibootmgr(8). It is working well, though without secure boot enabled and with a bit of work to make the rEFInd boot screen look pretty.

My experience of installing Windows was truly awful.  It really looked like Microsoft hadn't tested the installer well.  When I left my FreeBSD partitions at the end of the drive the installer insisted there wasn't enough space to install despite having several hundred gigabytes.  After deleting my FreeBSD partitions the Windows installer then complained that my EFI partition was NTFS formatted, which it most definitely was not.  That error persisted even after I manually reformatted the EFI partition as FAT32 using Windows.  I ended up having to reinstall Windows 8 from backups and upgrade to Windows 10, which then somehow left me with a corrupt EFI partition that I needed to recreate using Windows...  Anyway, enough of my tales of Windows woe, since it sounds like Windows is working for you just fine.

You're right that that by default FreeBSD will create another EFI partition after your Windows partitions, which isn't what you want.  The FreeBSD install process is managed through a series of scripts (12.1 bsdinstall/scripts source here).  My experience is that the partitioning scripts work well for simple installations where FreeBSD is the sole operating system but for anything more complicated it is best to set up the partitions oneself. 

There is no magic in the install scripts and it is possible to duplicate everything they do by hand, though fortunately that is not necessary and there is a better option.  During the installation process you will be offered an opportunity to open a shell to set up partitioning.  This option lets you use the command line to set up your partitions and mountpoints exactly as you wish (likely using gpart(8) and potentially newfs(8) or zpool(8) and zfs(8)).  Importantly for you, this won't automatically create an EFI partition.  Once you have arranged your partitions as you want, mount everything at /mnt, write fstab(5) and put it at /tmp/bsdinstall_etc/fstab then `exit` back to the installer, which will do the rest.  If you're more comfortable using another partitioning tool there is nothing to stop you doing some of the work with that first.

To boot FreeBSD with rEFInd you'll need to copy /boot/boot1.efi to your EFI partition for a simple installation or /boot/loader.efi if you're using geli(8) for an encrypted root.  I appreciate this reply doesn't offer you a step-by-step, 'type this then press enter' level of detail but hopefully will point you towards useful things to read and digest.  Have a look and I can delve into more detail on my setup if useful to you.


----------



## nix1 (Apr 14, 2020)

Hello and thanks for the detailed reply.
I downloaded the Current 12.3 stable branch.

So are you telling me that if I manually partition and have FreeBSD boot installed on the Windows UEFI, will I be able to boot as in the old days with F1 and F2 key?

I open a constructive controversy, however after 20 years of development and about 5 that I did not return to FreeBSD, I would have expected great steps forward towards artificial intelligence even at the installation level, today as today it should be able to do everything from only.


----------



## SirDice (Apr 14, 2020)

nix1 said:


> So are you telling me that if I manually partition and have FreeBSD boot installed on the Windows UEFI, will I be able to boot as in the old days with F1 and F2 key?


That's boot0cfg(8).  And it only works for MBR with UFS.


----------



## Sevendogsbsd (Apr 14, 2020)

OP: FYI, you should be using "RELEASE", not "STABLE" unless that was your intention. STABLE is a development branch, not a production release branch.


----------



## SirDice (Apr 14, 2020)

Nothing wrong with a -STABLE version, as long as  it's a supported branch.  But I'm going to assume nix1 simply meant 'stable version',  as-in,  supported version. Most newcomers don't know 'stable' or 'current'  has a special meaning  when it comes to FreeBSD.


----------



## Sevendogsbsd (Apr 14, 2020)

Ah ok, thanks. I will admit the word "STABLE" confused me first time I went to download and install. I only use RELEASE, mainly because I am not adventuresome


----------



## asteriskRoss (Apr 15, 2020)

nix1 said:


> So are you telling me that if I manually partition and have FreeBSD boot installed on the Windows UEFI, will I be able to boot as in the old days with F1 and F2 key?


It might be possible to configure your BIOS to load boot1.efi or loader.efi from the EFI partition, which would allow you to select it as a boot option on startup (probably by pressing a function key during startup) without installing a separate boot manager.  However, on my machine, although the BIOS configuration seemed to support adding boot options to alternate EFI executables I couldn't get it to work.  If I understand correctly, efibootmgr(8) manipulates the BIOS firmware boot information.  BCDEdit on Windows can also manipulate this, which it describes as the "firmware boot store" and that was what I used as part of my rEFInd setup. Before installing rEFInd I had FreeBSD installed on a different physical disk to Windows, with its own EFI partition that I could select from the BIOS boot menu. However, this came to feel quite cumbersome.


nix1 said:


> I open a constructive controversy, however after 20 years of development and about 5 that I did not return to FreeBSD, I would have expected great steps forward towards artificial intelligence even at the installation level, today as today it should be able to do everything from only.


I've always seen FreeBSD as a "hands-on" operating system.  It can be configured exactly as you want it but it does require configuration effort. It would be reasonable to report a bug in relation to the creation of a second EFI partition during the installation process by bsdinstall(8) as that is obviously the wrong thing to do. I'm also sure the FreeBSD development team would welcome contributions to improve the installer.


----------



## asteriskRoss (Apr 15, 2020)

Sevendogsbsd said:


> Ah ok, thanks. I will admit the word "STABLE" confused me first time I went to download and install. I only use RELEASE, mainly because I am not adventuresome


Before switching to other GNU/Linux distributions and subsequently to FreeBSD I spent years using Fedora with every software update resulting in time spent trying to get my desktop machine working properly again. I expect it has matured since then but I see no shame at all in running a well-tested version of an operating system rather than being the tester for one with the latest features!


----------



## weberjn (Apr 15, 2020)

asteriskRoss said:


> It might be possible to configure your BIOS to load boot1.efi or loader.efi from the EFI partition



The other day I installed FreeBSD 12.1 on my old ThinkPad E130 beside Windows 10, using the FreeBSD installer.
BIOS lets me choose a partition on boot. This works fine, I only have to be quick not to miss the moment to press Enter to enter BIOS, else Windows gets started.


```
# gpart show ada1
=>       34  488397101  ada1  GPT  (233G)
         34       2014        - free -  (1.0M)
       2048      32768     1  ms-reserved  (16M)
      34816  268402688     2  ms-basic-data  (128G)
  268437504     409600     3  efi  (200M)
  268847104   66699256     4  freebsd-ufs  (32G)
  335546360   16777216     5  freebsd-swap  (8.0G)
  352323576  136073559     6  freebsd-ufs  (65G)
```

(there is also an ada0 for data, the original magnetic hard disc)

Maybe I'll try some day to add FreeBSD to the Windows boot manager.


----------



## SirDice (Apr 15, 2020)

asteriskRoss said:


> It might be possible to configure your BIOS to load boot1.efi or loader.efi from the EFI partition, which would allow you to select it as a boot option on startup (probably by pressing a function key during startup) without installing a separate boot manager.


That's were efibootmgr(8)  comes in. 

Assuming ada0p1 is the efi partition, you need to mount it first; `mount -t msdosfs /dev/ada0p1 /mnt` (just temporary)
Then something like `efibootmgr -c -l /mnt/EFI/BOOT/BOOTX64.EFI -L FreeBSD` will add a _new_ EFI  boot  option named "FreeBSD" which is started from EFI/BOOT/BOOTX64.EFI. I needed to do this for a machine that simply didn't want to EFI boot. Apparently my machine had a bunch of old installs still registered and I needed to clean that up first. Then added the correct entry for FreeBSD and now it EFI boots just fine.

I haven't tried this with boot1.efi or loader.efi but I see no reason why this won't work (assuming those files are proper EFI executables).  
`efibootmgr -c -l /mnt/EFI/BOOT/loader.efi -L FreeBSD-loader` for  example. Make sure to copy that loader.efi file to the EFI partition, in the specified location. You can add multiple entries, each pointing to a different EFI executable (and using a different label).

The efi partition is actually FAT32, which is not case-sensitive.  So the exact case of the files in the efi partition doesn't matter.


----------



## mickey (Apr 16, 2020)

In my dual boot FreeBSD/Windows 10 setup I first used windows' `BCDEDIT` tool to add an entry for FreeBSD that enabled me to use the mainboard's integrated boot menu (activated by pressing F12 at the right moment) to boot into FreeBSD, otherwise it would just go ahead and boot into Windows 10. That was working ok for a while but did not seem like a real solution, also I think that at least once something got messed up after some major windows update. Eventually I installed reFind boot manager and never looked back. It automatically finds installed boot loaders and even chooses appropriate icons for those, you can have your own background image, icons and configure various options to your liking. I also installed an EFI version of memtest86 on the EFI partition, so it can be run directly from the boot menu.

To boot FreeBSD I installed a copy of /boot/loader.efi to the EFI partition as \EFI\FreeBSD\loader.efi. Previously I had used /boot/boot1.efi instead, but there have been some issues with screen resolution/GOP mode.


----------



## micski (Aug 4, 2020)

weberjn said:


> The other day I installed FreeBSD 12.1 on my old ThinkPad E130 beside Windows 10, using the FreeBSD installer.
> BIOS lets me choose a partition on boot. This works fine, I only have to be quick not to miss the moment to press Enter to enter BIOS, else Windows gets started.



Do you have separate post about, how you did this?  I have an X260, that has Windows 10 preinstalled. I would like to install FreeBSD and have both systems on the boot menu.


----------

