Skip to contentSkip to conversation

grub + FreeBSD's loader(8) + ZFS root

PATCH In review Navdeep Parhar 3 participants 6 messages Feb 22, 2010 – Feb 27, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 grub + FreeBSD's loader(8) + ZFS root

Hello grub-devel,

Right now it's not possible to boot using FreeBSD's loader(8) from a ZFS root filesystem. Grub doesn't indicate to the loader that there is a ZFS root involved and consequently the loader fails to find the kernel. The attached patch fixes this. It does not affect those that boot the kernel directly. This is only for users that want to boot using FreeBSD's loader.

Why would you want to? IMHO it is much simpler to boot indirectly using the loader because in that case grub does not have to deal with device.hints, kernel modules, kFreeBSD.xxx style variables, /boot/zfs/zpool.cache, etc. As a FreeBSD user, I'm used to putting this information in the "normal" config files (/boot/loader.conf, device.hints, etc.) and not in a grub.cfg file. Grub only needs to know where the loader is, nothing else:

menuentry "FreeBSD 8" {
search -s -l fbsd8
kfreebsd -D /@/boot/zfsloader
}
(fbsd8 is the name of the ZFS root pool)

Let me know if you have any questions. Once again, if you load the kernel directly and want to load modules and set kFreeBSD.foo.bar=... yourself, all that will continue to work.

Regards,
Navdeep

loader/i386/bsd.c +28 -1
diff -r 59814c4fed40 -r 21692a51cebb loader/i386/bsd.c
@@ -54,6 +54,7 @@
 static grub_dl_t my_mod;
 static grub_addr_t entry, entry_hi, kern_start, kern_end;
 static grub_uint32_t bootflags;
+static grub_uint64_t zpool_guid = 0;
 static char *mod_buf;
 static grub_uint32_t mod_buf_len, mod_buf_max, kern_end_mdofs;
 static int is_elf_kernel, is_64bit;
@@ -559,7 +560,7 @@
     }
   else
     grub_unix_real_boot (entry, bootflags | FREEBSD_RB_BOOTINFO, bootdev,
-			 0, 0, 0, &bi, bi.tags, kern_end);
+			 zpool_guid ? 4 : 0, zpool_guid, &bi, bi.tags, kern_end);
 
   /* Not reached.  */
   return GRUB_ERR_NONE;
@@ -742,6 +743,7 @@
 
   grub_free (netbsd_root);
   netbsd_root = NULL;
+  zpool_guid = 0;
 
   return GRUB_ERR_NONE;
 }
@@ -954,6 +956,30 @@
   return result;
 }
 
+static void
+grub_fetch_zpool_guid(void)
+{
+  grub_device_t dev;
+  grub_fs_t fs;
+  char *uuid = NULL;
+
+  dev = grub_device_open (NULL);
+  if (! dev)
+    return;
+
+  fs = grub_fs_probe (dev);
+  if (! fs)
+    return;
+
+  if (grub_strcmp(fs->name, "zfs") != 0 ||
+      ! fs->uuid || fs->uuid (dev, &uuid) || !uuid)
+    return;
+
+  zpool_guid = grub_strtoull(uuid, NULL, 16);
+
+  grub_free (uuid);
+}
+
 static grub_err_t
 grub_cmd_freebsd (grub_extcmd_t cmd, int argc, char *argv[])
 {
@@ -1012,6 +1038,7 @@
 	    return err;
 	}
       grub_loader_set (grub_freebsd_boot, grub_bsd_unload, 1);
+      grub_fetch_zpool_guid();
     }
 
   return grub_errno;
#1 lore raw

Warning messages

Hi,

Are these no-prototype warnings normal/expected?

