There are plenty of guides on how to use ZFS without UFS on FreeBSD 8, but that doesn't mean I can't make one as well.
Much of this information comes from http://wiki.freebsd.org/ZFSOnRootWithZFSboot and http://blogs.freebsdish.org/lulf/2008/12/16/setting-up-a-zfs-only-system/. The specific goal of this guide is to provide a single-OS system (FreeBSD, obviously) with simple disk redundancy and no RAID hardware; this is accomplished with a "mirror" (RAID-1) zpool and also swapping to either a GEOM_MIRROR device or to a ZFS volume.
You will use the "fixit" command shell rather than sysinstall(8), so I've also provided steps for several setup tasks that sysinstall(8) would normally take care of.
The shell commands in this guide are formatted and variable-ized for easy copying/pasting. Remember that a colon at the beginning of a command line or immediately after a semicolon is considered by sh(1) to be a comment, so you can freely paste or pipe large command blocks into your fixit command shell without removing the inline comments.
disk0=ad4 disk1=ad6 zfspart=2
gpart create -s GPT $disk0 gpart create -s GPT $disk1 gpart add -s 128 -t freebsd-boot $disk0 gpart add -s 128 -t freebsd-boot $disk1
zfspart=3 ; : Since this will place swap on ${disk0}p2, respecify where ZFS will go
gpart add -s <swapsize> -t freebsd-swap $disk0
gpart add -s <swapsize> -t freebsd-swap $disk1
If you did not "load geom_mirror" at a loader prompt, load it now:
kldload /mnt2/boot/kernel/geom_mirror.koCreate the mirror:
gmirror label swap0 /dev/${disk0}p2 /dev/${disk1}p2
kldload /mnt2/boot/kernel/opensolaris.ko kldload /mnt2/boot/kernel/zfs.ko
gpart add -t freebsd-zfs $disk0 gpart add -t freebsd-zfs $disk1
gpart bootcode -b /mnt2/boot/pmbr -p /mnt2/boot/gptzfsboot -i 1 $disk0 gpart bootcode -b /mnt2/boot/pmbr -p /mnt2/boot/gptzfsboot -i 1 $disk1
export poolname=z0 ; : change as desired
zpool create ${poolname} mirror /dev/${disk0}p${zfspart} /dev/${disk1}p${zfspart}
zfs set mountpoint=none ${poolname}
zfs create -o mountpoint=/${poolname} ${poolname}/root
zpool set bootfs=${poolname}/root ${poolname}
Others may use ${poolname} as the root filesystem, but using (for example)
${poolname}/root allows you to set default properties for descendents of ${poolname} without
affecting the root filesystem's own properties.
: chmod before creating separate /tmp so it's right if /tmp isn't mounted.
: install will take care of mode on ${poolname}/tmp filesystem.
: repeat for /${poolname}/var/tmp if creating a separate filesystem for that.
mkdir /${poolname}/tmp
chmod 1777 /${poolname}/tmp
: feel free to change/add/remove options, quotas, filesystems/mountpoints, etc.
zfs create -o mountpoint=/${poolname}/tmp -o setuid=off -o compression=on ${poolname}/tmp
zfs create -o mountpoint=/${poolname}/usr ${poolname}/usr
zfs create -o mountpoint=/${poolname}/var ${poolname}/var
zfs create -o mountpoint=/${poolname}/var/crash -o exec=off -o setuid=off -o compression=on -o quota=5120M ${poolname}/crash
zfs create -o mountpoint=/${poolname}/usr/obj -o atime=off ${poolname}/obj
zfs create -o mountpoint=/${poolname}/usr/ports -o atime=off -o compression=gzip-9 ${poolname}/ports
zfs create -o mountpoint=/${poolname}/usr/src -o atime=off -o compression=on ${poolname}/src
zfs create -o mountpoint=/${poolname}/usr/local ${poolname}/usrlocal
zfs create -o mountpoint=/${poolname}/usr/local/homes ${poolname}/homes
: etc...
zfs create -V <swapsize> ${poolname}/swap
zfs set org.freebsd:swap=on ${poolname}/swap
zfs set checksum=off ${poolname}/swap
(cd /;ln -s mnt2/rescue) if you want
to use mount -t cd9660 ....)
sh -V or sh -E as
desired) to make for an easy environment cleanup after the next steps.
cd /dist/<OSVersion> (DVD) or
cd /mnt/<OSVersion> (two CDs or CD+NFS, "disc1"
mounted under /mnt)
export DESTDIR=/${poolname}
for a in base *pages; do
(cd $a && ./install.sh)
done
install.sh will prompt you to overwrite any installation in /${poolname}.
Make sure it warns you about the right directory—if not, something
went wrong with the "export" line above.Continue installation with OS source and the GENERIC kernel.
(cd src && ./install.sh all)
(cd kernels && ./install.sh generic)
cd /${poolname}/boot
rmdir kernel
mv GENERIC kernel
exit
: /etc/src.conf
: THIS IS A MUST-HAVE!
echo 'LOADER_ZFS_SUPPORT=true' > /${poolname}/etc/src.conf
: add other entries as desired. edit etc/make.conf if needed.
: --------------------
: /boot/loader.conf
cat << EOH > /${poolname}/boot/loader.conf
# skip/delete/comment out next line if swapping to zvol:
geom_mirror_load=YES
zfs_load=YES
vfs.root.mountfrom="zfs:${poolname}/root"
# if "sysctl vm.kmem_size" is very different from size of physical RAM,
# set it to size of physical RAM
#vm.kmem_size=8G
# add anything else you know you'll need/want
EOH
: --------------------
: /etc/fstab
: uncomment swap entry if you followed step 4; zvol swap is activated
: automatically and so does not need an fstab entry
cat << EOH > /${poolname}/etc/fstab
# Device Mountpoint FStype Options Dump Pass#
proc /proc procfs rw 0 0
#/dev/mirror/swap0 none swap sw 0 0
# uncomment after installing Linux ports
#linprocfs /compat/linux/proc linprocfs rw,late 0 0
EOH
: --------------------
: /etc/rc.conf
cat << EOH > /${poolname}/etc/rc.conf
zfs_enable=YES
# fill in values as desired
hostname=
ifconfig_xxxX=
defaultrouter=
# $dumpdev is now "NO" by default!
#dumpdev=/dev/mirror/swap0
#sshd_enable=YES
#ntpdate_enable=YES
#ntpdate_flags=-b
#ntpd_enable=YES
# etc...
EOH
: /etc/resolv.conf
cat << EOH > /${poolname}/etc/resolv.conf
nameserver x.y.z.w
search example.com example.org
EOH
cp /${poolname}/usr/share/zoneinfo/<YourTimeZone> /${poolname}/etc/localtime
: uncomment next line if system clock is not set to UTC:
: touch /etc/wall_cmos_clock
Also see etc/dhclient.conf, etc/ntp.conf, etc/ssh/sshd_config, and others as
needed.
mount -t devfs devfs /${poolname}/dev
chroot /${poolname}
cd /usr/src/sys/boot
make obj && make depend && make
cd i386/loader
make install
passwd
Set your root password, and exit the chroot environment:
exit
umount /${poolname}/dev
mkdir /boot/zfs
zpool export ${poolname} && zpool import ${poolname}
cp -p /boot/zfs/zpool.cache /${poolname}/boot/zfs/zpool.cache
zfs unmount -a
zfs set mountpoint=legacy ${poolname}/root
zfs set mountpoint=/usr ${poolname}/usr
zfs set mountpoint=/var ${poolname}/var
: etc...