Installing FreeBSD on ZFS
Introduction
I love ZFS and for building a large NAS, I need FreeBSD which is capable of implementing ZFS and, most importantly, using it on the root partition as well.
For this purpose, I needed 5 disks of the same capacity and the FreeBSD DVD (I emphasize the DVD because the livefs or CD versions don’t contain everything needed to boot from ZFS).
Disk Formatting
Creating Partitions
Boot from the FreeBSD DVD and launch the Fixit menu.
Once inside, I recommend checking the names of the devices installed on your system:
|
|
Before creating partitions and slices, note that you can check the status of your disks at any time with:
|
|
Let’s define the disks format as GPT:
|
|
Then we’ll create a boot partition:
|
|
And a swap partition (4GB for example):
|
|
To calculate the size in cylinders, here’s the simple formula in MB with an example for our 4GB:
cylinder size = x * 4 * 512
8388608 = 4096 * 4 * 512
And finally, the data partitions where the raid-z will reside:
|
|
You should adjust according to the remaining space (see ‘gpart show’ to know how much space is left). We install the protected MBR and gptzfsboot on each disk:
|
|
Creating the ZFS
We’ll need to load the ZFS modules:
|
|
And finally we create the raidz:
|
|
Now we’ll create the necessary mount points and ZFS options to install the system. We enable checksum validation on the filesystem:
|
|
We create a partition for /tmp with some useful options:
|
|
And that’s it for the ZFS part.
Installing FreeBSD
We’ll decompress part of what’s on the DVD into our freshly created zpool:
|
|
Let’s chroot into our new environment:
|
|
And configure the rc.conf file:
|
|
And the bootloader file:
|
|
Configuration
Let’s configure the root password:
|
|
The timezone:
|
|
The mail aliases:
|
|
We unmount and exit the chroot:
|
|
And we copy the zpool cache:
|
|
We create the fstab file (/zroot/etc/fstab
):
# Device Mountpoint FStype Options Dump Pass#
/dev/gpt/swap0 none swap sw 0 0
/dev/gpt/swap1 none swap sw 0 0
/dev/gpt/swap2 none swap sw 0 0
/dev/gpt/swap3 none swap sw 0 0
/dev/gpt/swap4 none swap sw 0 0
We unmount the zpool:
|
|
And we configure the mount points of our ZFS:
|
|
All that’s left is to exit the fixit mode and the sysinstall to reboot.
FAQ
RaidZ2 degraded
What happens if you have a disk in degraded mode? First, let’s check the status to see what’s happening:
|
|
Here we can see the “DEGRADED” status. To put it simply:
- If the machine is running: replace the defective disk with a new one.
- If the machine is off or if you want to shut it down: boot from the FreeBSD DVD, load the ZFS modules.
Then recreate the partitions as you did for the other disks. Next, we’ll add the new disk to the raidz2 so it automatically rebuilds what’s needed:
|
|
Here, my disk3 was defective, so I recreated exactly the same partitions on the new disk and added it. When we do a status check, we can see that the other disks are rebuilding the new one:
|
|
Once completed, you can either reboot if you chose the solution of booting from the FreeBSD DVD, or do nothing if your machine was already running.
Resources
Last updated 21 Sep 2010, 21:23 CEST.