How to install grub2 with ZFS and UEFI ?

Hi!
I having some trouble in installing GRUB2.

In FreeBSD 11.

SO,how can I install grub2 with ZFS and UEFI ?

My partitions:
Code:
=>       40  250069600  ada0  GPT  (119G)
         40     409600     1  efi  (200M)
     409640       2008        - free -  (1.0M)
     411648   16777216     2  freebsd-swap  (8.0G)
   17188864  232880128     3  freebsd-zfs  (111G)
  250068992        648        - free -  (324K)

my /etc/grub.d/40_custom:
Code:
root@ykla:~ # cat  /etc/grub.d/40_custom
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry "FreeBSD ZFS Loader" {
insmod zfs
kfreebsd /boot/loader

}
root@ykla:~ #

TIM图片20170825134556.png
TIM图片20170825134552.jpg
 
Last edited by a moderator:
If you have UEFI why are you using a bootloader? FreeBSD's UEFI program can boot ZFS according to the documentation. Try this guide. It will help you create an EFI System Partition to boot from:

https://wiki.freebsd.org/UEFI

If you're new to FreeBSD and ZFS I'd recommend taking a look at putting swap on a volume instead of a partition. I find it a lot more flexible.
 
If you have UEFI why are you using a bootloader? FreeBSD's UEFI program can boot ZFS according to the documentation. Try this guide. It will help you create an EFI System Partition to boot from:

https://wiki.freebsd.org/UEFI

If you're new to FreeBSD and ZFS I'd recommend taking a look at putting swap on a volume instead of a partition. I find it a lot more flexible.

Because I need grub to boot other system.
 
I had assumed you had a single OS because you only showed ada0 and it only has FreeBSD on it. I believe your problem is with /boot/loader. I don't think you can load FreeBSD on UEFI with that. You have to select an *.efi program to execute. It would be something along the lines of:

Code:
menuentry "FreeBSD ZFS Loader" {
       insmod part_gpt
        insmod chain
        set root='(hd0,gpt1)'
        chainloader /EFI/Boot/FreeBSD.efi
}

Where hd0,gpt1 is your EFI System Partition. You may have to change that. Have you installed the FreeBSD EFI binaries to your EFI System Partition? I named the efi file "FreeBSD.efi" in my example because bootx64.efi is the grub2-efi bootloader and you don't want to overwrite that.

Every EFI firmware implementation I've seen allows you to add custom boot options where you can select different EFI programs to execute, even on the same partition. This is the simplest way of booting one of multiple operating systems. You could also use rEFInd if you must have a boot loader.

I would really recommend you look into using your system's boot manager to boot different operating systems. For example you could add these boot options to your boot manager:

| Name | Path |
| FreeBSD | /EFI/Boot/FreeBSDx64.efi |
| Windows | /EFI/Microsoft/Boot/bootmgfw.efi |
 
I had assumed you had a single OS because you only showed ada0 and it only has FreeBSD on it. I believe your problem is with /boot/loader. I don't think you can load FreeBSD on UEFI with that. You have to select an *.efi program to execute. It would be something along the lines of:

Code:
menuentry "FreeBSD ZFS Loader" {
       insmod part_gpt
        insmod chain
        set root='(hd0,gpt1)'
        chainloader /EFI/Boot/FreeBSD.efi
}

Where hd0,gpt1 is your EFI System Partition. You may have to change that. Have you installed the FreeBSD EFI binaries to your EFI System Partition? I named the efi file "FreeBSD.efi" in my example because bootx64.efi is the grub2-efi bootloader and you don't want to overwrite that.

Every EFI firmware implementation I've seen allows you to add custom boot options where you can select different EFI programs to execute, even on the same partition. This is the simplest way of booting one of multiple operating systems. You could also use rEFInd if you must have a boot loader.

I would really recommend you look into using your system's boot manager to boot different operating systems. For example you could add these boot options to your boot manager:

