Installing FreeBSD 9 Root on ZFS with less fuss
WIP! DO NOT USE UNLESS YOU KNOW WHAT YOU ARE DOING.
Based the 9.0-REL page.
Creating a bootable ZFS filesystem
export DISK=mfid0 /etc/rc.d/tmp start dd if=/dev/zero of=/dev/$DISK bs=1m count=10 gpart create -s gpt $DISK gpart add -b 34 -s 256 -t freebsd-boot $DISK gpart add -b 512 -s 32G -t freebsd-swap -l sys-swap0 $DISK gpart add -t freebsd-zfs -l sys-zfs0 $DISK gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $DISK
kldload zfs
- Create the zfs pool.
Replace mirror as needed, and add all disks that should be part of the pool.
zpool create -o altroot=/mnt zroot /dev/gpt/sys-zfs0
Installing FreeBSD to the ZFS file system
Create ZFS filesystem hierarchy
ZFS apparently requires zroot/usr if I want zroot/usr/localzfs create -o setuid=off zroot/tmp zfs create zroot/usr zfs create zroot/usr/local zfs create -o setuid=off zroot/home zfs create -o compression=lzjb -o setuid=off zroot/usr/ports zfs create -o compression=off -o setuid=off zroot/usr/ports/distfiles zfs create -o compression=lzjb -o setuid=off zroot/usr/src zfs create zroot/usr/obj zfs create zroot/var zfs create zroot/var/log zfs create -o setuid=off zroot/var/tmp chmod 1777 /mnt/var/tmp /mnt/tmp
export DIST=/usr/freebsd-dist tar -C /mnt -xf ${DIST}/base.txz tar -C /mnt -xf ${DIST}/games.txz tar -C /mnt -xf ${DIST}/kernel.txz tar -C /mnt -xf ${DIST}/lib32.txz tar -C /mnt -xf ${DIST}/src.txz
Finishing touches
- Fix zpool cachefile, to be able to boot from the new pool. Enable ZFS in the startup configuration to mount zfs filesystems on startup.
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 mkdir /mnt/etc cat << EOF > /mnt/etc/fstab # Device Mountpoint FStype Options Dump Pass# /dev/gpt/sys-swap0 none swap sw 0 0 EOF echo -h > /mnt/boot.config echo 'console="comconsole"' >> /mnt/boot/loader.conf echo 'beastie_disable="YES"' >> /mnt/boot/loader.conf sed -i "" -e '/tty[du]0/s/off/on/' -e '/tty[du]0/s/dialup/vt100/' /mnt/etc/ttys echo 'comconsole_speed="115200"' >> /mnt/boot/loader.conf zfs unmount -a zpool export zroot zpool import -o cachefile=/tmp/zpool.cache -o altroot=/mnt zroot
- Set mountpoints
zfs set mountpoint=/ zroot cp /tmp/zpool.cache /mnt/boot/zfs/ zfs unmount -a zpool set bootfs=zroot zroot zpool set cachefile='' zroot zfs set mountpoint=legacy zroot zfs set mountpoint=/tmp zroot/tmp zfs set mountpoint=/usr zroot/usr zfs set mountpoint=/var zroot/var zfs set mountpoint=/home zroot/home
UFS
gpart add -s 2G -t freebsd-ufs -l sys-root0 $DISK gpart add -s 2G -t freebsd-ufs -l sys-root1 $DISK gpart add -s 15G -t freebsd-ufs -l sys-var $DISK gpart add -s 15G -t freebsd-ufs -l sys-usr $DISK gpart add -t freebsd-ufs -l sys-local0 $DISK gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 $DISK newfs /dev/gpt/sys-root0 newfs -U /dev/gpt/sys-var newfs -U /dev/gpt/sys-usr newfs -U /dev/gpt/sys-local0 mount /dev/gpt/sys-root0 /mnt mkdir /mnt/usr /mnt/var /mnt/local0 mount /dev/gpt/sys-var /mnt/var mount /dev/gpt/sys-usr /mnt/usr mount /dev/gpt/sys-local0 /mnt/local0/