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 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 disks 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 devices 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 800K -t efi ada0
         gpart bootcode -p /boot/boot1.efifat -i 1 ada0
      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. Create the ZFS Pool
     zpool create -o altroot=/mnt zroot ada0p3

    Note: zroot is the name of the ZFS Pool, it could be anything (i.e. tank, data, mypool, ...)

4. Create ZFS file system hierarchy

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

     zfs set compress=on                                            zroot
    Create a Boot Environment hierarchy
     zfs create -o mountpoint=none                                  zroot/ROOT
     zfs create -o mountpoint=/ -o canmount=noauto                  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 > /zroot/etc/fstab
     # Device                       Mountpoint              FStype  Options         Dump    Pass#
     /dev/gpt/swap0                 none                    swap    sw              0       0
     EOF
  2. Exit Shell Partitioning mode, bsdinstall will continue and complete the installation.
     exit

RootOnZFS/GPTZFSBoot (last edited 2018-07-17 02:34:57 by AllanJude)