====== Installing FreeBSD Root on ZFS (RAIDZ1) 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
Fixit# gpart create -s gpt ad2
- Create the boot, swap and zfs partitions
Create 3 partitions on drives ad0, ad1 and ad2. 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 128k -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 128k -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
Fixit# gpart add -b 34 -s 128k -t freebsd-boot ad2
Fixit# gpart add -s 4G -t freebsd-swap -l swap2 ad2
Fixit# gpart add -s 60G -t freebsd-zfs -l disk2 ad2
**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 (1 sector is typically 512 bytes) but can also be specified in MB or GB by adding an 'M' or 'G' suffix.
- 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
Fixit# gpart bootcode -b /mnt2/boot/pmbr -p /mnt2/boot/gptzfsboot -i 1 ad2
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 raidz1 /dev/gpt/disk0 /dev/gpt/disk1 /dev/gpt/disk2
Fixit# zpool set bootfs=zroot zroot
**Note:**
- zroot is the name of the ZFS Pool, it could be anything (i.e. tank, data, ...)
- A raidz1 pool requires a minimum of 3 disks and a maximum of 9 disks
===== 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/gpt/swap0 none swap sw 0 0
/dev/gpt/swap1 none swap sw 0 0
/dev/gpt/swap2 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.