FreeBSD on a bootable ZFS mirror • 28 Dec 2011

This is a decription of how I install FreeBSD on a server machine with two or more harddisks, using ZFS, and without swap. I distilled this method from a variety of sources on the Web. It's nothing new or unique; I just document it for myself here.

Typographical ornament

Power on the server and boot from an USB stick. For this example, I used a FreeBSD-9.0-REL-amd64 USB stick. When the installer comes up, select 'Shell' to drop into a shell.

I like to start with clean disks. If you're unsure, wipe them first (it won't hurt):

dd if=/dev/zero of=/dev/ada0 bs=1m count=1 dd if=/dev/zero of=/dev/ada1 bs=1m count=1

Then, partition the disks:

gpart create -s gpt ada0 gpart create -s gpt ada1 gpart add -b 34 -s 94 -t freebsd-boot ada0 gpart add -b 34 -s 94 -t freebsd-boot ada1 gpart add -t freebsd-zfs ada0 gpart add -t freebsd-zfs ada1 gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0 gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1 # You could even initialize more disks, like ada2, ada3 etc...

Create a zpool with the mirror, and set some options:

zpool create -f -o altroot=/mnt -o cachefile=/var/tmp/zpool.cache \ zroot mirror ada0p2 ada1p2 # For hot spares, you could append to the above command: spare ada2p2 ada3p2 zpool set bootfs=zroot zroot zfs set checksum=fletcher4 zroot zfs set atime=off zroot

Install FreeBSD:

chmod 0177 /mnt cd /mnt ; ln -s usr/home home sh cd /usr/freebsd-dist for file in base.txz lib32.txz kernel.txz doc.txz; do (cat $file | tar --unlink -xpJf - -C /mnt); done

Note: if you install a 32-bit architecture, you don't need lib32.txz. Include src.txz if you want the kernel source code. You also might want to include ports.txz to install the ports tree, however, I prefer 'portsnap fetch && portsnap extract' after installation, to get really up-to-date ports.

Finishing up:

cp /var/tmp/zpool.cache /mnt/boot/zfs/zpool.cache echo 'zfs_enable="yes"' >>/mnt/etc/rc.conf echo 'zfs_load="yes"' >>/mnt/boot/loader.conf echo 'vfs.root.mountfrom="zfs:zroot"' >>/mnt/boot/loader.conf touch /mnt/etc/fstab

Now you can reboot. Don't forget to add a root password with 'passwd'.


andy • 26 Oct 2012

works perfectly, thanks a lot !!!

Michiel • 6 Sep 2014

The FreeBSD installer nowadays offers this out of the box. No need for above procedure anymore!

Leave a comment

name (required)

content last edited on June 13, 2012, 14:15 - rendered in 2.02 msec