====== Installing FreeBSD Root on ZFS (Mirror) using GPT ====== ===== Creating a bootable ZFS Filesystem ===== - Boot %%FreeBSD%% install DVD or USB Memstick - Choose Fixit option in sysinstall - Create GPT Disks Fixit# gpart create -s gpt ad0 Fixit# gpart create -s gpt ad1 - Create the boot, swap and zfs partitions Create 3 partitions on both drives ad0 and ad1. The first partition contains the gptzfsboot loader which is able to recognize and load the loader from a [[/ZFS]] partition. The second partition is a 4 GB swap partition. The third partition is the partition containing the zpool (60GB). Fixit# gpart add -b 34 -s 512k -t freebsd-boot ad0 Fixit# gpart add -s 4G -t freebsd-swap -l swap0 ad0 Fixit# gpart add -s 60G -t freebsd-zfs -l disk0 ad0 Fixit# gpart add -b 34 -s 512k -t freebsd-boot ad1 Fixit# gpart add -s 4G -t freebsd-swap -l swap1 ad1 Fixit# gpart add -s 60G -t freebsd-zfs -l disk1 ad1 **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 'M' or 'G' suffixes for MB and GB. - Install the Protective MBR (pmbr) and gptzfsboot loader to both drives Fixit# gpart bootcode -b /mnt2/boot/pmbr -p /mnt2/boot/gptzfsboot -i 1 ad0 Fixit# gpart bootcode -b /mnt2/boot/pmbr -p /mnt2/boot/gptzfsboot -i 1 ad1 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 - 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 mirror /dev/gpt/disk0 /dev/gpt/disk1 Fixit# zpool set bootfs=zroot zroot **Note:** zroot is the name of the ZFS Pool, it could be anything (i.e. tank, data,...) ===== Installing FreeBSD to the ZFS filesystem ===== {{page>RootOnZFS/InstallingFreeBSD&nofooter&noeditbtn}} ===== Finish install ===== - Using swap \\ \\ There are 2 ways to use the gpt/swap0 and gpt/swap1 partitions \\ \\ - Create /etc/fstab to use both swap partitions Fixit# cat << EOF > /zroot/etc/fstab # Device Mountpoint FStype Options Dump Pass# /dev/gpt/swap0 none swap sw 0 0 /dev/gpt/swap1 none swap sw 0 0 EOF - Use gmirror to mirror the swap partitions \\ \\ - Load gmirror kernel module Fixit# kldload /mnt2/boot/kernel/geom_mirror.ko - Create the gmirror swap Fixit# gmirror label -b prefer swap gpt/swap0 gpt/swap1 **Note:** The 'prefer' balance algorithm can be replaced by 'round-robin'. See the gmirror(8) man page about problem using the 'round-robin' balance algorithm and kernel dumps \\ \\ - Create /etc/fstab to use the gmirror swap partition Fixit# cat << EOF > /zroot/etc/fstab # Device Mountpoint FStype Options Dump Pass# /dev/mirror/swap none swap sw 0 0 EOF - Add gmirror to /boot/loader.conf Fixit# echo 'geom_mirror_load="YES"' >> /zroot/boot/loader.conf - 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 sysinstall. Remove the %%FreeBSD%% install DVD/Memstick and the system will boot using the ZFS root.