ZFS About exporting ZFS pool and hostid

I have recently finished setting up a dual boot of Gentoo Linux and FreeBSD 12.1-RELEASE on my old laptop. Both systems are installed on a ZFS pool named zroot, with the zroot/linux/gentoo volume holding the root of the Gentoo installation, and zroot holding the FreeBSD root.

After rebooting from FreeBSD into Gentoo, I reach a point in the boot process where Linux's initramfs attempts to import the zpool zroot, and after several seconds I receive at least a hundred lines with this error message:
Code:
!! zroot/linux/gentoo is not a filesystem
(this comes from one of the kernel parameters passed to Linux: root=ZFS=zroot/linux/gentoo

Upon entering the rescue shell for my initramfs, I tried running zpool import -R /mnt zroot and was met with this:
Code:
cannot import 'zroot': pool was previously in use from another system
Last accessed by <hostname> (hostid=67518724) at <date>
The pool can be imported, use 'zpool import -f' to import the pool.

The only way to fix this is to forcefully import the pool with zpool import -R /mnt -f zroot, export it with zpool export zroot, and reboot the system. Next time Linux tries to load the zpool, it succeeds and boots my system.
It's important to note that rebooting from Linux back into Linux works. I even tested this with my USB installation of Arch Linux: I booted Arch from the USB, imported the zroot zpool, and re-booted; I was able to boot back into Gentoo and go back and forth as much as I wanted without errors.

From my limited understanding, the hostid is set when a pool is imported to prevent another system from importing the pool and trying to concurrently modify data, and the hostid is reset when the pool is exported. A system may define its hostid in /etc/hostid, and at least on Linux, this variable gets baked into the initramfs. I do not have a hostid set on Gentoo.

What's happening here? It seems as if ZFS on FreeBSD is not resetting hostid on the pool, whereas OpenZFS on Linux is?
Do I need to define a hostid for Gentoo, either through a kernel parameter or /etc/hostid & my initramfs?
Or am I missing something else entirely?

I'm using FreeBSD 12.1-RELEASE. Both Gentoo Linux and Arch Linux are using openZFS 0.8.3.
 
I have recently finished setting up a dual boot of Gentoo Linux and FreeBSD 12.1-RELEASE on my old laptop. Both systems are installed on a ZFS pool named zroot

1. Don't do that.
2. I share a 4 TB mirror between FreeBSD and Gentoo. The pool must be created by FreeBSD and not upgraded while running Linux. When switching from one OS to the other you must export the pool before rebooting and then import the pool into the other system.
3. Don't try to boot two different OS's from one pool. Who owns the pool?! If you boot into Linux on that pool then obviously the pool thinks it is owned by Linux. It can't be accessed by FreeBSD without first exporting it from Linux. But you can't export it while running Linux because it is being used!
4. So don't do that!

EDIT: I have an ssd for gentoo, an ssd for freebsd, and 10 TB of storage on 4 enterprise hard drives, so it's easy to follow my own advice of not trying to put two OS on one zpool (and not messing about trying to fool the pool into thinking the two OS have the same hostid). If I wanted my data on zfs with a single drive I would put gentoo on one partition using xfs filesystem, freebsd on another partition using ufs, and the data pool on a third partition using zfs. But really if I had to live with a single disk I would choose either freebsd or gentoo (probably gentoo if the system is fast). Multi-booting introduces so much potential for human error that the data on zfs is probably less secure than it would be in either OS alone.
 
Back
Top