Installing FreeBSD 9.0 with Root on ZFS

Why this post?

I hadn’t administered ZFS for a few years, and had never used it as the root filesystem before.  FreeBSD 9.0 no longer uses sysinstall, it uses bsdinstall.  The bsdinstall based instructions don’t work.

What’s wrong?  bsdinstall seems to re-mount the ZFS filesystem on /.  This breaks ZFS and the installation never completes.

Steps

1. Boot FreeBSD install DVD.

2. Begin installation; select keyboard and hostname, then drop out to the shell at the first opportunity.

3. Partition your disks.  I’m using 3 disks configured as RAIDZ1.

# gpart create -s gpt ada0
# gpart create -s gpt ada1
# gpart create -s gpt ada2
# gpart add -s 64K -t freebsd-boot -l boot0 ada0
# gpart add -s 64K -t freebsd-boot -l boot1 ada1
# gpart add -s 64K -t freebsd-boot -l boot2 ada2
# gpart add -s 8G -t freebsd-swap -l swap0 ada0
# gpart add -s 8G -t freebsd-swap -l swap1 ada1
# gpart add -s 8G -t freebsd-swap -l swap2 ada2
# gpart add -t freebsd-zfs -l disk0 ada0
# gpart add -t freebsd-zfs -l disk1 ada1
# gpart add -t freebsd-zfs -l disk2 ada2

4. Install the Protected MBR (pmbr) and gptzfsboot loader.

# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0
# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1
# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada2

5. Create the ZFS filesystem

# zpool create -o altroot=/mnt zroot raidz /dev/gpt/disk0 /dev/gpt/disk1 /dev/gpt/disk2
# zfs create zroot/usr
# zfs create zroot/home
# zfs create zroot/var
# zfs create zroot/var/tmp
# zfs create zroot/tmp
# chmod 1777 /mnt/tmp
# chmod 1777 /mnt/var/tmp

6. Perform the Installation, this is the full set but you clearly don’t want them all.

# cd /usr/freebsd-dist/
# tar –unlink -xpJf base.txz -C /mnt
# tar –unlink -xpJf kernel.txz -C /mnt
# tar –unlink -xpJf ports.txz -C /mnt
# tar –unlink -xpJf doc.txz -C /mnt
# tar –unlink -xpJf src.txz -C /mnt
# tar –unlink -xpJf games.txz -C /mnt

7. Fixup /etc/

# cat /tmp/bsdinstall_etc/rc.conf.hostname /tmp/bsdinstall_etc/rc.conf.keymap > /mnt/etc/rc.conf
# echo ‘zfs_enable=”YES”‘ >> /mnt/etc/rc.conf
# echo ‘ifconfig_en0=”DHCP”‘ >> /mnt/etc/rc.conf
#
# echo ‘zfs_load=”YES”‘ >> /mnt/boot/loader.conf
# echo ‘vfs.root.mountfrom=”zfs:zroot”‘ >> /mnt/boot/loader.conf
#
# chroot /mnt
# passwd
# tzsetup
# exit

From here on, if ZFS fails to initialize, type reboot to reboot the system, follow steps 1 and 2, then continue where you left off.

8. Complete the ZFS setup.

# zfs umount -a
# zpool export zroot
#
# zpool import -o cachefile=/tmp/zpool.cache zroot
# cp /tmp/zpool.cache /mnt/boot/zfs/zpool.cache
# zfs umount -a
#
# zfs set mountpoint=/ zroot
# reboot

Further Comments

Clearly the ZFS filesystem can be tuned further.  My first reference shows a reasonable configuration.  I am using raidz, so the number of copies can be set to 2 for permanent mount points.

References

Installing FreeBSD Root on ZFS (RAIDZ1) using GPT

Installing FreeBSD 9.0-RELEASE Root on ZFS using GPT

ZFS fails with bsdinstaller 9.0RC3

Advertisements

~ by kbw333 on August 28, 2012.

One Response to “Installing FreeBSD 9.0 with Root on ZFS”

  1. […] am running a FreeBSD system with a ZFS root filesystem.  This was described in a previous post, here.  I suspected the one of the drives is faulty and hoped this would prove a useful test for […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: