bugGNU GRUB - Bugs: bug #58498, GRUB cannot correctly boot...


You are not allowed to post comments on this tracker with your current authentication level.

bug #58498: GRUB cannot correctly boot kFreeBSD i386 from ZFS

Submitted by:  WHR <whr>
Submitted on:  Thu 04 Jun 2020 03:01:25 PM UTC  
Category:  Booting Severity:  Major
Priority:  5 - Normal Item Group:  Software Error
Status:  None Privacy:  Public
Assigned to:  None Originator Name:  WHR
Open/Closed:  Open Release: 
Release:  Git master Reproducibility:  Every Time
Planned Release:  None

Thu 04 Jun 2020 03:17:53 PM UTC, comment #1: 

The configuration example missing a line to set where '/' should be mounted from by kernel:

>  set kFreeBSD.vfs.root.mountfrom=zfs:zroot/ROOT/default

However it isn't important for this bug anyways.

WHR <whr>
Thu 04 Jun 2020 03:01:25 PM UTC, original submission:  

This issue can be reproduced with GRUB version 2.02 and 2.04, and I believe it exists in the latest source repository as well; unfortunately I can't select '2.04' in 'Release:' combo box on this page.

The kFreeBSD versions I tested are 10.1-RELEASE, 10.3-RELEASE, 11.1-RELEASE-p15, 12.0-RELEASE, 12.0-RELEASE-p5, 12.0-RELEASE-p9 and 12.0-RELEASE-p10.

To reproduce

  • Install a FreeBSD i386 system with ZFS root.
  • Install GRUB (i386-pc) by building it from source, and run grub-install(8) to install it to hard disk.
  • Create a grub.cfg by either running grub-mkconfig(8) or manually writing one.
  • Reboot the machine and select to boot FreeBSD from GRUB menu.

Simplified configuration example

> menuentry "FreeBSD i386" --class freebsd --class bsd --class os {
>  insmod part_gpt
>  insmod zfs
>  set root=hd0,gpt3
>  search --set root --label zroot
>  echo "Loading FreeBSD kernel ..."
>  kfreebsd /ROOT/default@/boot/kernel/kernel
>  kfreebsd_loadenv /ROOT/default@/boot/device.hints
>  kfreebsd_module_elf /ROOT/default@/boot/kernel/opensolaris.ko
>  kfreebsd_module_elf /ROOT/default@/boot/kernel/zfs.ko
> }


The system hang soon after GRUB jumps to kFreeBSD entry point, there is no console output from kFreeBSD.


GRUB source file 'grub-core/loader/i386/bsd.c' contains the following code in function 'grub_freebsd_boot':   

>       stack[1] = bootflags | FREEBSD_RB_BOOTINFO;
>       stack[2] = freebsd_bootdev;
>       stack[3] = freebsd_zfsguid ? 4 : 0;
>       stack[4] = freebsd_zfsguid;
>       stack[5] = freebsd_zfsguid >> 32;
>       stack[6] = stack_target + 9 * sizeof (grub_uint32_t);
>       stack[7] = bi.tags;
>       stack[8] = kern_end;

it prepare the arguments to be passed to the entry point of the kernel ('btext' in kFreeBSD image); the arguments 3, 4 and 5 are incorrect, because according to the corresponding FreeBSD source code (https://svnweb.freebsd.org/base/stable/12/sys/i386/i386/locore.s?revision=339434&view=markup#l178), those 3 arguments should always be set to 0 to distinguish from old boot protocols, otherwise the kernel would just halt as they assumed it was booted with an unsupported boot protocol (https://svnweb.freebsd.org/base/stable/12/sys/i386/i386/locore.s?revision=339434&view=markup#l214).

Since the boot protocol check exists only in kFreeBSD i386, and 'freebsd_zfsguid' will be 0 if current 'root' device in GRUB isn't a ZFS vdev, this bug only shown when booting kFreeBSD i386 with from ZFS.

Proposed fix

I removed 'freebsd_zfsguid' variable and codes that used it. Passing a ZPOOL GUID to the kernel would be completely useless, as the kernel didn't use it in anyways, but instead chokes on it.

The attached diff file is generated from the latest commit in 'master' branch of GRUB Git repository.

WHR <whr>


Attached Files


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by whr (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-06-04 whr Attached File- => Added grub-kfreebsd-i386-zfs-hang-fix.diff, #49213

    Back to the top

    Powered by Savane 3.5