====== Installing FreeBSD Root on ZFS using FreeBSD-ZFS partition in a FreeBSD MBR Slice ======
===== Creating a bootable ZFS Filesystem =====
- Boot %%FreeBSD%% install DVD or USB Memstick
- Choose Fixit option in sysinstall
- Create MBR disk \\ \\
If you are installing on an New drive, you will need to create the MBR geometry first:
Fixit# gpart create -s mbr ad0
- Create Slice using gpart\\ \\
This example already has two slices defined on the drive.
Fixit# gpart show ad0
=> 63 625142385 ad0 MBR (289G)
63 209712447 1 !7 (100G)
209712510 417690 2 !136 (204M)
210130200 415012248 - free - (198G)
Create a third slice - gpart will use all the remaining space by default. Then create a BSD partition table on the new slice.
Fixit# gpart add -t freebsd ad0
ad0s3 added
Fixit# gpart create -s BSD ad0s3
ad0s3 created
And examine the result:
Fixit# gpart show ad0
=> 63 625142385 ad0 MBR (289G)
63 209712447 1 !7 (100G)
209712510 417690 2 !136 (204M)
210130200 415012248 3 freebsd (198G)
**Note:**
Sizes and offsets are specified in sectors by default (1 sector is typically 512 bytes) but can have an 'M' and 'G' suffix to use MB or GB.
- Set partition active (Optional)\\ \\
Some BIOSes might require setting a Slice active. Here we set partition 1 (the Windows Partiton) as the active partition.
Fixit# gpart set -a active -i 1 ad0
- Create partitions (ad0s3a and ad0s3b)\\ \\
Note that partition order is important. It seems that zfsboot requires the freebsd-zfs partition to be the first, so make sure you add if first, before your swap partition.
Fixit# gpart show ad0s3
=> 0 415012248 ad0s3 BSD (198G)
0 415012248 ad0s3 - free - (198G)
Fixit# gpart add -s 194G -t freebsd-zfs ad0s3
ad0s3a added
Fixit# gpart show ad0s3
=> 0 415012248 ad0s3 BSD (198G)
406631421 1 freebsd-zfs (194G)
406631421 8380827 - free - (4.0G)
Fixit# gpart add -t freebsd-swap ad0s3
ad0s3b added
Fixit# gpart show ad0s3
=> 0 415012248 ad0s3 BSD (198G)
0 406631421 1 freebsd-zfs (194G)
406631421 8380827 2 freebsd-swap (4.0G)
**Note:**
- While a [[/RootOnZFS#ZFS_Swap_Volume|ZFS Swap Volume]] can be used instead of the freebsd-swap partition, crash dumps can't be created on the ZFS Swap Volume.
- Sizes and offsets are specified in sectors by default (1 sector is typically 512 bytes) but can have an 'M' or 'G' suffix to use MB or GB.
- Load ZFS kernel module
Fixit# kldload /mnt2/boot/kernel/opensolaris.ko
Fixit# kldload /mnt2/boot/kernel/zfs.ko
- Create ZFS Pool zroot
Fixit# mkdir /boot/zfs
Fixit# zpool create zroot /dev/ad0s3a
Fixit# zpool set bootfs=zroot zroot
**Note:**
zroot is the name of the ZFS Pool, it could be anything (i.e. tank, data, ...)
- Install boot Manager
Fixit# gpart bootcode -b /mnt2/boot/boot0 ad0
ad0 has bootcode
It's ok if you get an "unknown class" message here, but it you get "failed to install" or the like, you'll need to try again after making sure that nothing is mounted from /dev/ad0.
- Install ZFS boot\\ \\
Export zroot, before installing boot code
Fixit# zpool export zroot
Install the boot1 stage:
Fixit# dd if=/mnt2/boot/zfsboot of=/tmp/zfsboot1 count=1
Fixit# gpart bootcode -b /tmp/zfsboot1 /dev/ad0s3
This may fail with an "operation not permitted" error message, since the kernel likes to protect critical parts of the disk. If this happens for you, run:
Fixit# sysctl kern.geom.debugflags=0x10
Install the boot2 zfs stage into the convienient hole in the ZFS filesystem on-disk format which is located just after the ZFS metadata (this is the seek=1024).
Fixit# dd if=/mnt2/boot/zfsboot of=/dev/ad0s3a skip=1 seek=1024
Import zroot to continue the install
Fixit# zpool import zroot
===== Installing FreeBSD to the ZFS filesystem =====
{{page>RootOnZFS/InstallingFreeBSD&nofooter&noeditbtn}}
===== Finish install =====
- Create /etc/fstab
Fixit# cat << EOF > /zroot/etc/fstab
# Device Mountpoint FStype Options Dump Pass#
/dev/ad0s3b none swap sw 0 0
EOF
- export LD_LIBRARY_PATH
Fixit# export LD_LIBRARY_PATH=/mnt2/lib
- Unmount all zfs filesystems
Fixit# zfs unmount -a
- Change mount points for zroot pool
Fixit# zfs set mountpoint=legacy zroot
Fixit# zfs set mountpoint=/tmp zroot/tmp
Fixit# zfs set mountpoint=/usr zroot/usr
Fixit# zfs set mountpoint=/var zroot/var
- Exit Fixit mode, and then sysinstall. Remove the %%FreeBSD%% install DVD/Memstick and the system will boot using the ZFS root.