Adding FreeBSD to Arch Linux Grub

Has anyone added a Grub menuentry for FreeBSD to an existing Arch Linux installation?

I created a 40_custom file but can't get FreeBSD launched.

I would prefer to add Arch Linux to my FreeBSD-based grub.cfg to boot from ISO but can't stumble across the required parameters...
 
Here is my Grub menuentry for GRUB2, regardless of the OS grub resides in:
Code:
menuentry 'FreeBSD 11.1-RELEASE-p1' {
insmod zfs
insmod part_gpt
search --no-floppy --fs-uuid [B]--set=root cd397a8f11725bf3[/B]
    kfreebsd /ROOT/freebsd-root/@/boot/kernel/kernel -v
    kfreebsd_loadenv /ROOT/freebsd-root/@/boot/device.hints
    kfreebsd_module /ROOT/freebsd-root/@/boot/zfs/zpool.cache -type /boot/zfs/zpool.cache
    kfreebsd_module /ROOT/freebsd-root/@/boot/entropy -type /boot/entropy
    kfreebsd_module_elf /ROOT/freebsd-root/@/boot/kernel/opensolaris.ko
    kfreebsd_module_elf /ROOT/freebsd-root/@/boot/kernel/zfs.ko
    kfreebsd_module_elf /ROOT/freebsd-root/@/boot/kernel/linux_common.ko
    kfreebsd_module_elf /ROOT/freebsd-root/@/boot/kernel/linux.ko
    kfreebsd_module_elf /ROOT/freebsd-root@/boot/kernel/drm2.ko
        kfreebsd_module_elf /ROOT/freebsd-root@/boot/kernel/iicbus.ko
        kfreebsd_module_elf /ROOT/freebsd-root@/boot/kernel/iicbb.ko
        kfreebsd_module_elf /ROOT/freebsd-root@/boot/kernel/iic.ko
        kfreebsd_module_elf /ROOT/freebsd-root@/boot/kernel/i915kms.ko
    set kFreeBSD.kern.vty=vt
    set kFreeBSD.vfs.root.mountfrom=zfs:mypool/ROOT/freebsd-root
    set kFreeBSD.vfs.root.mountfrom.options=rw
    set kFreeBSD.sem_load=NO
}
--set-root value is the one returned by grub-probe program of your linux installation.
In other cases it may be enough to use just "kfreebsd /boot/gptloader |gptzfsloader | zfsloader | loader" instead of this.
 
I would prefer to add Arch Linux to my FreeBSD-based grub.cfg to boot from ISO but can't stumble across the required parameters...
Note that this may NOT be possible because not every ISO has the ability to be booted in such way. You need to loop mount the ISO and check the grub.cfg file (or syslinux.conf for that matter) to see the way it boots, then try adding those kernel parameters to the GRUB boot command. Then you will see if the ISO can be booted that way at all, which depends on whether or not it creates /dev/loop at boot time, among other things.
 
Note that this may NOT be possible because not every ISO has the ability to be booted in such way. You need to loop mount the ISO and check the grub.cfg file (or syslinux.conf for that matter) to see the way it boots, then try adding those kernel parameters to the GRUB boot command. Then you will see if the ISO can be booted that way at all, which depends on whether or not it creates /dev/loop at boot time, among other things.

I do have a number of Linux ISO's that I've successfully incorporated into my FreeBSD-based Grub setup, but can't figure out the paramaters for Arch Linux. They are specified here.

Code:
menuentry '[loopback]archlinux-2014.11-1-archboot' {
   set isofile='/boot/iso/archlinux-2014.11-1-archboot.iso'
   loopback loop $isofile
   linux (loop)/boot/vmlinuz_x86_64 iso_loop_dev=$imgdevpath iso_loop_path=$isofile
   initrd (loop)/boot/initramfs_x86_64.img
}

The problem is I don't know how to interpret $imgdevpath...
 
It says:
set imgdevpath="/dev/disk/by-label/label_value"
or
set imgdevpath="/dev/disk/by-uuid/label_value"
Have you tried the value found under /dev/disk/by-label or /dev/disk/by-uuid in your Arch installation? If you ls -l /dev/disk/by-uuid, you will see which disk it is in "standard" notation. Use that for you GRUB installed under Linux.

Under FreeBSD use grub-probe command to find out your UUID. In the past the UUID shown under FreeBSD corresponded with the value /dev/disk/by-partuuid (not by-uuid) under LINUX. But since you're using FreeBSD GRUB, this shouldn't matter, that will help with the GRUB installed under FreeBSD. I mean, there used to be difference between the grub-probe output in both OS's, but since then they have fixed most of the bugs...

PS: Just in case: # grub-probe --target=fs_uuid -d /dev/adaX
 
