Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 442050 - [patch] sys-boot/grub-2.00-r1 build fails on Gentoo/FreeBSD
Summary: [patch] sys-boot/grub-2.00-r1 build fails on Gentoo/FreeBSD
Status: RESOLVED FIXED
Alias: None
Product: Gentoo/Alt
Classification: Unclassified
Component: FreeBSD (show other bugs)
Hardware: All FreeBSD
: Normal normal (vote)
Assignee: Mike Gilbert
URL: https://savannah.gnu.org/bugs/index.p...
Whiteboard:
Keywords: Goal, Inclusion
Depends on:
Blocks:
 
Reported: 2012-11-06 15:33 UTC by Yuta SATOH
Modified: 2013-01-07 03:27 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
files/grub-2.00-fbsd.patch (grub-2.00-fbsd.patch,4.55 KB, patch)
2012-11-06 15:51 UTC, Yuta SATOH
Details | Diff
files/grub-2.00-fbsd91-boot.patch (grub-2.00-fbsd91-boot.patch,1.41 KB, patch)
2012-11-06 15:52 UTC, Yuta SATOH
Details | Diff
patch for grub-2.00-r1.ebuild (442050.patch,1.15 KB, patch)
2012-11-06 15:57 UTC, Yuta SATOH
Details | Diff
patch for grub-2.00-r1.ebuild (442050-new.patch,1.02 KB, patch)
2012-11-07 11:23 UTC, Yuta SATOH
Details | Diff
When static enabled, fails to link libgeom -- log (442050-log.txt,11.70 KB, text/plain)
2012-11-07 11:33 UTC, Yuta SATOH
Details
files/grub-2.00-fbsd.patch (grub-2.00-fbsd.patch,5.26 KB, patch)
2012-11-07 11:34 UTC, Yuta SATOH
Details | Diff
files/grub-2.00-fbsd.patch (grub-2.00-fbsd.patch,16.08 KB, patch)
2013-01-04 11:12 UTC, Yuta SATOH
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yuta SATOH 2012-11-06 15:33:13 UTC
I have confirmed basic operation of grub2.
What about as an alternative sys-freebsd/boot0 can not be compiled gcc version 4.6 or later.

