# FreeBSD 10 on UEFI/GPT systems



## krnlpk (May 18, 2014)

I am trying to install the last FreeBSD release into a GPT partition (ada0p9, on an AHCI SATA HDD). Setup itself is successful, but I have no idea how to boot FreeBSD. I know that a UEFI bootloader is in the works and has been merged into HEAD; but how can I boot the current release without waiting for a UEFI-enabled one?

I have other systems (Windows, GNU/Linux) on the same disk, and they all boot through UEFI bootloaders in the EFI partition ada0p1. I have a 512K freebsd-boot partition on ada0p8, but I don't know how to use it.

Trying to use grub2 to boot the system has not been successful at all:
- Trying to load /boot/loader with a kFreeBSD /boot/loader results in a blinking cursor. Nothing happens.
- Trying to load /boot/kernel/kernel and needed files (kFreeBSD /boot/kernel/kernel + kfreebsd_loadenv for device.hints, needed modules and set kFreeBSD.vfs.root.mountfrom="ufs:ada0p9" has had no effect at all) fails instantly, and after giving the `boot` command on the GRUB command line it instantly reboots.

Any ideas? How do you boot FreeBSD on UEFI systems?


----------



## helizeg (May 18, 2014)

Before the FreeBSD UEFI bootloader becomes available, all you need to do to boot up a FreeBSD system installed onto a GPT disk in a UEFI motherboard is to switch to legacy/CSM/MBR compatibility mode in your UEFI "BIOS". The appropriate bootstrapping codes should have been installed into the protective MBR of your GPT disk and your freebsd-boot partition by the installer automatically. With those codes in place, your motherboard will treat your GPT disk like an MBR disk in the MBR compatibility mode and boot directly into your FreeBSD partition, skipping the GRUB you may have installed into your EFI system partition. But it seems almost like impossible to chainload to the FreeBSD partition from GRUB if you boot up in UEFI mode.


----------



## krnlpk (May 18, 2014)

I cannot find CSM modality in my UEFI settings - *I* think it's not supported by this firmware.


----------



## helizeg (May 19, 2014)

There should be some sort of MBR compatibility mode (or whatever they like to name it) in your UEFI "BIOS". It is made mandatory by the UEFI specification for UEFI motherboards to be able to boot up a MBR disk. BTW, what is the manufacturer of your motherboard?


----------



## krnlpk (May 19, 2014)

helizeg said:
			
		

> There should be some sort of MBR compatibility mode (or whatever they like to name it) in your UEFI "BIOS". It is made mandatory by the UEFI specification for UEFI motherboards to be able to boot up a MBR disk. BTW, what is the manufacturer of your motherboard?


