Installing FreeBSD 9.x Root on ZFS using VTOC8 (sparc)

This article covers installing FreeBSD 9.x with the root file system on ZFS with bsdinstall.

Creating a bootable ZFS filesystem

Note: This walkthrough assumes that a zfs mirror of two disks is created, but the instructions work equally well for a single disk or a raidz or raidz2 setup, just replace 'mirror' as needed in the examples.

  1. Boot the FreeBSD install CD/DVD.
  2. Go through the initial setup as usual.
  3. When the partitioning dialogue in bsdinstall comes up, choose the 'Shell' option.
  4. Create new VTOC8 partitioned disks, repeat this for all disks.
     # sysctl kern.disks
    kern.disks: cd0 da0 da1
     # gpart destroy -F da0
     da0 destroyed
     # gpart destroy -F da1
     da1 destroyed
     # gpart create -s VTOC8 da0
     da0 created
     # gpart create -s VTOC8 da1
     da1 created
  5. Add partitions for the zfs pools and swap. This example creates a 292GB partition for the ZFS, adapt to your case.
     # gpart add -s 292G -t freebsd-zfs da0
     da0a added
     # gpart add -t freebsd-swap da0
     da0b added
  6. Now duplicate this layout for each additional disk:
     # gpart add -s 292G -t freebsd-zfs da1
     da1a added
     # gpart add -t freebsd-swap da1
     da1b added
  7. Create the zfs pool.

Replace the 'mirror' keyword as needed, and list all disks that should be part of the pool.

This will create a zpool called 'zroot' which will not be automatically mounted. The canmount property is also set to off, to avoid mounting this by accident. This zpool is only used to derive other file systems from. Now install the boot-loader on these partitions:

  1. Installing boot-loader.
     # zpool export zroot
     # gpart bootcode -p /boot/zfsboot da0
     # gpart bootcode -p /boot/zfsboot da1
     # sysctl kern.geom.debugflags=0x10
     kern.geom.debugflags: 0 -> 16
     # dd if=/boot/zfsloader of=/dev/da0a bs=512 oseek=1024 conv=notrunc,sync
     465+1 records in
     466+0 records out
     238592 bytes transferred in 0.244906 secs (974219 bytes/sec)
     # dd if=/boot/zfsloader of=/dev/da1a bs=512 oseek=1024 conv=notrunc,sync
     465+1 records in
     466+0 records out
     238592 bytes transferred in 0.244906 secs (974219 bytes/sec)
     # zpool import -o altroot=/mnt zroot

Installing FreeBSD to the ZFS file system

  1. Create ZFS file system hierarchy.

    The fletcher4 algorithm should be more robust than the fletcher2 algorithm.

     # zfs set checksum=fletcher4                                   zroot
     # zfs set atime=off                                            zroot
     # zfs create -o mountpoint=/                                   zroot/ROOT

    You can fine-tune and create other zfs pool: check other guide for more detailed examples.

  2. Set booting property to this zpool
     # zpool set bootfs=zroot/ROOT zroot
  3. Add the swap devices to fstab, so that they will automatically show up when the system starts.
     # cat << EOF > /tmp/bsdinstall_etc/fstab
     # Device                       Mountpoint              FStype  Options         Dump    Pass#
     /dev/da0b                      none                    swap    sw              0       0
     /dev/da1b                      none                    swap    sw              0       0
  4. Once all of the zfs file systems have been created, type 'exit' in the shell and proceed with the installation as normal.
  5. Once the installation is complete choose 'Exit' from the main menu.
  6. The next dialogue will offer the option to 'open a shell in the new system', choose this option.
  7. Configure zfs to load and mount the file systems automatically at boot.
     # echo 'zfs_enable="YES"' >> /etc/rc.conf
     # echo 'zfs_load="YES"' >> /boot/loader.conf
  8. Update the zpool cache file.
     # zpool set cachefile=/boot/zfs/zpool.cache   zroot
     # exit
  9. To finish the installation, choose the reboot option from the dialogue, do not forget to remove the installation media from the computer.

RootOnZFS/VTOC8ZFSBoot/9.x-RELEASE (last edited 2013-09-13T15:58:26+0000 by OlivierCochardLabbé)