Installing FreeBSD Root on ZFS using GPT
Contents
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.
- Boot FreeBSD install DVD or USB Memstick
- Select Install, and answer questions such as keyboard layout and hostname
- When prompted to partition the disk:
If you do not want to use the entire disk, skip to the Partition Creation section.
- 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.
- Determine which disk you wish to use:
camcontrol devlist
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.<TOSHIBA HDWN180 GX2M> at scbus7 target 0 lun 0 (ada0,pass1)
- Create a fresh partition table:
gpart destroy ada0 gpart create -s gpt ada0
This will erase all data on the disk!
- Create the bootcode partition:
- 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
- for Legacy Boot:
gpart add -a 4k -s 512K -t freebsd-boot ada0 gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0
- for UEFI Boot:
2. Create Partitions
Add some partitions for FreeBSD to use: a freebsd-swap partition and a freebsd-zfs partition.
-a <number>: controls alignment.
-s <size>: sets the size of the partition; if not set, it will default to the remaining space on the disk.
-l <name> sets the label for the partition.
- Create the swap and zfs partitions
gpart add -a 1m -s 4G -t freebsd-swap -l swap0 ada0 gpart add -a 1m -t freebsd-zfs -l disk0 ada0
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
- 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)
- Mount a tmpfs to /mnt
mount -t tmpfs tmpfs /mnt
- 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 hierarchyzfs 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 Permissionsln -s /usr/home /mnt/home chmod 1777 /mnt/var/tmp chmod 1777 /mnt/tmp
5. Configure Boot Environment
zpool set bootfs=zroot/ROOT/default zroot
6. Finish install
- 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 EOF
- Exit Shell Partitioning mode, bsdinstall will continue and complete the installation.
exit
- 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