In Linux (not available in ports) you can install the os-prober package which will add the ability to grub (grub-mkconfig) to find and auto-configure others OSes.

I never used it to add a FreeBSD installation but it ever works for Windows.
 
I would try this.

That being said, I used to dual-boot Arch and FreeBSD. The easiest way for me is GRUB2 from Arch (or whatever Linux distro) with FreeBSD chainloading.

I don't quite get how "FreeBSD GRUB" would be different of any other "Linux GRUB". As a bootloader it should load whatever asked to, provided it's correctly set. Am I missing something...?

Also:

The problem is I don't know how to interpret $imgdevpath...

As far as I know these variables are set during the boot and its different stages. In other words, when it comes to read /boot/grub/grub.cfg it seems to me [FONT=Courier New]$imgdevpath[/FONT] should've been already known and set. Stumbled upon this once, when trying to configure Arch with LVM on LUKS and type my passphrase only once during boot. Took me a couple of days researching GRUB2 until I caught a broader overview of how things (should) work. Hence, the answer for "how to interpret..." is probably "you shouldn't have to since GRUB is supposed to do it by itself".
 
Has anyone added a Grub menuentry for FreeBSD to an existing Arch Linux installation?

I've added Grub2 entries in Debian/Slackware for OpenBSD/NetBSD and if you use a UFS based filesystem, chainloading the bootblock is the easiest. I've seen alternative grub entries where an initrd, with the appropriate file system module, has to be be generated. Not clear from the OP what FreeBSD file system is being used.
 
I've added Grub2 entries in Debian/Slackware for OpenBSD/NetBSD and if you use a UFS based filesystem, chainloading the bootblock is the easiest. I've seen alternative grub entries where an initrd, with the appropriate file system module, has to be be generated. Not clear from the OP what FreeBSD file system is being used.

I have FreeBSD installed on a UFS partition, and eventually got it to work using 'chainloading'.

I found this page which shows three options for a FreeBSD menuentry but only the chainloading option worked for me. The others gave me:-
error: unknown filesystem.
 
Glad you've found the one that works for you.

Just for reference: the command line kfreebsd /boot/loader may need to be modified to suit the environment. In case you have GPT partitions it would not be just /boot/loader|zfsloader, but kfreebsd /boot/gptloader or /boot/zfsgptloader .

Chainloading, in turn, will work only if the bootblock is installed, and the kfreebsd $loader GRUB command doesn't need that. Which is useful if you did the installation in a non-standard way and omitted the bootblock installation...
 
This post can give a good idea as to what's understood to be $imgdevpath. As seems clear from the name itself, it's path to the device where ISO is located.

Thanks, I already found this earlier, but couldn't work out how it should be resolved... The Arch Linux ISO is actually on an ms-basic-data partition on a GPT disk. The disk has FreeBSD's GRUB2 installed and grub.cfg is located at (gpt2)/boot/grub. The location of the Arch Linux iso is (gpt6)/iso/archlinux-2017.04.01-x86_64.iso. When selecting this option from the Grub menu, I get:
Code:
:: running early hook [udev]
starting version 232
:: running early hook [archiso_pxe_nbd]
:: running hook [udev]
:: Triggering uevents...
:: running hook [memdisk]
:: running hook [archiso]
:: running hook [archiso_loop_mnt]
:: running hook [archiso_pxe_common]
:: running hook [archiso_pxe_nbd]
:: running hook [archiso_pxe_http]
:: running hook [archiso_pxe_nfs
:: Mounting '/dev/loop0' to '/run/archiso/bootmnt'
mount: you must specify the filesystem type
ERROR: failed to mount '/dev/loop0'
    Falling back to interactive prompt
    You can try to fix the problem manually, log ou when you are finished
sh: can't access tty; job control turned off
[rootfs ]#


If I type uname -a I get
Code:
Linux (none) 4.10.6.-1-ARCH #1 SMP PREEMPT Mon Mar 27 08:28:22 CEST 2017 x86_64 GNU/Linux
... so it seems as though Arch Linux has actually booted but there is no login prompt.
 
You say you "select that option from GRUB" -- ok, WHAT option do you select from GRUB? What boot commands are used in that option you select? Now THAT'S where your answer lies.

You understand, I'm sure, that with GRUB it doesn't really matter the OS under which it is installed. At the time of the boot process (which interests you most) the OS doesn't come into play at all. It being so, your questions must be first of all directed to the Arch people & mailing lists.
But meantime you can do some checks from the command prompt you've mentioned. For example, try to mount -t c9660 /dev/loop0 /run/archiso/bootmnt, as the prompt suggests. If it mounts all right, then you can exit the shell and see if it will boot normally.
 
Back
Top