[UEFI/GPT] [Dual-Boot] How to install FreeBSD (with ZFS) alongside another OS (sharing the same disk)

As far as I know it's not possible to directly boot ZFS with MBR, there's simply not enough room in the master boot record. Note that a BIOS boot doesn't mean you're stuck with the MBR partitioning scheme. Many older machines will boot just fine from a GPT partitioned disk.
 
As far as I know it's not possible to directly boot ZFS with MBR, there's simply not enough room in the master boot record. Note that a BIOS boot doesn't mean you're stuck with the MBR partitioning scheme. Many older machines will boot just fine from a GPT partitioned disk.
Exactly, that's what I guessed. And if I'm not wrong, as far as there's a Windows installation already present on the disk (with a MBR partition scheme), I think I can not change the partition scheme.
 
Is it possible to make it work on a BIOS/MBR environment?
Exactly, that's what I guessed. And if I'm not wrong, as far as there's a Windows installation already present on the disk (with a MBR partition scheme), I think I can not change the partition scheme.

Hi

I had the similar problem today.
Windows installed on MBR disk.
Free space made.
I wated to install FreeBSD.
On ZFS if possible.

I read:
https://wiki.freebsd.org/RootOnZFS#Using_MBR_Disk
And then:
Installing FreeBSD Root on ZFS using UFS /boot
Installing FreeBSD Root on ZFS using FreeBSD-ZFS partition in a FreeBSD MBR Slice
and the first post from this thread.

It took me some time to understand what I am doing, a few failed tries, but I've done it finally :)

I've decided to boot from UFS and run from ZFS then.

A little howto below (explanation in the linked instructions and in the first post):

Start installer, choose the "Shell" option in "Partitiong", and then:

create partitions

in my case:

# gpart add -s 1G -t freebsd-ufs da0s3
# gpart add -s 16G -t freebsd-swap da0s3
# gpart add -t freebsd-zfs da0s3


and the result is:

% gpart show da0
=> 32 488212768 da0 MBR (233G)
32 2016 - free - (1.0M)
2048 204800 1 ntfs [active] (100M)
206848 125622272 2 ntfs (60G)
125829120 362383680 3 freebsd (173G)

% gpart show da0s3
=> 0 362383680 da0s3 BSD (173G)
0 2097152 1 freebsd-ufs (1.0G)
2097152 33554432 2 freebsd-swap (16G)
35651584 326732096 4 freebsd-zfs (156G)


add bootcode

# gpart bootcode -b /boot/boot ad0s3

load required ZFS modules

# kldload opensolaris.ko
# kldload zfs.ko


now, like in the first post

Create your zroot pool:
# zpool create -f -o altroot=/mnt -O compress=lz4 -O atime=off -m none zroot /dev/da0s3d

Create ZFS file system hierarchy:
# zfs create -o mountpoint=none zroot/ROOT
# zfs create -o mountpoint=/ zroot/ROOT/default


Define the default ZFS datasets for root zpool:
# zfs create -o mountpoint=/tmp -o exec=on -o setuid=off zroot/tmp
# zfs create -o mountpoint=/usr -o canmount=off zroot/usr
# zfs create zroot/usr/home
# zfs create -o setuid=off zroot/usr/ports
# zfs create zroot/usr/src
# zfs create -o mountpoint=/var -o canmount=off zroot/var
# zfs create -o exec=off -o setuid=off zroot/var/audit
# zfs create -o exec=off -o setuid=off zroot/var/crash
# zfs create -o exec=off -o setuid=off zroot/var/log
# zfs create -o atime=on zroot/var/mail
# zfs create -o setuid=off zroot/var/tmp


Create a symlink to /usr/home:
# ln -s /usr/home /mnt/home

Change /tmp and /var/tmp permissions:
# chmod 1777 /mnt/tmp
# chmod 1777 /mnt/var/tmp


Configure the Boot Environment:
# zpool set bootfs=zroot/ROOT/default zroot

add partition for boot data

# mkdir /mnt/bootdir
# newfs /dev/da0s3a
# mount /dev/da0s3a /mnt/bootdir
# mkdir /mnt/bootdir/boot
# cd /mnt
# ln -s bootdir/boot /mnt/boot
# chflags -h sunlink /mnt/boot


modify configuration files

# echo 'zfs_enable="YES"' > /tmp/bsdinstall_etc/rc.conf
# echo 'zfs_load="YES"' > /tmp/bsdinstall_boot/loader.conf
# echo 'vfs.root.mountfrom="zfs:zroot/ROOT/default"' >> /tmp/bsdinstall_boot/loader.conf


and add to /tmp/bsdinstall_etc/fstab

Code:
# Device                       Mountpoint              FStype  Options         Dump    Pass#
/dev/ad0s3a                    /bootdir                ufs     rw              0       0
/dev/ad0s3b                    none                    swap    sw              0       0

Type exit and continue system install.

After restart I made:

# gpart set -a active -i 1 da0

Next restart, Windows Server 2008 R2 started, and I added FreeBSD to Windows Boot Manager:

Dual Booting – Booting FreeBSD using Windows Boot Manager

I hope I didn't forget anything...

Regards,
Marcin
 
I'm so sorry to necro, but I think this may greatly help anyone coming here from google. The setup from the OP does not appear compatible with boot environments, at least not from the loader menu. Maybe it either wasn't a goal or something has changed since, but I fixed it by changing:
Code:
zfs create -o mountpoint=/ zroot/ROOT/default
to
Code:
zfs create -o mountpoint=none zroot/ROOT/default
mount -t zfs zroot/ROOT/default /mnt
as per https://wiki.freebsd.org/RootOnZFS/GPTZFSBoot

I assumed that the datasets were exactly like a vanilla ZFS install, but that doesn't seem to be the case at this time. It took me about five hours of chasing leads to figure this out. I'm a ZFS novice, so I may be missing something obvious here.
 
And I upgraded to 14 on two different laptops, and the upgrade (using freebsd-update) went perfectly. I've praised your various howtos all over this forum, and so I add my thanks, once again.
 


zfs create -o mountpoint=none zroot/ROOT/default

jmxg has a good eye.

none is proper.

See the Boot environment structures section of bectl(8) at <https://man.freebsd.org/cgi/man.cgi?query=bectl&sektion=8&manpath=FreeBSD+15.0-CURRENT>.


kevans clarified at comment 4.



Incidentally:

 
Fab, many thanks, tried with 14.1 and worked like a dream until the final efibootmgr command which said

efibootmgr: efi variables not supported on the system. kdload efirt?

but efirt was already loaded. The result is that it didn't offer freebsd as a boot option and went straight into Debian grub menu. On that system, upgate-grub didn't find FreeBSD when running os-prober. Any suggestions?

Thanks again for a great guide

M
 
You get the same error if the system was BIOS/CSM booted. In order to use efibootmgr(8) the system MUST be UEFI booted.

Check sysctl machdep.bootmethod
 
Great guide, thanks, worked out-of-the-box with an existing (complicated) Debian partition scheme and a FreeBSD 14-2 Prerelease! Maybe one could add, that before installation the space needs to be completely unallocated and not only formatted unused as e.g. gparted in linux can do..
 
Back
Top