How to‎ > ‎

Install FreeBSD on ZFS filesystem

FreeBSD sysinstal utility does not support at this time installation to ZFS file systems on GPT-style partitioned disks.
Here is a small guide showing how to install FreeBSD 8.1 on A ZFS-only system, including the root volume. I used the name 'data' for my ZFS pool. On this example I used a single disk configuration.

The first thing is to start a shell on the system where the target disk is attached. I used the FreeBSD bootable DVD, using the 'Fixit Shell'. On my configuration, the disk is attached to a SCSI controller, so the disk is identified by 'da0'. When installing to an ATA disk, it may be named 'ad0' or 'ada0', depending on your configuration.

Create GPT partitions

Fixit# gpart create -s GPT da0
Fixit# gpart add -b 34 -s 128 -t freebsd-boot da0
Fixit# gpart add -s 4G -t freebsd-swap da0
Fixit# gpart add -t freebsd-zfs da0

The disk must be made bootable, i need to install the boot loader on the partition with index 1
Fixit# gpart bootcode -b /dist/boot/pmbr -p /dist/boot/gptzfsboot -i 1 da0
 

Create ZFS pool on the third partition

Fixit# zpool create data /dev/da0p3

After creating partitions, it's time to begin working on ZFS pool and volumes

Load ZFS kernel modules

Fixit# kldload /dist/boot/kernel/opensolaris.ko
Fixit# kldload /dist/boot/kernel/zfs.ko
 
ZFS supports compression for file systems. When compression is active, there will be some latency while reading or writing to these filesystems, depending on the algorithm used. If you change this setting, it will take effect for the files written AFTER change.

Create ZFS filesystems

Fixit# zfs create -o compression=on -o exec=on -o setuid=off data/tmp
Fixit# chmod 1777 /data/tmp
Fixit# zfs create data/usr
Fixit# zfs create data/usr/home
Fixit# cd /data; ln -s /usr/home home
Fixit# zfs create -o compression=lzjb -o setuid=off data/usr/ports
Fixit# zfs create -o compression=off -o exec=off -o setuid=off data/usr/ports/distfiles
Fixit# zfs create -o compression=off -o exec=off -o setuid=off data/usr/ports/packages
Fixit# zfs create -o compression=lzjb -o exec=off -o setuid=off data/usr/src
Fixit# zfs create data/var
Fixit# zfs create -o compression=lzjb -o exec=off -o setuid=off data/var/crash
Fixit# zfs create -o exec=off -o setuid=off data/var/db
Fixit# zfs create -o compression=lzjb -o exec=on -o setuid=off data/var/db/pkg
Fixit# zfs create -o exec=off -o setuid=off data/var/empty

Fixit# zfs create -o compression=lzjb -o exec=off -o setuid=off data/var/log
Fixit# zfs create -o compression=gzip -o exec=off -o setuid=off data/var/mail
Fixit# zfs create -o exec=off -o setuid=off data/var/run
Fixit# zfs create -o compression=lzjb -o exec=on -o setuid=off data/var/tmp
Fixit# chmod 1777 /data/var/tmp

Instruct the boot loader to load the required modules and where to look for the root volume
 

Instruct the boot loader to load the required modules and where to look for the root volume

Fixit# echo 'zfs_load="YES"' >> /data/boot/loader.conf
Fixit# echo 'vfs.root.mountfrom="zfs:data"' >> /data/boot/loader.conf
 

Create /etc/fstab and the initial system configuration

Fixit# echo '/dev/da0p2 none swap sw 0 0' >> /data/etc/fstab
Fixit# echo 'zfs_enable="YES"' >> /etc/rc.conf
Fixit# echo 'zfs_enable="YES"' > /data/etc/rc.conf
Fixit# echo 'hostname="myhostname.local"' >> /data/etc/rc.conf
Fixit# echo 'ifconfig_em0="DHCP"' >> /data/etc/rc.conf
 

Create /boot/zfs/zpool.cache, this is required when booting from ZFS

Fixit# mkdir /boot/zfs
Fixit# zpool export data; zpool import data
Fixit# cp /boot/zfs/zpool.cache /data/boot/zfs
 
Set the mount points for ZFS filesystems. Because /usr filesystem will be remounted, it's needed to instruct the linker where to find libraries
Fixit# export LD_LIBRARY_PATH=/dist/lib
 
The / filesystem will be mounted automatically at boot time. The other filesystems won't need explicit entries in /etc/fstab if the ZFS mountpoint option is set, otherwise they must be listed in /etc/fstab and zfs mountpoint set to 'legacy' for these filesystems.
Fixit# zfs set mountpoint=legacy data
Fixit# zfs set mountpoint=/tmp data/tmp
Fixit# zfs set mountpoint=/usr data/usr
Fixit# zfs set mountpoint=/var data/var
 
Remove the DVD (or USB key), reboot the system.

Post-installation tasks: root password, aliases, time zone

hostname# passwd root
hostname# tzsetup
hostname# cd /etc/mail; make aliases

The others settings can be adjusted as usual, by using sysinstall or by hand.
 
Comments