Installing FreeBSD Root on ZFS using a FreeBSD MBR Slice¶
- Creating a bootable ZFS Filesystem
Boot FreeBSD install DVD or USB Memstick
Choose Fixit option in sysinstall
Create MBR/GPT disk
If you are installing on an New drive, you will need to create the MBR geometry first:
# gpart create -s mbr ada0 gpart destroy ada0 gpart create -s gpt ada0
Create Slice using gpart
This example already has two slices defined on the drive.
gpart show ad0 => 63 625142385 ad0 MBR (289G) 63 209712447 1 !7 (100G) 209712510 417690 2 !136 (204M) 210130200 415012248 - free - (198G)
Create a third slice then create a BSD partition table on the new slice.
gpart add -t freebsd ad0 ad0s3 added
And examine the result:
gpart show ad0 => 63 625142385 ad0 MBR (289G) 63 209712447 1 !7 (100G) 209712510 417690 2 !136 (204M) 210130200 415012248 3 freebsd (198G)
Sizes and offsets are specified in sectors (1 sector is typically 512 bytes) but can also be specified in MB or GB by adding an 'M' or 'G' suffix.
Set partition active (Optional)
Some BIOSes might require setting a Slice active. Here we set partition 1 (the Windows Partiton) as the active partition.
gpart set -a active -i 1 ad0
Load ZFS kernel module
kldload /mnt2/boot/kernel/opensolaris.ko kldload /mnt2/boot/kernel/zfs.ko
Create ZFS Pool zroot
mkdir /boot/zfs zpool create zroot /dev/ad0s3 zpool set bootfs=zroot zroot
NOTE: zroot is the name of the ZFS Pool, it could be anything (i.e. tank, data, ...)
Create ZFS Swap volume
zfs create -V 2gb zroot/swap zfs set org.freebsd:swap=on zroot/swap zfs set checksum=off zroot/swap
Install boot Manager
#gpart bootcode -b /mnt2/boot/boot0 ad0 #ad0 has bootcode gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0
It's ok if you get an "unknown class" message here, but it you get "failed to install" or the like, you'll need to try again after making sure that nothing is mounted from /dev/ad0.
Install ZFS boot
- Export zroot, before installing boot code
zpool export zroot
- Install the boot1 stage:
dd if=/mnt2/boot/zfsboot of=/dev/ad0s3 count=1
This may fail with an "operation not permitted" error message, since the kernel likes to protect critical parts of the disk. If this happens for you, run:
sysctl kern.geom.debugflags=0x10
- Install the boot2 zfs stage into the convienient hole in the ZFS filesystem on-disk format which is located just after the ZFS metadata (this is the seek=1024).
dd if=/mnt2/boot/zfsboot of=/dev/ad0s3 skip=1 seek=1024
- Import zroot to continue the install
zpool import zroot
- Installing FreeBSD to the ZFS filesystem
Create ZFS filesystem hierarchy
The fletcher4 algorithm should be more robust than the fletcher2 algorithm.
zfs set checksum=fletcher4 zroot zfs create -o compression=on -o exec=on -o setuid=off zroot/tmp chmod 1777 /zroot/tmp zfs create zroot/usr zfs create zroot/usr/home cd /zroot ; ln -s /usr/home home zfs create -o compression=lzjb -o setuid=off zroot/usr/ports zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/distfiles zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/packages
Note:
If you use nullfs or nfs to mount /usr/ports to different locations/servers, you will also need to nullfs/nfs mount /usr/ports/distfiles and/or /usr/ports/packages.
zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/usr/src zfs create zroot/var zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/var/crash zfs create -o exec=off -o setuid=off zroot/var/db zfs create -o compression=lzjb -o exec=on -o setuid=off zroot/var/db/pkg zfs create -o exec=off -o setuid=off zroot/var/empty zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/var/log zfs create -o compression=gzip -o exec=off -o setuid=off zroot/var/mail zfs create -o exec=off -o setuid=off zroot/var/run zfs create -o compression=lzjb -o exec=on -o setuid=off zroot/var/tmp chmod 1777 /zroot/var/tmp
Note:
Compression may be set to on, off, lzjb, gzip, gzip-N (where N is an integer from 1 (fastest) to 9 (best compression ratio. gzip is equivalent to gzip-6).
Compression will cause some latency when accessing files on the ZFS filesystems. Use compression on ZFS filesystems which will not be accessed that often.
Install FreeBSD to zroot
cd /dist/8.0-* export DESTDIR=/zroot for dir in base catpages dict doc games info lib32 manpages ports; \ do (cd $dir ; ./install.sh) ; done cd src ; ./install.sh all cd ../kernels ; ./install.sh generic cd /zroot/boot ; cp -Rlp GENERIC/* /zroot/boot/kernel/
Make /var/empty readonly
zfs set readonly=on zroot/var/empty chroot into /zroot chroot /zroot
Create /etc/rc.conf
echo 'zfs_enable="YES"' > /etc/rc.conf echo 'hostname="beastie.mydomain.local"' >> /etc/rc.conf echo 'ifconfig_re0="DHCP"' >> /etc/rc.conf
Note:
Replace re0 with the name of the Network interface for the new system
Create /boot/loader.conf
echo 'zfs_load="YES"' > /boot/loader.conf echo 'vfs.root.mountfrom="zfs:zroot"' >> /boot/loader.conf
Change root's password
passwd
Set the local time zone
tzsetup
Create /etc/mail/aliases.db
cd /etc/mail make aliases
Exit from the /zroot
umount /dev exit
Install zpool.cache to the ZFS filesystem
cp /boot/zfs/zpool.cache /zroot/boot/zfs/zpool.cache
- Finish install
Create /etc/fstab
cat << EOF > /zroot/etc/fstab # Device Mountpoint FStype Options Dump Pass# EOF export LD_LIBRARY_PATH export LD_LIBRARY_PATH=/mnt2/lib Unmount all zfs filesystems zfs unmount -a
Change mount points for zroot pool
zfs set mountpoint=legacy zroot zfs set mountpoint=/tmp zroot/tmp zfs set mountpoint=/usr zroot/usr zfs set mountpoint=/var zroot/var
Exit Fixit mode, and then sysinstall. Remove the FreeBSD install DVD/Memstick and the system will boot using the ZFS root.