I have a laptop (Asus N56VZ), with an American Megatrends BIOS/UEFI - quite standard I think.
Yes, compatibility mode exists (I can boot from USB and CDs without /EFI directories so it's definitely present), but after installing the protective MBR in this way from the live CD: `gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 8 ada0`, the boot loader menu still has only a list of the UEFI bootloaders in ada0p1, USB keys or CD drive, no entry for booting the harddisk.

Am I installing the pMBR in a wrong way? I remember that the menu used to show both the drive and the UEFI bootloader in /EFI if a CD with both is inserted (like the Windows one), so *I* assume it should behave the same way with a pMBR on the main hdd if anything was right (?)

Also the main HDD is not listed under the "legacy devices" section inside the BIOS.


----------



## helizeg (May 19, 2014)

> CD:
> 
> 
> 
> ...



Your command should work fine. Though there are variations as to how manufacturers implement their own MBR compatibility mode, you shouldn't be able to see the lists of UEFI bootloaders installed in your UEFI system partitions when you're really booting up your laptop in "PURE" MBR mode. The fact that you got the list of UEFI bootloaders in you boot menu (F8??) suggested that you're in fact booting into the UEFI mode. 
Maybe your UEFI "BIOS" thought no one with a sane mind would like to boot up a GPT disk like a MBR disk §e  and so automatically switch to UEFI mode when she saw your GPT disk with the proper UEFI system partition containing valid UEFI boot loaders. If that's the case, I believe you have to enter the "BIOS" and see if you can force it to boot in the MBR compatibility mode. Disabling any UEFI-related boot options like secure boot may help



> Also the main HDD is not listed under the "legacy devices" section inside the BIOS.



That's because your HDD is GPT-formatted instead of MBR-formatted(legacy devices).  According to wblock, the kind moderator here, the 
	
	



```
gpart bootcode -b /boot/pmbr
```
 part of your command serve to insert some bootstrapping code in the protective MBR of the GPT disk, so that you can boot up the GPT disk like a MBR in the CSM mode, some sort of cheating for you UEFI BIOS. I beleive that's the only way you can install FreeBSD into a GPT disk in UEFI enable system before the official FreeBSD UEFI bootloader is made available


----------



## krnlpk (May 19, 2014)

This laptop shipped with Win7, so it has no Secure boot. In the Setup there is no option whatsover about legacy modes or anything - I think you're right about the fact it doesn't think you would want to boot with MBR if you have an EFI partition with bootloaders in it. 

I suppose I will have to wait for the EFI bootloader to get into stable, unless I find another way


----------



## helizeg (May 20, 2014)

Too bad, your UEFI BIOS sounds like too clever and won't fall into the trap. What about booting up a live CD/USB install of any Linux distro with a Grub2 and chainload from there? Not the latest version of Ubuntu live CD, _be_cause it can be booted in UEFI mode though. Get into the command mode[](pressing 'c') after the GRUB load and type: 


```
GRUB> set root=(hd0)
GRUB> chainloader +1
GRUB> boot
```


----------



## ColdfireMC (Aug 28, 2014)

man, use rEFInd, there's some ways to chain legacy firmware loaders to a .EFI loader executable

http://www.rodsbooks.com/refind/

i used it for chain a freedos bootloader  :e, GRUB or another famous bootloader will be better explained and easier to deploy.


----------



## pkubaj (Sep 5, 2014)

Since r271136 there's UEFI support in stable/10 so you might want to download a recent snapshot and try it. Still, there's no SecureBoot support (for now).


----------



## ColdfireMC (Sep 6, 2014)

pkubaj said:
			
		

> Since r271136 there's UEFI support in stable/10 so you might want to download a recent snapshot and try it. Still, there's no SecureBoot support (for now).


but how can I install a snapshot?


----------



## pkubaj (Sep 6, 2014)

See https://wiki.freebsd.org/UEFI#Bootable_ ... mory_stick or wait until there are snapshots at r271136 or higher. Follow freebsd-snapshots@ to get a current info about them.


----------



## kpa (Sep 6, 2014)

ColdfireMC said:
			
		

> pkubaj said:
> 
> 
> 
> ...



The ISO images and the USB memory stick images can't be used for updating/upgrading. You have to install from scratch if you're using those. Updating/upgrading an existing installation to a stable branch has to be done with the source based update as described in the handbook:

https://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/current-stable.html

(And the following chapters).


----------



## pkubaj (Sep 6, 2014)

kpa said:
			
		

> ColdfireMC said:
> 
> 
> 
> ...


AFAICS he doesn't want to upgrade because he can't even boot FreeBSD, so a clean install using new UEFI boot would be the best.


----------



## ColdfireMC (Sep 6, 2014)

Seems to be a little complicated. *I* want make this, there's a report protocol for this feature? *I* have a UEFI desktop with DX79TO, are there successful reports booting Intel UEFI?


----------



## ColdfireMC (Sep 6, 2014)

pkubaj said:
			
		

> kpa said:
> 
> 
> 
> ...



*I* have an "old" snapshot. Clearly, to install a UEFI compatible snapshot, *I* have to make new partitions with GPT, and possibly a UEFI partition, or copy loader to existent EFI partition (Windows 8.1). *M*y question is how to make installation media with a snapshot (if it applies in this case), or how *I* can install this from scratch (that would be hard), and what about EFI loaders, has FreeBSD one?


----------



## natharran (Sep 18, 2014)

krnlpk said:
			
		

> Any ideas? How do you boot FreeBSD on UEFI systems?


Hi,
I had exactly the same problem - my Asus N750JV refuses to boot FreeBSD from hard drive. A also tried Grub2 and rEFIned - none of them worked for me (I spent days on it and it was quite frustrating, honestly). In the end the only solution that worked was to install the freebsd-boot partition AND the /boot partition on a separate USB thumb drive from which the UEFI "BIOS" can boot. It's not ideal but it works and you can use the system until the UEFI-capable bootloader becomes the part of -RELEASE version.


----------

