# Can't install FreeBSD 11.1 and 10.4 on UEFI mode.



## greatfox (Mar 17, 2018)

I spent lots time to try install FreeBSD on my old asus notebook K42Jv* with UEFI*: i5-520m, 8GB memory, IGP and nvidia 335m, but all failed.
The notebook can run arch linux, ubuntu linux, windows 7-10, even include tianocore's Shell_Full.efi with UEFI boot, so I believe it's support freebsd too.

1. hang rate > 95 percents
I use 10.4-uefi-memstick and 11.1-memstick version. The partition layout of version 11.1 include efi and freebsd-boot, I think it's the reason haven't uefi version.
The very strange thing is that almost every boot will hang after print out 'masks 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000' without switch display mode.
In very rare cases, someitmes I modify the partition table or adjust the EFI entry under Linux, and the try to start, it can enter the correct installation interface.
I can't master the rule at all, because even if don't do anything, reboot it immediately then would hang at masks line again.

2 installer can't create correct efi partition.
Although the chance is very small, sometimes it can be installed. However, the installer will not recognize the existing EFI partition. Whenever I create a freebsd-ufs partition, it will automatically generate a 200M efi partition for me. The worst part is that this efi partition does not work correctly. The installer not only didn't create any EFI entry, it did not even create the correct file in the EFI partition.

3 Strange efi partition
Since the installer always creates its own EFI partition, my partition table is often similar to:
sda1 600M EFI
sda2 60G Ext4 (My Linux root partition)
sda3 8G swap (Linux swap)
sda4 200M EFI (FreeBSD)
sda5 60G freebsd-ufs
sda6 8G freebsd-swap
The  second efi partition is very strange, there is only one file /EFI/Boot/BOOTX64.EFI, version 11.1 will have one more STARTUP.NSH, but none of them work. Even if I mount with the rw option, I can't write to the partition again. I tried to copy the file(s) to my own efi partition and added the entry with efibootmgr by:
efibootmgr -c -g -d /dev/sda -p 1 --label 'FreeBSD' --loader '/EFI/Boot/BOOTX64.EFI'
but it only started efi correctly, not the boot succeeded. I guess it is missing the necessary boot file, or there is no correct entry parameter telling the loader where to find the root directory.

How should I install in UEFI mode?


----------



## k.jacker (Mar 17, 2018)

To my knowledge, according to UEFI standard, when booting in UEFI mode the disk's partitions are searched sequential for an EFI partition. If found, boot will be attempted from the first bootable partition. So I guess the second EFI partition will never be seen, because the system will try to boot allready after Linux's EFI partition is found. The attempt to boot I guess will always be from your EXT4 partition, as it is the first bootable.

Long story short, you can't install in UEFI mode if you allready have an EFI partition.
You could instead install FreeBSD using a legacy freebsd-boot partition (this will be automatically created, same as with EFI).
Problem then, it will install a (protective) MBR, and looking at the age of your laptop, chances are really high that it will fall back trying to boot in legacy mode if an MBR is found on the disk. Yes, even if you have set your BIOS to UEFI boot.
That's against the UEFI standard, but it has been like this on all old hardware I have used. That would leave you unable to  boot your Linux.

But a little chance remains, if your laptop behaves according to UEFI standard, you could switch your BIOS between UEFI and legacy boot, to boot Linux (UEFI mode) or FreeBSD (legacy mode).
I have successful done that once on a Haswell generation computer.  

Another option maybe grub can be configured to boot a legacy freebsd-boot partition, but I really can't tell. I'm not a Linux guy and used grub last on FreeBSD 4.x 

I can't give you a perfect advice. It could work with legacy boot-code, but please don't try it if you depend on your Linux.
And yeah, try the search function here in the forum with something like "dualboot" and "grub". I think there have been discussions about that earlier.


----------



## greatfox (Mar 18, 2018)

Thanks for detailed advice.

I can't guarantee that the old notebook be perfect for UEFI, but since all major operating systems can be properly installed, and include open source projects such as Linux and EDK. Why FreeBSD cannot do it and it is not clearly given in the documentation that must be installed on a brand new hard disk.

I still deleted all GPT partitions (including EFI) and removed all EFI boot entries. But every time the installer hangs after the masks line.

Is it possible to find a manual installation of FreeBSD in UEFI mode? This allows me to create partitions in legacy mode and the enter UEFI mode through configuration.


----------



## k.jacker (Mar 18, 2018)

Hei,

FreeBSD has always been very standards compliant, more then MS and "Linux" (IMO), so I think it relies more on standard compliant and bugfree UEFI implementation.
I have experienced that UEFI implementations on older hardware are quite buggy, mostly unuseable I would say.
It works very well since Haswell generation hardware with FreeBSD for me.



greatfox said:


> I still deleted all GPT partitions (including EFI) and removed all EFI boot entries.


Do you mean, you have wiped the whole disk including your Linux?



greatfox said:


> Is it possible to find a manual installation of FreeBSD in UEFI mode?


You don't "create partitions in legacy mode". They are the same no matter if you told the installer to install legacy or EFI bootcode.
As said, you can't have more then one EFI partition. The FreeBSD installation itself is the same for legacy and EFI, it's just the bootcode that's different.

Long time since I used the installer, but you might want to manually create:

```
freebsd-boot (512K)    *this contains legacy bootcode that is normally executed by the MBR*
freebsd-ufs (60G)    /
freebsd-swap (8G)
```
...and then try to boot the freebsd-boot partition from the grub that came with you Linux installation.

Use the search function for that, I can't help you with grub


----------



## greatfox (Mar 18, 2018)

k.jacker said:


> FreeBSD has always been very standards compliant, more then MS and "Linux" (IMO), so I think it relies more on standard compliant and bugfree UEFI implementation.


Tianocore is Intel supported open source project. If it's Shell_Full.efi can run, and FreeBSD's installer doesn't boot properly, I think we need more evidence that the responsibility is not in FreeBSD. 



k.jacker said:


> Do you mean, you have wiped the whole disk including your Linux?


Yes, I wiped the whole disk including my linux.



k.jacker said:


> You don't "create partitions in legacy mode". They are the same no matter if you told the installer to install legacy or EFI bootcode.
> As said, you can't have more then one EFI partition. The FreeBSD installation itself is the same for legacy and EFI, it's just the bootcode that's different.


I also think that freebsd-ufs and freebsd-swap are correct, but I don't know what should be in the correct EFI partition. How does bootx64.efi know which freebsd-ufs partition is the root partition? There is no detail in the installation documentation.



k.jacker said:


> ...and then try to boot the freebsd-boot partition from the grub that came with you Linux installation.


If I start using UEFI mode, the installation wizard will not ask me to create freebsd-boot. Only when the Legacy mode starts, the installation wizard will auto create a freebsd-boot partition. And I have seen in other places that some people say that there are four partitions (efi, boot, ufs, swap) in 11.1-memstick.img because of the combination of uefi and legacy. So I believe that when using uefi boot, it should not require a freebsd-boot partition.

I should be able to properly configure a grub boot system, but I like EFI is easier to configure and easier to manage under the efi interface. If possible, I don't want to remember a bunch of grub commands later.


----------



## k.jacker (Mar 18, 2018)

greatfox said:


> So I believe that when using uefi boot, it should not require a freebsd-boot partition.


True, I meant to install a freebsd-boot partition and then let grub point to it. If you install FreeBSD to boot in UEFI mode there is no need for a freebsd-boot partition.
And yes, the 11.1-memstick.img has both EFI and legacy bootcode to be able to boot on new and old hardware as well.

Otherwise, I have never tried to fiddle with FreeBSD's efi bootcode and have no idea what Tianocore is, so I can't be of any help with that.
To get a better knowledge of how the FreeBSD UEFI booting stuff works I'd like to point you to the two most important manpages: boot(8) uefi(8)
All important files are in /boot/ on the freebsd-ufs partition.


----------



## asteriskRoss (Mar 19, 2018)

Hi greatfox, welcome to the forums.


greatfox said:


> Is it possible to find a manual installation of FreeBSD in UEFI mode? This allows me to create partitions in legacy mode and the enter UEFI mode through configuration.


It's certainly possible to install FreeBSD by hand and judging by your posts here you are not afraid to dive in.  There is no magic and if you like you can take a look at exactly what the bsdinstall(8) tool does by looking at its source here.  However, I would suggest that rather than trying to do it all by hand, just use the Shell mode of the installer, which will give you full control on the command line over disk partitioning using gpart(8) etc.  You might find it helpful to look at a howto I put together for FreeBSD 10.1, when the UEFI bootloader was new (and only supported UFS): Thread howto-freebsd-10-1-amd64-uefi-boot-with-encrypted-zfs-root-using-geli.51393.  This doesn't do exactly what you want but does at least point you in the right direction regarding creating an EFI partition, swap and UFS partition on the command line.

For anyone else reading this thread I'll note that I need to write an updated version of that howto.  It's now possible, provided you have a simple set-up and aren't picky about encryption algorithms, to install with an encrypted ZFS root using options in bsdinstall(8) without any need for typing on the command line.


----------



## greatfox (Mar 22, 2018)

Thanks very much to the comments of k.jacker and asteriskRoss. My problem seems to be caused by nvidia GT335m. I have already found the same report:
https://imgur.com/a/0Aw6x
Similar problems can be found at bugs.freebsd.org.

I have correctly configured the EFI partition with boot1.efi, the problem is the kernel runtime.

What is known now is that sometimes some operations in the Linux system will affect the system. After the hot reboot, it can still affect the FreeBSD kernel, so sometimes it can enter the system by boot.efi. But I'm not a system developer, unable to determine the relationship between the two.


----------



## VladiBG (Mar 22, 2018)

I had similar problem on HP Zbook 14 where the UEFI boot incorrectly report the frame buffer resolution. I resolved it whit (3) escaping to loader prompt and manually specify the fb resolution using graphics output protocol command

example:
`gop list`
`gop set <mode>`
`boot`

You can try to update your bios firmware if there's a new.


----------



## greatfox (Mar 22, 2018)

VladiBG said:


> I had similar problem on HP Zbook 14 where the UEFI boot incorrectly report the frame buffer resolution. I resolved it whit (3) escaping to loader prompt and manually specify the fb resolution using graphics output protocol command



my gop reports 2 mode,  0 is 1024x768, 1 is 800x600. 800x600 is default mode.
I tried both modes have failed.


----------



## tingo (Mar 24, 2018)

And you did try `gop set 1` also?
(one case I was seeing was that explicit setting the default mode worked. YMMV)


----------

