Grub2 has no ZFS support

Hi there

I was wondering me that on a fresh installation after I've installed Grub2 from ports no support about ZFS is available.

Code:
/usr/local/sbin/grub-install --modules="zfs udf2" /dev/da0

breaks because no zfs module here :(

Will there comes somthing about that in the future? Or should I use Grub2 from the project-pages?
 
Aloha,

I am trying to make desktop FreeBSD zfs on my laptop. And I got in to the same trouble.

I've already got installed Fedora with Grub2. It should support ZFS boot with not problems.

However I spend long time searching in Google and trying to hit the exact entry in the grub.conf to make it boot the FreeBSD. At some places, they say that I can't boot because my partition table is FDISK, not GPT. Is this true?

And if not, can somebody post the syntax of entry in grub.conf for booting FreeBSD from ZFS pool?

Thank you.
 
Thank you vermaden, this is very nice stuff. For sure I am going to try it some day.

But today I had 2 already installed operating systems with already installed boot loader.

I was able to boot Fedora, I had grub and I just needed to boot the already installed FreeBSD 9.

I found what I needed, check this out:

You first need to install the boot loader with zfs.mod and zfsinfo.mod.

[CMD="root#"]grub2-install –-modules=zfs.mod –-modules=zfsinfo.mod /dev/sda[/CMD]

Then, the entry in /boot/grub2/grub.cfg will look like this:

Code:
menuentry "FreeBSD ZFS Loader" {
insmod zfs
search -s -l zfsroot  # zfsroot=the name of your root pool
kfreebsd /@/boot/zfsloader
}
This is all you need. I spend too much time searching in google, but I really needed to reed the grub2 man page.

However, if you like to skip the FreeBSD loader and you want to load directly the OS, you can do this:
Code:
menuentry "FreeBSD ZFS Loader" {
insmod zfs
search -s -l zfsroot  # zfsroot=the name of your root pool
kfreebsd /@/boot/kernel/kernel
kfreebsd_module_elf /@/boot/kernel/opensolaris.ko
kfreebsd_module_elf /@/boot/kernel/zfs.ko
kfreebsd_module /@/boot/zfs/zpool.cache type=/boot/zfs/zpool.cache
set kFreeBSD.vfs.root.mountfrom=zfs:zfsroot
}
I saw posts around the internet of people that do this and I tested it. It works. But I don’t prefer it, because this way you lose the options you have in the FreeBSD loader like Save mode, Disable ACPI, Single user mode and so on. Also /boot/loader.conf will not play role. So if you need to change some of this stuff, you have to do it by reconfiguring grub2.

Hope this was useful.
 
gnoma

Thanks for detailed FreeBSD/ZFS with GRUB2 information and also sorry for late response.

This may be useful for generating GRUB2 menu entries for ZFS Boot Environments (sysutils/beadm).

Some FreeBSD Developers are already working on the 'native' solution within the FreeBSD bootloader but its good to have 'backup solution' ;)

Regards,
vermaden
 
... But I don't prefer it, because this way you lose the options you have in the FreeBSD loader like Save mode, Disable ACPI, Single user mode and so on. Also /boot/loader.conf will not play role. So if you need to change some of this stuff, you have to do it by reconfiguring grub2.
Well, "reconfiguring grub2" sounds too scary compared with what one actually needs: edit your grub.cfg by adding a separate menuentry (or edit the existing one) and replace all the kfreebsd..., kfreebsd_module* lines with this single line:
Code:
kfreebsd $mypool/@/boot/zfsloader
That will launch BTX and zfs-aware loader, which will normally boot your $zfsroot/@/boot/kernel/kernel the FreeBSD way.
The only reason I'm using the complicated config with kfreebsd_module*... etc. is because it boots faster this way. Also to test and make sure GRUB2 can actually take the booting process into its hands entirely. But yes, in this case it isn't possible, for example, to specify kern.vty=vt option. Hope they'll add this functionality to GRUB2, seeing that they want to make it universal and so far it works pretty well.
Another problem is that the zfsloader boot command doesn't work so far with the EFI version of GRUB2. But I haven't tested it yet with the GNU git most recent code. Along with that it needs be tested, whether the newer version supports all ZFS feature flags. Because the last sysutils/grub2 version does not, so it won't work for a zpool created by the most recent FreeBSD installer.
 
