Root On ZFS @ FreeBSD 9

6a00e54fc8012e88330105365f1554970c-350wi

The new bsdInstaller is here but unfortunately as we saw it still doesn’t support a full ZFS installation. Also, due to the new layout of the installer the traditional way of installing from <FIXIT> doesn’t work anymore. The installation files are now located under /usr/freebsd-dist and the new “Live CD” option doesn’t create any kind of live fs. Therefore we have to improvise.

For the purpose of this demonstration am using a 9-Current that I created on April 29th. Boot with your 9-Current and choose “Lice CD” when prompted.

UPDATE:   You can see a newer version here !

The first thing we need to do is to make /tmp writable so that we can store the zpool.cache file.

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

That should be enough. Now,  lets partition our drive. I will be using a GPT scheme and create a native swap partition of 4 GB Ram, the rest will be allocated to ZFS. This guide installs FreeBSD on a single disk but this could be easily reproduced for a mirror or a raidz1 pool.

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

My disk is now ready so I will create a pool and call it zroot and then mount it under /mnt. During this procedure some error messages will appear “can not mount, failed to create mount point”. The reason for those is that /mnt is read only but you can safely ignore them since we will export and import back our pool.

zpool create zroot /dev/gpt/disk0
zpool set bootfs=zroot zroot
zfs set checksum=fletcher4 zroot

Now lets create the file system layout. You can safely ignore the error messages about mounting  again since the pool hasn’t been exported/imported yet.

zfs set mountpoint=/mnt zroot
zfs create zroot/usr
zfs create zroot/usr/home
zfs create zroot/var
zfs create -o compression=on -o exec=on -o setuid=off zroot/tmp
zfs create -o compression=lzjb -o setuid=off zroot/usr/ports
zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/distfiles
zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/packages
zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/usr/src
zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/var/crash
zfs create -o exec=off -o setuid=off zroot/var/db
zfs create -o compression=lzjb -o exec=on -o setuid=off zroot/var/db/pkg
zfs create -o exec=off -o setuid=off zroot/var/empty
zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/var/log
zfs create -o compression=gzip -o exec=off -o setuid=off zroot/var/mail
zfs create -o exec=off -o setuid=off zroot/var/run
zfs create -o compression=lzjb -o exec=on -o setuid=off zroot/var/tmp

Now at this point I will export the pool, import back while preserving the zpool.cache in /tmp

zpool export zroot
zpool import -o cachefile=/tmp/zpool.cache zroot

The pool is now mounted under /mnt and we can now proceed with the final steps.

chmod 1777 /mnt/tmp
cd /mnt ; ln -s usr/home home
chmod 1777 /mnt/var/tmp

Next we need to install FreeBSD. Like I said things have changed therefore the procedure is different. This guide assumes that you also want to install source and ports. For a minimal installation only base.txz lib32.txz kernel.txz are necessary.

sh
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

Now let’s save the zpool.cache

cp /tmp/zpool.cache /mnt/boot/zfs/zpool.cache

Done! Now, all that is left is to create the rc.conf, loader.conf and fstab.

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
cat << EOF > /mnt/etc/fstab
# Device Mountpoint FStype Options Dump Pass#
/dev/gpt/swap0 none swap sw 0 0
EOF

Final steps

zfs set readonly=on zroot/var/empty
zfs umount -a

If you get a device busy message try umount -f /mnt

zfs set mountpoint=legacy zroot
zfs set mountpoint=/tmp zroot/tmp
zfs set mountpoint=/usr zroot/usr
zfs set mountpoint=/var zroot/var

Reboot, adjust time zone info, add a password for root, add a user and enjoy!!!

For an automated installation see Olaf Klein comment !

Powered by BareBSD
 

34 Responses

  1. Rick says:

    Thank you. This works perfectly for me with RC3. And thank you Olaf, your script also works great. One question; is there a way to use this with PCBSD 9? According to Kris Moore with PC-BSD we only need the PCBSD.tbz from the cd but everytime I extract it right after the freebsd *.txz install, I get an error stating it can not unlink rpc. Do you have any tips or ideas?

    Thanks,
    Rick

    • gkontos says:

      Hi Rick,

      Unfortunately I don’t have any experience with PC-BSD. I was under the impression though that the installer gives you the option to perform a ZFS install.

Leave a Reply

*


*