[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug #58498] GRUB cannot correctly boot kFreeBSD i386 from ZFS
From: |
WHR |
Subject: |
[bug #58498] GRUB cannot correctly boot kFreeBSD i386 from ZFS |
Date: |
Thu, 4 Jun 2020 11:01:27 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0 |
URL:
<https://savannah.gnu.org/bugs/?58498>
Summary: GRUB cannot correctly boot kFreeBSD i386 from ZFS
Project: GNU GRUB
Submitted by: 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
Originator Email: msl0000023508@gmail.com
Open/Closed: Open
Release:
Release: Git master
Discussion Lock: Any
Reproducibility: Every Time
Planned Release: None
_______________________________________________________
Details:
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
> }
== Result ==
The system hang soon after GRUB jumps to kFreeBSD entry point, there is no
console output from kFreeBSD.
== Cause ==
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.
_______________________________________________________
File Attachments:
-------------------------------------------------------
Date: Thu 04 Jun 2020 03:01:25 PM UTC Name:
grub-kfreebsd-i386-zfs-hang-fix.diff Size: 2KiB By: whr
<http://savannah.gnu.org/bugs/download.php?file_id=49213>
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?58498>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [bug #58498] GRUB cannot correctly boot kFreeBSD i386 from ZFS,
WHR <=