... it needs be tested, whether the newer version supports all ZFS feature flags. Because the last sysutils/grub2 version does not, so it won't work for a zpool created by the most recent FreeBSD installer.
Well, bad news here :(:even the newest GNU git code, which I compiled in my Linux installation and linked against the latest git ZFS libraries, can't read the newest ZFS feature flags, so it can't boot anything from the newest zpool. So I don't even see how LINUX systems are supposed to reside on a newest versions of ZFS pool without a working bootloader to boot them. Except for the /boot residing in a big enough boot-bios partition. :)

One way out of this situation is to use one of the earlier installer CDs (I have one for 9.1-RELEASE) and create a zpool of an earlier "obsolete" version, but which will be available to GRUB2 bootloader.
 
...
One way out of this situation is to use one of the earlier installer CDs (I have one for 9.1-RELEASE) and create a zpool of an earlier "obsolete" version, but which will be available to GRUB2 bootloader.
Some further research over zpool-features(7) shows there is another option. It is to create zpool with the most recent ZFS tools, but at the time of creation only enable such features in the pool, as are known to GRUB2. That way the pool version will be up-to-date and yet it will be accessible to GRUB2. Here are the ones I have in my zpool which is yet available to GRUB2:
Code:
mypool  feature@async_destroy  enabled  local
mypool  feature@empty_bpobj  active  local
mypool  feature@lz4_compress  active  local
mypool  feature@multi_vdev_crash_dump  enabled  local
So I used the following command to create a zpool with only these feature flags enabled and other ones disabled:
Code:
sudo zpool create -d -o feature@async_destroy=enabled -o feature@empty_bpobj=enabled -o feature@lz4_compress=enabled -o feature@multi_vdev_crash_dump=enabled rpool /dev/ada0
The -d flag disables all feature flags when creating a zpool, so one may use this alone to have all of them disabled.
 
At the time of the last writing the latest git GRUB2 showed this problem: it couldn't recognize kfreebsd_module_elf $path-to/zfs.ko or any other, returning "file not found". Notably, grub shell does recognize the existence of the file itself, in that while you're typing it in grub shell like /ROOT/mypool@/boot/kernel/openso... -- and then press <Tab>, the shell completes the line to look like /ROOT/mypool@/boot/kernel/opensolaris.ko. As it is expected to do when the file is there. Yet if you type ls /ROOT/..etc.../opensolaris.ko, it returns "no such file" error. Weird?
So the only option to boot remains to use kfreebsd $path-to/boot/zfsloader.

But this is a git version, under development, so maybe by now they've solved this one? Never get time to try.
 
At the time of the last writing the latest git GRUB2 showed this problem: it couldn't recognize kfreebsd_module_elf $path-to/zfs.ko or any other, returning "file not found". Notably, grub shell does recognize the existence of the file itself, in that while you're typing it in grub shell like /ROOT/mypool@/boot/kernel/openso... -- and then press <Tab>, the shell completes the line to look like /ROOT/mypool@/boot/kernel/opensolaris.ko. As it is expected to do when the file is there. Yet if you type ls /ROOT/..etc.../opensolaris.ko, it returns "no such file" error. Weird?
So the only option to boot remains to use kfreebsd $path-to/boot/zfsloader.

But this is a git version, under development, so maybe by now they've solved this one? Never get time to try.
It's been solved now in GIT.
 
Hello,

sorry, that I refer to this old thread, but it hits my issues very well so I think it is not useful to open a new thread.

I've installed Antergos on my Notebook with following partition sheme (in FreeBSD terms):
Code:
ada0     GPT
ada0p1  bios_grub
ada0p2  ext4 #Partition for Antergos
ada0p3   swap #for Antergos
ada0p4   freebsd-swap
ada0p5   freebsd-zfs  #pool for FreeBSD and data
    zelch   none
    zelch/ROOT  none
    zelch/ROOT/default /zelch/system
    zelch/local  /local

With grub-zfs and linux-zfs Antergos is zfs ready, I can import the pool zelch under Antergos and see installed FreeBSD under /zelch/system

I've learned some months ago, that a separate freebsd-boot is not needed when starting FreeBSD with grub2.

But - which lines exactly I've to put into /etc/grub.d/40_custom, that I can start FreeBSD? Since a lot of ours I've tried to find out the correct code .... without any success.

Here is my current /etc/grub.d/40_custom:
Code:
#!/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
search -s -l zelch  # zfsroot=the name of your root pool
kfreebsd zelch/@/boot/zfsloader
set kFreeBSD.vfs.root.mountfrom=zfs:zelch/ROOT/default
}