gcc-4.3.2 -Itests/lib -I../tests/lib -nostdinc -isystem /usr/lib/gcc/i386-pc-solaris2.11/4.3.2/include -I../include -I. -I./include -Wall -W -Os -DGRUB_MACHINE_PCBIOS=1 -Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes -Wundef -Wstrict-prototypes -g -falign-jumps=1 -falign-loops=1 -falign-functions=1 -mno-mmx -mno-sse -mno-sse2 -mno-3dnow -fno-common -m32 -fno-stack-protector -mno-stack-arg-probe -Werror -fno-builtin -mrtd -mregparm=3-m32 -MD -c -o functional_test_mod-tests_lib_functional_test.o ../tests/lib/functional_test.c
../lib/libgcrypt-grub/cipher/camellia.c:447: warning: no previous prototype for 'camellia_setup128' ../lib/libgcrypt-grub/cipher/camellia.c:658: warning: no previous prototype for 'camellia_setup256'
gcc-4.3.2 -Itests/lib -I../tests/lib -nostdinc -isystem /usr/lib/gcc/i386-pc-solaris2.11/4.3.2/include -I../include -I. -I./include -Wall -W -Os -DGRUB_MACHINE_PCBIOS=1 -Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes -Wundef -Wstrict-prototypes -g -falign-jumps=1 -falign-loops=1 -falign-functions=1 -mno-mmx -mno-sse -mno-sse2 -mno-3dnow -fno-common -m32 -fno-stack-protector -mno-stack-arg-probe -Werror -fno-builtin -mrtd -mregparm=3 -m32 -MD -c -o functional_test_mod-tests_lib_test.o ../tests/lib/test.c
../lib/libgcrypt-grub/cipher/camellia.c:944: warning: no previous prototype for 'camellia_setup192' ../lib/libgcrypt-grub/cipher/camellia.c: In function 'camellia_setup192':
../lib/libgcrypt-grub/cipher/camellia.c:949: warning: implicit declaration of function 'memcpy' ../lib/libgcrypt-grub/cipher/camellia.c: At top level:
../lib/libgcrypt-grub/cipher/camellia.c:966: warning: no previous prototype for 'camellia_encrypt128' ../lib/libgcrypt-grub/cipher/camellia.c:1056: warning: no previous prototype for 'camellia_decrypt128' ../lib/libgcrypt-grub/cipher/camellia.c:1149: warning: no previous prototype for 'camellia_encrypt256' ../lib/libgcrypt-grub/cipher/camellia.c:1263: warning: no previous prototype for 'camellia_decrypt256'

--S

#2 lore raw

Re: Warning messages

Quoted 4 lines · Seth Goldberg

Hi,

Are these no-prototype warnings normal/expected?

GRUB team doesn't manage files under lib/libgcrypt(-grub), they are imported unmodified from libgcrypt. If you want them fixed, feel free to contact libgcrypt team and the change will propagate on next resync

Quoted 48 lines

gcc-4.3.2 -Itests/lib -I../tests/lib -nostdinc -isystem /usr/lib/gcc/i386-pc-solaris2.11/4.3.2/include -I../include -I.

(quoted diff) +0 -6
-I./include -Wall -W  -Os -DGRUB_MACHINE_PCBIOS=1 -Wall -W -Wshadow
-Wpointer-arith -Wmissing-prototypes          -Wundef
-Wstrict-prototypes -g -falign-jumps=1 -falign-loops=1
-falign-functions=1 -mno-mmx -mno-sse -mno-sse2 -mno-3dnow -fno-common
-m32 -fno-stack-protector -mno-stack-arg-probe -Werror -fno-builtin
-mrtd -mregparm=3-m32 -MD -c -o

functional_test_mod-tests_lib_functional_test.o ../tests/lib/functional_test.c ../lib/libgcrypt-grub/cipher/camellia.c:447: warning: no previous prototype for 'camellia_setup128' ../lib/libgcrypt-grub/cipher/camellia.c:658: warning: no previous prototype for 'camellia_setup256'
gcc-4.3.2 -Itests/lib -I../tests/lib -nostdinc -isystem /usr/lib/gcc/i386-pc-solaris2.11/4.3.2/include -I../include -I.

(quoted diff) +0 -6
-I./include -Wall -W  -Os -DGRUB_MACHINE_PCBIOS=1 -Wall -W -Wshadow
-Wpointer-arith -Wmissing-prototypes                -Wundef
-Wstrict-prototypes -g -falign-jumps=1 -falign-loops=1
-falign-functions=1 -mno-mmx -mno-sse -mno-sse2 -mno-3dnow -fno-common
-m32 -fno-stack-protector -mno-stack-arg-probe -Werror -fno-builtin
-mrtd -mregparm=3 -m32 -MD -c -o functional_test_mod-tests_lib_test.o

../tests/lib/test.c ../lib/libgcrypt-grub/cipher/camellia.c:944: warning: no previous prototype for 'camellia_setup192' ../lib/libgcrypt-grub/cipher/camellia.c: In function 'camellia_setup192':
../lib/libgcrypt-grub/cipher/camellia.c:949: warning: implicit declaration of function 'memcpy' ../lib/libgcrypt-grub/cipher/camellia.c: At top level:
../lib/libgcrypt-grub/cipher/camellia.c:966: warning: no previous prototype for 'camellia_encrypt128' ../lib/libgcrypt-grub/cipher/camellia.c:1056: warning: no previous prototype for 'camellia_decrypt128' ../lib/libgcrypt-grub/cipher/camellia.c:1149: warning: no previous prototype for 'camellia_encrypt256' ../lib/libgcrypt-grub/cipher/camellia.c:1263: warning: no previous prototype for 'camellia_decrypt256'

--S

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#3 lore raw
In reply to Navdeep Parhar
Quoted 17 lines · Navdeep Parhar

Hello grub-devel,

Right now it's not possible to boot using FreeBSD's loader(8) from a ZFS root filesystem. Grub doesn't indicate to the loader that there is a ZFS root involved and consequently the loader fails to find the kernel. The attached patch fixes this. It does not affect those that boot the kernel directly. This is only for users that want to boot using FreeBSD's loader.