I have confirmed can boot directly using grub2 in the following environments.
* FreeBSD 9.1-RC2 amd64
* gcc-4.6.3
* patched grub-2.00
* BIOS/GPT (FYI, https://wiki.gentoo.org/wiki/Gentoo_FreeBSD#If_you_want_to_use_the_UFS2_file_system_.28GPT.29 )
* UFS2

How to use
1. layman -a gentoo-bsd
2. echo 'source /var/lib/layman/make.conf' >> /etc/portage/make.conf
3. ACCEPT_KEYWORDS=~amd64 USE="-nls -device-mapper -mount" emerge -va sys-boot/grub::gentoo-bsd
4. grub2-install --modules="part_gpt fat ufs2" --no-floppy /dev/ada0
5. grub2-mkconfig -o /boot/grub2/grub.cfg


I'm not confirm ZFS and other operation yet.
please test!
and please update the patches.

thanks in advance.
Comment 1 Yuta SATOH 2012-11-06 15:51:20 UTC
Created attachment 328544 [details, diff]
files/grub-2.00-fbsd.patch

* Added support freebsd-boot partition on GPT.
* FreeBSD's sed doesn't support '\t', change to tab.
* grub2-probe is used instead of grub-probe on Gentoo.

Taken from FreeBSD ports (I made ​​some changes for grub-2.00)
patch-include-grub-gpt_partition.h
patch-util-i386-pc-grub-setup.c
patch-util-grub.d-10_kfreebsd.in
Comment 2 Yuta SATOH 2012-11-06 15:52:11 UTC
Created attachment 328546 [details, diff]
files/grub-2.00-fbsd91-boot.patch

Fix to boot directly.

Taken from http://people.freebsd.org/~nox/tmp/grub2-paste_180121.patch
FYI, http://www.freebsd.org/cgi/query-pr.cgi?pr=170417&cat=ports
Comment 3 Yuta SATOH 2012-11-06 15:57:25 UTC
Created attachment 328548 [details, diff]
patch for grub-2.00-r1.ebuild

use elibc_FreeBSD && append-cppflags "-isystem /usr/include" to fix the following problems.

x86_64-gentoo-freebsd9.1-gcc -DHAVE_CONFIG_H -I. -I/var/tmp/portage/sys-boot/grub-2.00-r1/work/grub-2.00/grub-core -I..  -Wall -W -I/var/tmp/portage/sys-boot/grub-2.00-r1/work/grub-2.00/include -I../include  -DGRUB_MACHINE_PCBIOS=1 -DGRUB_MACHINE=I386_PC -DGRUB_TARGET_CPU_I386=1 -m32 -nostdinc -isystem /usr/lib/gcc/x86_64-gentoo-freebsd9.1/4.6.3/include -DGRUB_FILE=\"fs/btrfs.c\" -I. -I/var/tmp/portage/sys-boot/grub-2.00-r1/work/grub-2.00/grub-core -I.. -I/var/tmp/portage/sys-boot/grub-2.00-r1/work/grub-2.00 -I/var/tmp/portage/sys-boot/grub-2.00-r1/work/grub-2.00/include -I../include   -I/var/tmp/portage/sys-boot/grub-2.00-r1/work/grub-2.00/grub-core/lib/posix_wrap -I/var/tmp/portage/sys-boot/grub-2.00-r1/work/grub-2.00/grub-core/lib/minilzo -DMINILZO_HAVE_CONFIG_H   -Os -Wall -W -Wshadow -Wold-style-definition -Wpointer-arith -Wundef -Wextra -Waddress -Wattributes -Wcast-align -Wchar-subscripts -Wcomment -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wempty-body -Wendif-labels -Wfloat-equal -Wformat-extra-args -Wformat-security -Wformat-y2k -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Winit-self -Wint-to-pointer-cast -Winvalid-pch -Wmain -Wmissing-braces -Wmissing-field-initializers -Wmissing-format-attribute -Wmissing-noreturn -Wmultichar -Wnonnull -Woverflow -Wparentheses -Wpointer-arith -Wpointer-to-int-cast -Wreturn-type -Wsequence-point -Wshadow -Wsign-compare -Wstrict-aliasing -Wswitch -Wtrigraphs -Wundef -Wunknown-pragmas -Wunused -Wunused-function -Wunused-label -Wunused-parameter -Wunused-value  -Wunused-variable -Wvariadic-macros -Wvolatile-register-var -Wwrite-strings -Wnested-externs -Wstrict-prototypes -Wpointer-sign -g -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations -falign-jumps=1 -falign-loops=1 -falign-functions=1 -mno-mmx -mno-sse -mno-sse2 -mno-3dnow -fno-dwarf2-cfi-asm -fno-asynchronous-unwind-tables -m32 -fno-stack-protector -mno-stack-arg-probe -Wno-trampolines   -mrtd -mregparm=3       -ffreestanding -fno-builtin -Wno-undef   -c -o fs/btrfs_module-btrfs.o `test -f 'fs/btrfs.c' || echo '/var/tmp/portage/sys-boot/grub-2.00-r1/work/grub-2.00/grub-core/'`fs/btrfs.c
In file included from /var/tmp/portage/sys-boot/grub-2.00-r1/work/grub-2.00/grub-core/lib/minilzo/lzoconf.h:56:0,
                 from /var/tmp/portage/sys-boot/grub-2.00-r1/work/grub-2.00/grub-core/lib/minilzo/minilzo.h:60,
                 from /var/tmp/portage/sys-boot/grub-2.00-r1/work/grub-2.00/grub-core/fs/btrfs.c:29:
/usr/lib/gcc/x86_64-gentoo-freebsd9.1/4.6.3/include/stddef.h:59:24: fatal error: sys/_types.h: No such file or directory
compilation terminated.
gmake[3]: *** [fs/btrfs_module-btrfs.o] Error 1
gmake[3]: Leaving directory `/var/tmp/portage/sys-boot/grub-2.00-r1/work/build-guessed/grub-core'
gmake[2]: *** [all] Error 2
gmake[2]: Leaving directory `/var/tmp/portage/sys-boot/grub-2.00-r1/work/build-guessed/grub-core'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/var/tmp/portage/sys-boot/grub-2.00-r1/work/build-guessed'
gmake: *** [all] Error 2
Comment 4 Richard Yao (RETIRED) gentoo-dev 2012-11-07 01:06:53 UTC
These patches should be applied unconditionally. A scenario in which the conditional patching based on elibc_FreeBSD would cause a problem would be a dual-boot between Gentoo Linux and Gentoo FreeBSD where the Gentoo Linux package is used.
Comment 5 Yuta SATOH 2012-11-07 11:23:44 UTC
Created attachment 328650 [details, diff]
patch for grub-2.00-r1.ebuild

(In reply to comment #4)
> These patches should be applied unconditionally. A scenario in which the
> conditional patching based on elibc_FreeBSD would cause a problem would be a
> dual-boot between Gentoo Linux and Gentoo FreeBSD where the Gentoo Linux
> package is used.

Thank you for your comment.
I attach a new patch.

Fix patch for FreeBSD to be applied all environments.
I made the following changes in addition.

 RDEPEND+="
-	grub_platforms_efi-32? ( sys-boot/efibootmgr )
-	grub_platforms_efi-64? ( sys-boot/efibootmgr )
+	kernel_linux? (
+		grub_platforms_efi-32? ( sys-boot/efibootmgr )
+		grub_platforms_efi-64? ( sys-boot/efibootmgr )
+	)
 "
Comment 6 Yuta SATOH 2012-11-07 11:26:34 UTC
Update the status of operation check.

BIOS/GPT/UFS2, boot directly ok. see comment #0
BIOS/MBR/UFS2, boot directly ok.

grub2-install --modules="biosdisk part_msdos bsd search_fs_uuid ufs2 msdospart" --no-floppy /dev/ada0

NOTE,
You need to create a free space when creating partitions in order to successfully install grub2.

# gpart add -b 1024k -t freebsd ada0
=>      63  23068609  ada0  MBR  (11G)
        63      2016        - free -  (1M)
      2079  23066568     1  freebsd  [active]  (11G)
  23068647        25        - free -  (12k)

BIOS/GPT/ZFS, boot directly ok.
Patch needs to be updated. I'll attach it, and also update patch on overlay.

grub2-install --modules="part_gpt fat zfs" --no-floppy /dev/ada0


If you want to install the modules of larger capacity may not be enough free space.
I would like to change to reserve 1MB of free space in the description on the wiki...

The error message is as follows.
/usr/sbin/grub2-bios-setup: warning: your BIOS Boot Partition is too small; embedding won't be possible.
/usr/sbin/grub2-bios-setup: error: embedding is not possible, but this is required for cross-disk install.
Comment 7 Yuta SATOH 2012-11-07 11:33:04 UTC
Created attachment 328656 [details]
When static enabled, fails to link libgeom -- log

Information whether you can build

[ebuild   R    ] sys-boot/grub-2.00-r1::x-portage  USE="debug doc efiemu nls sdl truetype -custom-cflags -device-mapper (-libzfs) -mount -static" GRUB_PLATFORMS="coreboot efi-32 efi-64 ieee1275 multiboot pc qemu -emu -qemu-mips -yeeloong" 0 kB

USE flag
device-mapper and mount, probably only on linux.
please add to package.use.mask or use.mask.

device-mapper depends lvm2 and util-linux.
mount depends fuse and fuse4bsd.


When you enable USE flag static, it can not be compiled.
In the following the error message. details, please see attached log.

checking for geom_gettree in -lgeom... no
configure: error: Your platform requires libgeom


GRUB_PLATFORM
I have confirmed build of platforms other than those listed below.

qemu-mips yeeloong
CPU doesn't support

emu
Linux only ?
/var/tmp/portage/sys-boot/grub-2.00-r1/work/grub-2.00/grub-core/net/drivers/emu/emunet.c:24:22: fatal error: linux/if.h: No such file or directory
Comment 8 Yuta SATOH 2012-11-07 11:34:38 UTC
Created attachment 328658 [details, diff]
files/grub-2.00-fbsd.patch

fix for grub2-mkconfig to work correctly on ZFS environment
Comment 9 Richard Yao (RETIRED) gentoo-dev 2012-11-20 12:27:01 UTC
This looks good to me. floppym is the GRUB2 maintainer, so I am turning this over to him.
Comment 10 Mike Gilbert gentoo-dev 2012-11-21 05:03:11 UTC
(In reply to comment #2)
> Created attachment 328546 [details, diff] [details, diff]
> files/grub-2.00-fbsd91-boot.patch
> 

This has been applied upstream in revision 4556, so I have no problem applying it.

(In reply to comment #8)
> Created attachment 328658 [details, diff] [details, diff]
> files/grub-2.00-fbsd.patch

I would feel much more comfortable applying this patches if you would get it committed upstream first.

I suggest breaking this into 2 patches: one for the partmap changes, and another for the changes to 10_kfreebsd.in.

Instead of hard-coding "grub2-probe", please use the ${grub_probe} variable, as is done in 10_linux.in.
Comment 11 Yuta SATOH 2012-11-21 11:37:38 UTC
(In reply to comment #10)
> (In reply to comment #8)
> > Created attachment 328658 [details, diff] [details, diff] [details, diff]
> > files/grub-2.00-fbsd.patch
> 
> I would feel much more comfortable applying this patches if you would get it
> committed upstream first.
> 
> I suggest breaking this into 2 patches: one for the partmap changes, and
> another for the changes to 10_kfreebsd.in.

Thanks for your comment.

gpart support bios-boot partition type.
so, patch to support the freebsd-boot partition is not required.

I had to remove patches of grub-core/partmap/gpt.c and include/grub/gpt_partition.h.

Please change the partition type before you run the grub2-install.
# gpart modify -i 1 -t bios-boot ada0

FYI,
http://svnweb.freebsd.org/base/releng/9.1/sys/geom/part/g_part.c?r1=217040&r2=218014


> Instead of hard-coding "grub2-probe", please use the ${grub_probe} variable,
> as is done in 10_linux.in.

I reported to upstream, updated patch for 10_kfreebsd.in.
Please see URL.

NOTE,
\t problem is fixed in upstream, rev 4584
http://bzr.savannah.gnu.org/lh/grub/trunk/grub/revision/4584
Comment 13 Mike Gilbert gentoo-dev 2013-01-07 03:27:05 UTC
Ok I think I have applied everything that needed to be applied.