Install FreeBSD 11 on ZFS mirror (GPT or MBR)

Table of Contents

Begin installation
Partition the drives (GPT or MBR)
Create mirrored ZFS filesystem
Finish installation

Partition the drives (GPT or MBR)

by ross at 03:19:53 on October 25, 2016

We will create swap on ZFS and not in separate partition. This way you can change its size dynamically later.

Option 1. Partition the drives (GPT)

GPT is the best method to partition if you aren't going to dual boot.

If you have to use 4k-aligned GPT partitions please read the corresponding article. The solution is to skip -b 34 parameter here and add -a 4k to all the gpart add commands.

# gpart create -s gpt ada1
# gpart add -b 34 -s 512k -t freebsd-boot -l boot0 ada1
# gpart add -t freebsd-zfs -l system0 ada1
# gpart create -s gpt ada2
# gpart add -b 34 -s 512k -t freebsd-boot ada2
# gpart add -t freebsd-zfs -l system1 ada2

gpart will create /dev/gpt/label for each label you used. Use -s parameter to add to set the size, if ommited all the space is used.

Install boot code

# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1
# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada2

Option 2. Partition the drives (MBR)

# gpart create -s mbr ada1
# gpart add -t freebsd ada1
# gpart create -s bsd ada1s1
# gpart show ada1s1
=>        0  209715216  ada1s1  BSD  (100G)
          0  209715216          - free -  (100G)
# gpart add -s 209715215 -t freebsd-zfs ada1s1
# gpart show ada1s1
=>        0  209715216  ada1s1  BSD  (100G)
          0  209715215       1  freebsd-zfs  (100G)
  209715215          1          - free -  (512B)
# glabel label system0 /dev/ada1s1a

Here we first check created slice size (ada1s1). It is 209715216 sectors. Then we create single partition one sector less in size (209715215 sectors). This is needed to reserve the last sector for GEOM metadata (for glabel to work).

# gpart create -s mbr ada2
# gpart add -t freebsd ada2
# gpart create -s bsd ada2s1
# gpart show ada2s1
=>        0  209715216  ada2s1  BSD  (100G)
          0  209715216          - free -  (100G)
# gpart add -s 209715215 -t freebsd-zfs ada2s1
# glabel label system1 /dev/ada2s1a

Install boot code

Install simple MBR boot loader (boots active slice):
# gpart bootcode -b /boot/mbr ada1
# gpart set -a active -i 1 ada1
# gpart bootcode -b /boot/mbr ada2
# gpart set -a active -i 1 ada2

Or install FreeBSD boot manager:
# gpart bootcode -b /boot/boot0 ada1
# gpart bootcode -b /boot/boot0 ada2
# dd if=/boot/zfsboot of=/dev/ada1s1 count=1
# dd if=/boot/zfsboot of=/dev/ada1s1a skip=1 seek=1024
# dd if=/boot/zfsboot of=/dev/ada2s1 count=1
# dd if=/boot/zfsboot of=/dev/ada2s1a skip=1 seek=1024

 

Comments
There is an error in naming of drives in MBR section

Option 2. Partition the drives (MBR)
# gpart create -s mbr ada1 # --> ada1 is okay
# gpart add -t freebsd ada1 # --> ada1 is okay
# gpart create -s bsd ada2s1 # --> ada2 is NOT okay
# gpart show ada2s1 # --> ada2 is NOT okay
-- Nasko
Tuesday, October 14, 2014, 23:40:19
Corrected this part. Thank you.
-- ross
Monday, October 20, 2014, 2:23:34