======================================= FreeBSD zfs custom installation ======================================= A working example of how to custom install FreeBSD by hand - zfs two disk zpool mirror - mirrored swap - mirrored msdosfs efiboot ======================================= work in a shell --------------------------------------- Boot from a FreeBSD installer image and enter a shell # get a FreeBSD install image from here if you need to prepare something to boot from https://download.freebsd.org/ftp/releases/ISO-IMAGES/ ======================================= set up networking in the shell --------------------------------------- # check interface names ifconfig ifconfig em1 192.168.10.10/24 up route add default 192.168.10.1 cat << EOF > /etc/resolv.conf search domain.foo nameserver 9.9.9.9 EOF # test it ping download.freebsd.org ======================================= set up some elbow room to work --------------------------------------- mount -t tmpfs tmpfs /mnt ======================================= download FreeBSD files for a different release than the booted installer if necessary --------------------------------------- mkdir /mnt/download # base and kernel are the only essential files fetch -v -o /mnt/download https://download.freebsd.org/ftp/releases/amd64/14.1-RELEASE/base.txz fetch -v -o /mnt/download https://download.freebsd.org/ftp/releases/amd64/14.1-RELEASE/kernel.txz # optional components are # base-dbg # kernel-dbg # lib32-dbg # lib32 # ports # src # tests ======================================= partition the disks --------------------------------------- # camcontrol rescan all <--- warning: might cause a rash. if so then start with all disks attached instead. # camcontrol rescan 0 # check disk device names and look for a unique identifier or use the disk slot for the labels camcontrol devlist diskinfo -v da0 diskinfo -v da1 ls -l /dev/da* gpart show -l # destroy previous partitions if necessary gpart destroy -F da0 gpart destroy -F da1 # partition disks gpart create -s GPT da0 gpart create -s GPT da1 # create efi partition gpart add -t efi -l efi_s0 -b 40 -a 4K -s 256M da0 gpart add -t efi -l efi_s1 -b 40 -a 4K -s 256M da1 # create freebsd-boot partition gpart add -t freebsd-boot -l freebsd-boot_s0 -a 4K -s 512K da0 gpart add -t freebsd-boot -l freebsd-boot_s1 -a 4K -s 512K da1 gpart add -t freebsd-swap -l freebsd-swap_s0 -a 4K -s 4G da0 gpart add -t freebsd-swap -l freebsd-swap_s1 -a 4K -s 4G da1 gpart add -t freebsd-zfs -l freebsd-zfs_s0 -a 4K da0 gpart add -t freebsd-zfs -l freebsd-zfs_s1 -a 4K da1 # have a look gpart show -l gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 da0 gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 da1 ======================================= create zpool zroot --------------------------------------- # clear zpool labels if disks were ever used in a zpool zdb -l da0 zpool labelclear -f da0 zpool labelclear -f da0p3 zpool labelclear -f da0p4 zpool labelclear -f da1 zpool labelclear -f da1p3 zpool labelclear -f da1p4 zpool create \ -O compression=zstd -O checksum=sha512 -O atime=on \ -o autoexpand=off -o autoreplace=on -o failmode=continue -o listsnaps=off \ -o altroot=/mnt/zroot -m none -f zroot mirror da0p4 da1p4 # have a look zpool status zpool list -v zfs list ======================================= create the rest of zfs zroot --------------------------------------- zfs create -o mountpoint=none zroot/ROOT zfs create -o mountpoint=/ zroot/ROOT/default zfs create -o mountpoint=/tmp -o exec=on -o setuid=off zroot/tmp zfs create -o mountpoint=/usr -o canmount=off zroot/usr zfs create zroot/usr/home zfs create -o mountpoint=/var -o canmount=off zroot/var zfs create -o exec=off -o setuid=off zroot/var/audit zfs create -o exec=off -o setuid=off zroot/var/crash zfs create -o exec=off -o setuid=off zroot/var/log zfs create zroot/var/mail zfs create -o setuid=off zroot/var/tmp ======================================= extract FreeBSD essential files (others are optional) --------------------------------------- # to install the FreeBSD version from the booted installer tar xCf /mnt/zroot /usr/freebsd-dist/base.txz tar xCf /mnt/zroot /usr/freebsd-dist/kernel.txz # to install the FreeBSD version from the earlier fetch download tar xCf /mnt/zroot /mnt/download/base.txz tar xCf /mnt/zroot /mnt/download/kernel.txz ======================================= touch up zroot and make it bootable --------------------------------------- zfs set mountpoint=/zroot zroot zpool set bootfs=zroot/ROOT/default zroot zpool set cachefile=/mnt/zroot/boot/zfs/zpool.cache zroot zfs set canmount=noauto zroot/ROOT/default # have a look zfs get -r -t filesystem mountpoint zfs get -r -t filesystem canmount zfs list ======================================= set root password --------------------------------------- pw -R /mnt/zroot usershow -n root pw -R /mnt/zroot usermod -n root -h 0 pw -R /mnt/zroot usershow -n root ======================================= create users /usr/home --------------------------------------- zfs create zroot/usr/home/oeng pw -R /mnt/zroot groupadd -g 16401 -n oeng pw -R /mnt/zroot useradd -n oeng -c "Owen Eng" -g oeng -s /bin/sh -u 16401 -G wheel -m -h 0 pw -R /mnt/zroot usershow -n oeng mkdir /mnt/zroot/home/oeng/.ssh chmod 0700 /mnt/zroot/home/oeng chmod 0700 /mnt/zroot/home/oeng/.ssh chown -R 16401:16401 /mnt/zroot/home/oeng ======================================= setup gmirror to work in this shell --------------------------------------- kldload geom_mirror kldstat | grep geom_mirror gmirror status # destroy any previous gmirror metadata if necessary gmirror destroy -f swap gmirror destroy -f efiboot ======================================= setup gmirror for swap --------------------------------------- gmirror label -v -b prefer -F swap da0p3 da1p3 gmirror status ======================================= setup gmirror for efiboot --------------------------------------- gmirror label -v efiboot da0p1 da1p1 gmirror status mkdir /mnt/efiboot newfs_msdos /dev/mirror/efiboot mount_msdosfs /dev/mirror/efiboot /mnt/efiboot mkdir -p /mnt/efiboot/efi/boot cp /boot/loader.efi /mnt/efiboot/efi/boot/bootx64.efi umount /mnt/efiboot ======================================= setup /etc/fstab --------------------------------------- cat << EOF > /mnt/zroot/etc/fstab # Device Mountpoint FStype Options Dump Pass# /dev/mirror/efiboot /boot/efi msdosfs rw 2 2 /dev/mirror/swap none swap sw 0 0 EOF ======================================= setup /boot/loader.conf --------------------------------------- cat << EOF > /mnt/zroot/boot/loader.conf geom_mirror_load="YES" kern.geom.label.disk_ident.enable="0" kern.geom.label.gptid.enable="0" cryptodev_load="YES" zfs_load="YES" EOF ======================================= setup /etc/rc.conf --------------------------------------- cat << EOF > /mnt/zroot/etc/rc.conf clear_tmp_enable="YES" hostname="sumo" ifconfig_em0="inet 192.168.10.10 netmask 255.255.255.0" defaultrouter="192.168.10.1" sshd_enable="YES" # Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable dumpdev="AUTO" zfs_enable="YES" # sendmail enable outgoing only sendmail_enable="NO" # ntp ntpdate_enable="YES" ntpd_enable="YES" ntpd_sync_on_start="YES" ntpd_oomprotect="YES" EOF ======================================= setup /etc/resolv.conf --------------------------------------- cat << EOF > /mnt/zroot/etc/resolv.conf search domain.foo nameserver 9.9.9.9 EOF ======================================= create /etc/localtime if you do not want your local timezone to be UTC --------------------------------------- # find your timezone ls -lR /usr/share/zoneinfo cp -p /usr/share/zoneinfo/Canada/Eastern /mnt/zroot/etc/localtime ======================================= reboot --------------------------------------- # remove the installer image and reboot shutdown -p now ======================================= enjoy a refreshing beverage! =======================================