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

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 10,893
Messages: 36,805

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.
 

Kalero

Active Member

Reaction score: 9
Messages: 106

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.
 

marcinkk

Member

Reaction score: 5
Messages: 32

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
 
Top