This is an old revision of the document!


Installing FreeBSD 9 Root on ZFS with less fuss

WIP! DO NOT USE.

Based the 9.0-REL page.

gpart create -s gpt mfid0
  1. Add initial partitions for boot loader and swap, and install the protective MBR and gptzfsboot boot loader. It is possible to have swap partitions on zfs pools, but this might lead to deadlocks in low memory situations. Making the boot loader partition 122 blocks in size ensures that the following partitions will be suitably aligned on a ^2 boundary.
gpart add -b 34 -s 256 -t freebsd-boot mfid0
gpart add -b 512 -s 8G -t freebsd-swap -l sys-swap0 mfid0
gpart add -t freebsd-zfs -l sys-zfs0 mfid0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 mfid0
  1. Load the necessary kernel modules
kldload zfs
  1. 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
  1. Create ZFS filesystem hierarchy

ZFS apparently requires zroot/usr if I want zroot/usr/local

zfs 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/var
zfs create			zroot/var/log
zfs create -o setuid=off	zroot/var/tmp
chmod 1777 /mnt/var/tmp /mnt/tmp
tar -C /mnt -xf /usr/freebsd-dist/base.txz
tar -C /mnt -xf /usr/freebsd-dist/games.txz 
tar -C /mnt -xf /usr/freebsd-dist/kernel.txz 
tar -C /mnt -xf /usr/freebsd-dist/lib32.txz 

tar -C /mnt -xf /usr/freebsd-dist/src.txz 
  1. 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
zfs unmount -a
zpool export zroot
zpool import -o cachefile=/tmp/zpool.cache -o altroot=/mnt zroot
  1. 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
  1. Add swap devices to fstab, so that they will automatically show up when the system starts.
cat << EOF > /mnt/etc/fstab
# Device			Mountpoint		FStype	Options		Dump	Pass#
/dev/gpt/sys-swap		none			swap	sw		0	0
EOF
  • rootonzfs/light.1353768064.txt.gz
  • Last modified: 2012/11/24 14:41
  • by SimonNielsen