| Name | Path |
| FreeBSD | /EFI/Boot/FreeBSDx64.efi |
| Windows | /EFI/Microsoft/Boot/bootmgfw.efi |

Yep,I have two disks . Other System is Mac OS ,so I need to using Cover to boot grub2,and then by grub2 I can boot FreeBSD.
 
What version of MacOS? MacOS X (I know they don't call it that anymore) also uses UEFI :). The boot program is here: /System/Library/CoreServices/boot.efi. If you can load that program from your Mac's EFI shell then you will definitely not need this complicated boot process. Personally I do not think grub is even reaching the menu entry. That error you are getting

If that does not work then try adding a grub2 menu entry that loads the FreeBSD UEFI boot program.

If for some reason you do not want to use UEFI at all in the FreeBSD boot handoff and you want to use grub's legacy loader the correct loader to use is /boot/gptzfsboot, not /boot/loader. I use /boot/gptzfsboot because my server does not support UEFI. If it did support UEFI I would be using it.

Some form of this should work if you really want to stick with grub:

Code:
menuentry "FreeBSD ZFS Loader" {
      insmod part_gpt
        insmod zfs
        set root='(hd0,gpt2)'
        chainloader /boot/gptzfsboot
}

You'll have to modify the root to match your disk and the ZFS partition.

EDIT: I just took another look at that picture you took of you booting the machine. Although your menuentry is not correct I do not think that's the problem. The error about RSDP has to do with GRUB attempting to locate the ACPI tables. For some reason GRUB cannot find RSDP in your EFI_SYSTEM_TABLE. If it truly is not there then you have no choice but to add the FreeBSD UEFI loader to your boot options.
 
What version of MacOS? MacOS X (I know they don't call it that anymore) also uses UEFI :). The boot program is here: /System/Library/CoreServices/boot.efi. If you can load that program from your Mac's EFI shell then you will definitely not need this complicated boot process. If that does not work then try adding a grub2 menu entry that loads the FreeBSD UEFI boot program.

If for some reason you do not want to use UEFI at all in the FreeBSD boot handoff and you want to use grub's legacy loader the correct loader to use is /boot/gptzfsboot, not /boot/loader. I use /boot/gptzfsboot because my server does not support UEFI. If it did support UEFI I would be using it.

Some form of this should work if you really want to stick with grub:

Code:
menuentry "FreeBSD ZFS Loader" {
      insmod part_gpt
        insmod zfs
        set root='(hd0,gpt2)'
        chainloader /boot/gptzfsboot
}

You'll have to modify the root to match your disk and the ZFS partition.
Nope.Must using clover,I am not real mbp.X86 Mac OS.
 
Clover is a UEFI loader... Grub cannot find RSDP. Look at my edit on my previous post. You cannot use it. You'll have to boot FreeBSD with UEFI.
 
Okay. Listen to me. You cannot use GRUB. That system has quirky firmware. GRUB doesn't like it. It's probably searching in a specific area for RSDP and it cannot find it. Your system has UEFI. It can boot to FreeBSD if you put FreeBSD's UEFI loader in your EFI System Partition. You can still use Clover to boot to MacOS. You just can't use GRUB.

Your system does not have an interface for changing the boot variables for UEFI. You can only do it from within the Operating System. I'm not going to waste time telling you how to do this if you're not going to listen. Either let me help you or send a compliant to GRUB's mailing list.
 
Okay. Listen to me. You cannot use GRUB. That system has quirky firmware. GRUB doesn't like it. It's probably searching in a specific area for RSDP and it cannot find it. Your system has UEFI. It can boot to FreeBSD if you put FreeBSD's UEFI loader in your EFI System Partition. You can still use Clover to boot to MacOS. You just can't use GRUB.

Your system does not have an interface for changing the boot variables for UEFI. You can only do it from within the Operating System. I'm not going to waste time telling you how to do this if you're not going to listen. Either let me help you or send a compliant to GRUB's mailing list.
Thanks a lot and I will send an email to grub mailing list.
No reply at all.
 
Last edited:
Back
Top