When choosing FreeBSD ZFS loader from Grub menu, I get the message, that <boot> cannot be found.

Instead of
Code:
kfreebsd zelch/@/boot/zfsloader
I've also tried the following:
Code:
...
kfreebsd /@/boot/kernel/kernel
kfreebsd_module_elf /@/boot/kernel/opensolaris.ko
kfreebsd_module_elf /@/boot/kernel/zfs.ko
kfreebsd_module /@/boot/zfs/zpool.cache type=/boot/zfs/zpool.cache
...}
But get same message.

Another try with "zelch" before each /@/... also does not help.

A lot of other tries ends with the hint, that I've to load kernel first and so on ....

How to boot my FreeBSD?

Update1: Or would it be a better idea to create also a freebsd-boot (as first partition or could it also be ada0p5)?
Uptate2: Or is it better to install Grub2 on FreeBSD and not on Antergos?

Kind regards,
Holger
 
GRUB doesn't specify ZFS paths in a very intuitive way. You're probably looking for something like

Code:
search --set --label zelch
kfreebsd /ROOT/default/@/boot/zfsloader
You can verify that GRUB can see your files by dropping to a command prompt at boot and using ls to look around. That usually also gives you a hint as to how to indicate paths in your config.

If I can make one suggestion, it's that you keep FreeBSD's loader around in some capacity--even if that means chainloading it. Not only is it easier than loading the kernel and modules directly from GRUB, but it'll give you better support for boot environments.
 
Hello redpill

I'm very happy, your hint hits exactly my problem with grub2 and solves it.

Now I'm able to start FreeBSD,

Here a summary:
ada0 with GPT
p1 partition bios_grub
p2 partition ext4 Arch Linux
p3 partition linux-swap
p4 freebsd-swap
p5 freebsd-zfs with zelch as pool

A freebsd-boot is not needed.

To start FreeBSD from Arch's grub2 a /etc/grub.d/40_custom with following content is needed:
Code:
#!/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
search --set --label zelch
kfreebsd /ROOT/default/@/boot/zfsloader
}

A specification of partition is not needed, the line search --set --label zelch for specifying the pool is enough. So as abstract:
Code:
#!/bin/sh
exec tail -n +3 $0
menuentry "<name-of-entry-for-FreeBSD>" {
insmod zfs
search --set --label <name-of-pool>
kfreebsd /ROOT/default/@/boot/zfsloader
}

Kind regards,
Holger
 
Last edited by a moderator:
Hello hwagemann,

This is a little off topic question, but just out of curiosity why do you need 2 separated swap partitions - one for Linux and one for FreeBSD?
Shouldn't it be perfectly OK to use the same partition for swaping no matter if you are running FreeBSD, or Linux.

Thanks, iddqd & idkfa :)
 
Hello hwagemann,

This is a little off topic question, but just out of curiosity why do you need 2 separated swap partitions - one for Linux and one for FreeBSD?
Shouldn't it be perfectly OK to use the same partition for swaping no matter if you are running FreeBSD, or Linux.

Thanks, iddqd & idkfa :)

Hi,

well, good question. I was not sure, if this is possible.

But if this is possible, one of this swap partitions is not needed.

Thanks for your hint.

Kind regards,
Holger
 
Back
Top