Installing FreeBSD Root on ZFS using GPT

1. Manually Installing FreeBSD on ZFS

This guide assumes you want to manually creating the pool, to change default settings, or to not use the entire disk. If you just want to setup ZFS on the entire disk, use the 'ZFS' option in the bsdinstall partitioning menu.

  1. Boot FreeBSD install DVD or USB Memstick
  2. Select Install, and answer questions such as keyboard layout and hostname
  3. When prompted to partition the disk:
    1. If you do not want to use the entire disk, skip to the Partition Creation section.

    2. choose the 'shell' option.
      • In this mode you are expected to create a root file system mounted under /mnt that the installer will install the operating system into.
    3. Determine which disk you wish to use:
       camcontrol devlist

      <TOSHIBA HDWN180 GX2M> at scbus7 target 0 lun 0 (ada0,pass1)

      SATA disks usually start with ada followed by a number. SAS and USB disks start with da followed by a number. The rest of this page assumes the disk is ada0; replace it with your disk device's name in all commands below.
    4. Create a fresh partition table:
       gpart destroy ada0
       gpart create -s gpt ada0

    This will erase all data on the disk!

    1. Create the bootcode partition:
      1. for UEFI Boot:
         gpart add -a 4k -s 260M -t efi ada0
         # Create a FAT32 partition
         newfs_msdos -F 32 -c 1 /dev/ada0p1
         mount -t msdosfs -o longnames /dev/ada0p1 /mnt
         mkdir -p /mnt/EFI/BOOT
         cp /boot/loader.efi /mnt/EFI/BOOT/BOOTX64.efi
         umount /mnt
      2. for Legacy Boot:
         gpart add -a 4k -s 512K -t freebsd-boot ada0
         gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0

2. Create Partitions

Add some partitions for FreeBSD to use: a freebsd-swap partition and a freebsd-zfs partition.

Note: While a ZFS Swap Volume can be used instead of the freebsd-swap partition, it is not recommended, and crash dumps can't be saved to the ZFS Swap Volume.

3. Create the Pool

  1. Find the device for the freebsd-zfs partition created above
     gpart show -p ada0

    => 40 15628053088 ada0 GPT (7.3T)

    • 40 1024 ada0p1 freebsd-boot (512K)
    • 1064 984 - free - (492K) 2048 4194304 ada0p2 freebsd-swap (2.0G)
    • 4196352 15623856776 ada0p3 freebsd-zfs (7.3T)
  2. Mount a tmpfs to /mnt
     mount -t tmpfs tmpfs /mnt
  3. Create the ZFS Pool
     zpool create -o altroot=/mnt zroot ada0p3

    Note: zroot is the name of the ZFS Pool; it could be anything, e.g. tank, data, mypool, ...

4. Create the ZFS file system hierarchy

  • The lz4 compression algorithm is fast enough to be used by default, even for incompressible data.

     zfs set compress=on                                            zroot
    Create a Boot Environment hierarchy
     zfs create -o mountpoint=none                                  zroot/ROOT
     zfs create -o mountpoint=none                                  zroot/ROOT/default
     mount -t zfs zroot/ROOT/default /mnt
    Create the rest of the filesystems.
     zfs create -o mountpoint=/tmp  -o exec=on      -o setuid=off   zroot/tmp
     zfs create -o canmount=off -o mountpoint=/usr                  zroot/usr
     zfs create                                                     zroot/usr/home
     zfs create                     -o exec=off     -o setuid=off   zroot/usr/src
     zfs create                                                     zroot/usr/obj
     zfs create -o mountpoint=/usr/ports            -o setuid=off   zroot/usr/ports
     zfs create                     -o exec=off     -o setuid=off   zroot/usr/ports/distfiles
     zfs create                     -o exec=off     -o setuid=off   zroot/usr/ports/packages
     zfs create -o canmount=off -o mountpoint=/var                  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         -o exec=off     -o setuid=off   zroot/var/mail
     zfs create                     -o exec=on      -o setuid=off   zroot/var/tmp
    Links and Permissions
     ln -s /usr/home /mnt/home
     chmod 1777 /mnt/var/tmp
     chmod 1777 /mnt/tmp

5. Configure Boot Environment

6. Finish install

  1. Create /tmp/bsdinstall_etc/fstab
     cat << EOF > /tmp/bsdinstall_etc/fstab
     # Device                       Mountpoint              FStype  Options         Dump    Pass#
     /dev/gpt/swap0                 none                    swap    sw              0       0
  2. Exit Shell Partitioning mode, bsdinstall will continue and complete the installation.
  3. In the post installation step, when asked if you would like to drop into the installed system, choose yes and run the following two commands.
     sysrc zfs_enable="YES"
     echo 'zfs_load="YES"' >> /boot/loader.conf


RootOnZFS/GPTZFSBoot (last edited 2023-05-05T14:12:04+0000 by RebeccaCran)