Why would you want to? IMHO it is much simpler to boot indirectly using the loader because in that case grub does not have to deal with device.hints, kernel modules, kFreeBSD.xxx style variables, /boot/zfs/zpool.cache, etc. As a FreeBSD user, I'm used to putting this information in the "normal" config files (/boot/loader.conf, device.hints, etc.) and not in a grub.cfg file. Grub only needs to know where the loader is, nothing else:

Quoted 7 lines

menuentry "FreeBSD 8" {
search -s -l fbsd8
kfreebsd -D /@/boot/zfsloader
}
(fbsd8 is the name of the ZFS root pool)

Eternal chainloading isn't the way to go. It limits grub usefullness and scope and is to be used only when no alternative exists. In this case the right direction would be to make a small C module to parse boot(8) config or a shell script for 30_osprober.in to do the same job

Quoted 14 lines

Let me know if you have any questions. Once again, if you load the kernel directly and want to load modules and set kFreeBSD.foo.bar=... yourself, all that will continue to work.

Regards,
Navdeep

------------------------------------------------------------------------

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#4 lore raw

2010/4/7 Vladimir 'φ-coder/phcoder' Serbinenko <[email protected]>:

Quoted 25 lines
Quoted 17 lines · Navdeep Parhar

Hello grub-devel,

Right now it's not possible to boot using FreeBSD's loader(8) from a ZFS root filesystem.  Grub doesn't indicate to the loader that there is a ZFS root involved and consequently the loader fails to find the kernel. The attached patch fixes this.  It does not affect those that boot the kernel directly.  This is only for users that want to boot using FreeBSD's loader.

Why would you want to?  IMHO it is much simpler to boot indirectly using the loader because in that case grub does not have to deal with device.hints, kernel modules, kFreeBSD.xxx style variables, /boot/zfs/zpool.cache, etc.  As a FreeBSD user, I'm used to putting this information in the "normal" config files (/boot/loader.conf, device.hints, etc.) and not in a grub.cfg file. Grub only needs to know where the loader is, nothing else:

Quoted 7 lines

menuentry "FreeBSD 8" {
       search -s -l fbsd8
       kfreebsd -D /@/boot/zfsloader
}
(fbsd8 is the name of the ZFS root pool)

Quoted 4 lines

Eternal chainloading isn't the way to go. It limits grub usefullness and scope and is to be used only when no alternative exists. In this case the right direction would be to make a small C module to parse boot(8) config or a shell script for 30_osprober.in to do the same job

Sure, chainloading doesn't have to be the preferred way of booting an OS, but it shouldn't fail without a good reason either. Right now FreeBSD can be chainloaded from a UFS root but not from ZFS root. That's all that I'm trying to fix here. This patch doesn't imply that chainloading is *the* way to load FreeBSD - just that it is a usable alternate to direct loading, even from a ZFS root.

Regards,
Navdeep

#5 lore raw
Quoted 30 lines · Navdeep Parhar

2010/4/7 Vladimir 'φ-coder/phcoder' Serbinenko<[email protected]>:

Quoted 25 lines
Quoted 17 lines · Navdeep Parhar

Hello grub-devel,

Right now it's not possible to boot using FreeBSD's loader(8) from a ZFS root filesystem. Grub doesn't indicate to the loader that there is a ZFS root involved and consequently the loader fails to find the kernel. The attached patch fixes this. It does not affect those that boot the kernel directly. This is only for users that want to boot using FreeBSD's loader.

Why would you want to? IMHO it is much simpler to boot indirectly using the loader because in that case grub does not have to deal with device.hints, kernel modules, kFreeBSD.xxx style variables, /boot/zfs/zpool.cache, etc. As a FreeBSD user, I'm used to putting this information in the "normal" config files (/boot/loader.conf, device.hints, etc.) and not in a grub.cfg file. Grub only needs to know where the loader is, nothing else:

Quoted 7 lines

menuentry "FreeBSD 8" {
search -s -l fbsd8
kfreebsd -D /@/boot/zfsloader
}
(fbsd8 is the name of the ZFS root pool)

Quoted 4 lines

Eternal chainloading isn't the way to go. It limits grub usefullness and scope and is to be used only when no alternative exists. In this case the right direction would be to make a small C module to parse boot(8) config or a shell script for 30_osprober.in to do the same job

Quoted 6 lines

Sure, chainloading doesn't have to be the preferred way of booting an OS, but it shouldn't fail without a good reason either. Right now FreeBSD can be chainloaded from a UFS root but not from ZFS root. That's all that I'm trying to fix here. This patch doesn't imply that chainloading is *the* way to load FreeBSD - just that it is a usable alternate to direct loading, even from a ZFS root.

I've added this patch but only because since we support aout /boot/loader it makes little sense not to support zfsloader but it's not a recommended way to boot in either case.

Quoted 9 lines

Regards,
Navdeep

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko