Support #765
Install FreeBSD With ZFS Root The Hard Way
Description
This is a guide on how I manually setup FreeBSD with a ZFS root on a GPT formatted hard drive, without the help of a GUI or bsdinstall. This guide is intended to install FreeBSD using the installation DVD and will work offline.
- When the FreeBSD Installer Welcome message appears, choose Shell.
- Get a list of available drives:
camcontrol devlist
- Create the GPT slices:
gpart create -s gpt ada0
- Then create the boot slice:
gpart add -b 40 -s 512K -t freebsd-boot -a 4k -l boot0 ada0
- Create the swap slice:
gpart add -s 4G -t freebsd-swap -a 4k -l swap0 ada0
- Then create the root ZFS slice:
gpart add -t freebsd-zfs -a 4k -l disk0 ada0
- Then create the boot slice:
- Create ZFS pool using the GPT disk labeled
disk0
, then export it:zpool create -o altroot=/mnt -o cachefile=/tmp/zpool.cache -m / -f rpool /dev/gpt/disk0 zpool export rpool
- Next import the ZFS pool using
/mnt
as the alternate root create the root dataset and settings:zpool import -o altroot=/mnt -o cachefile=/tmp/zpool.cache rpool zpool set bootfs=rpool rpool zfs set checksum=fletcher4 rpool zfs set atime=off rpool zfs create rpool/root
- Then create some additional system datasets:
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
- Then create some additional system datasets:
- Set the permissions of the temp directories in the zfs mount:
chmod 1777 /mnt/tmp chmod 1777 /mnt/var/tmp
- Extract the base.txz and kernel.txz to the zfs root to install the base system:
cat /usr/freebsd-dist/base.txz | tar --unlink -xpJf - -C /mnt cat /usr/freebsd-dist/kernel.txz | tar --unlink -xpJf - -C /mnt
- Add the initial system configuration:
echo 'zfs_enable="YES"' >> /mnt/etc/rc.conf echo 'sshd_enable="YES"' >> /mnt/etc/rc.conf touch /mnt/etc/fstab
- And setup networking using DHCP:
echo 'ifconfig_em0="DHCP"' >> /mnt/etc/rc.conf echo 'hostname="freebsd.example.com"' >> /mnt/etc/rc.conf
- (Optional) Setup networking using a static IP address instead:
echo 'ifconfig_em0="inet 192.168.10.70 netmask 255.255.255.0 broadcast 198.100.10.255"' >> /mnt/etc/rc.conf echo 'defaultrouter="192.168.10.1"' >> /mnt/etc/rc.conf echo 'hostname="freebsd.example.com"' >> /mnt/etc/rc.conf echo 'nameserver 192.168.10.1' >> /mnt/etc/resolv.conf
- And setup networking using DHCP:
- Install the bootcode and set the boot partion to active:
gpart bootcode -b /mnt/boot/pmbr -p /mnt/boot/gptzfsboot -i 1 ada0 gpart set -a bootme -i 1 ada0
- Add the bootloader config:
echo 'zfs_load="YES"' >> /mnt/boot/loader.conf echo 'if_em_load="YES"' >> /mnt/boot/loader.conf echo 'vfs.root.mountfrom="zfs:rpool"' >> /mnt/boot/loader.conf
- Copy the working zpool.cache file to the rpool:
cp /tmp/zpool.cache /mnt/boot/zfs/zpool.cache
- Unmount the zpool:
zpool export rpool
- Reboot the system and eject the FreeBSD install disc:
reboot
Resources¶
- https://forums.freebsd.org/threads/42773/
- https://wiki.freebsd.org/RootOnZFS/GPTZFSBoot/9.0-RELEASE
- https://calomel.org/zfs_freebsd_root_install.html
- http://daemon-notes.com/articles/system/install-zfs/gpart
- http://daemon-notes.com/articles/system/install-zfs/zfs
- http://daemon-notes.com/articles/system/install-zfs/finish