Installing FreeBSD Root on ZFS using GPT¶
Manually Installing FreeBSD on ZFS¶
camcontrol devlist
gpart destroy ada0
gpart create -s gpt ada0
gpart add -a 4k -s 800K -t efi -l efi0 ada0
gpart add -a 4k -s 512K -t freebsd-boot -l boot0 ada0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 ada0
gpart bootcode -p /boot/boot1.efifat -i 1 ada0
create efiboot
newfs_msdos -F16 /dev/ada0p1
mount -t msdosfs /dev/ada0p1 /mnt
mkdir -p /mnt/efi/boot
cp /boot/loader.efi /mnt/efi/boot/bootx64.efi
mkdir -p /mnt/efi/freebsd
cp /boot/loader.efi /mnt/efi/freebsd/loader.efi
umount /mnt
file -s /dev/ada0p1 /dev/ada0p1
/dev/ada0p1: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "BSD4.4 ", sectors/cluster 32, root entries 512, sectors/FAT 65, sectors/track 63, heads 16, sectors 532480 (volumes > 32 MB), serial number 0x9cc41c01, unlabeled, FAT (16 bit)
/dev/ada0p1: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "BSD4.4 ", sectors/cluster 32, root entries 512, sectors/FAT 65, sectors/track 63, heads 16, sectors 532480 (volumes > 32 MB), serial number 0x3875130e, unlabeled, FAT (16 bit)
Create Partitions¶
gpart add -a 1m -s 4G -t freebsd-swap -l swap0 ada0
gpart add -a 1m -t freebsd-zfs -l z0disk0 ada0
Create the Pool¶
gpart show -p ada0
mount -t tmpfs tmpfs /mnt
zpool create -o altroot=/mnt zroot /dev/gpt/z0disk0
# The lz4 compression algorithm is fast enough to be used by default, even for uncompressible data.
zfs set compress=on zroot
# Create a Boot Environment hierarchy
zfs create -o mountpoint=none zroot/ROOT
zfs create -o mountpoint=/ -o canmount=noauto zroot/ROOT/default
mount -t zfs zroot/ROOT/default /mnt
Create the rest of the filesystems.¶
zfs create -o mountpoint=/tmp -o exec=on -o setuid=off zroot/tmp zfs create -o canmount=off -o mountpoint=/usr zroot/usr zfs create zroot/usr/home zfs create -o exec=off -o setuid=off zroot/usr/src zfs create zroot/usr/obj zfs create -o mountpoint=/usr/ports -o setuid=off zroot/usr/ports zfs create -o exec=off -o setuid=off zroot/usr/ports/distfiles zfs create -o exec=off -o setuid=off zroot/usr/ports/packages zfs create -o canmount=off -o mountpoint=/var 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 -o atime=on -o exec=off -o setuid=off zroot/var/mail zfs create -o exec=on -o setuid=off zroot/var/tmp
Links and Permissions¶
ln -s /usr/home /mnt/home chmod 1777 /mnt/var/tmp chmod 1777 /mnt/tmp
Configure Boot Environment¶
zpool set bootfs=zroot/ROOT/default zroot
Finish install¶
cat << EOF > /zroot/etc/fstab # Device Mountpoint FStype Options Dump Pass# /dev/gpt/swap0 none swap sw 0 0 EOF sysrc zfs_enable="YES" echo zfs_load="YES" >> /boot/loader.conf