Install FreeBSD 9.0 with ZFS root

- freebsd zfs

The “new” FreeBSD installer does not give you the options to simply install ZFS as root, so sad, here is how to do it.

Most installation recommand to install / in the zpool root, which is not always clean, for example a recursive snapshot will snapshot your swap …

#Boot cd and choose shell:

umount /dev/md1
mdmfs -s 1024M md1 /tmp

gpart destroy -F ada0

gpart create -s gpt ada0

gpart add -b 34 -s 64k -t freebsd-boot ada0
#gpart add -s 4G -t freebsd-swap -l swap0 ada0
gpart add -t freebsd-zfs -l disk0 ada0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0

zpool destroy rpool
# use -f if you already have a zpool
zpool create -f rpool /dev/gpt/disk0

zfs set checksum=fletcher4 rpool
zfs create rpool/root
zfs set mountpoint=none rpool
zfs set mountpoint=/mnt rpool/root

zfs create -o canmount=off  rpool/root/usr
zfs create  -o canmount=off rpool/root/var
zfs create -o compression=on -o exec=on -o setuid=off rpool/root/tmp
zfs create -o compression=gzip -o setuid=off  rpool/root/usr/ports
zfs create -o compression=off -o exec=off -o setuid=off rpool/root/usr/ports/distfiles
zfs create -o compression=off -o exec=off -o setuid=off rpool/root/usr/ports/packages
zfs create -o compression=gzip -o exec=off -o setuid=off  rpool/root/usr/src
zfs create -o compression=lzjb rpool/root/usr/obj
zfs create -o compression=lzjb  -o exec=off     -o setuid=off   rpool/root/var/crash
zfs create -o compression=off -o exec=off -o setuid=off   rpool/root/var/empty
zfs create -o compression=lzjb  -o exec=on -o setuid=off   rpool/root/var/tmp

zpool export rpool
zpool import -o cachefile=/tmp/zpool.cache rpool
chmod 1777 /mnt/tmp
chmod 1777 /mnt/var/tmp

cd /usr/freebsd-dist
export DESTDIR=/mnt
for file in base.txz lib32.txz kernel.txz doc.txz ports.txz src.txz;
do (cat $file | tar --unlink -xpJf - -C ${DESTDIR:-/}); done

cp /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:rpool/root"' >> /mnt/boot/loader.conf

zfs set readonly=on rpool/root/var/empty
touch /mnt/etc/fstab
zfs umount -a

zfs set mountpoint=legacy rpool/root
zfs set mountpoint=/tmp rpool/root/tmp
zfs set mountpoint=/usr rpool/root/usr
zfs set mountpoint=/var rpool/root/var
zpool set bootfs=rpool/root rpool
zfs create -V 2G rpool/swap
zfs set checksum=off rpool/swap
zfs set org.freebsd:swap=on rpool/swap


# if close to 4G of memory
#echo "vfs.zfs.prefetch_disable=0" >> /boot/loader.conf

#echo WRKDIRPREFIX=/usr/obj >> /etc/make.conf
#passwd root

This installation has been made on a Linux KVM, later blog post will follow how to enable Dtrace, virtio …