FreeBSD 8.0 on ZFS

Installing FreeBSD Root on ZFS using FreeBSD-ZFS partition in a FreeBSD MBR Slice

Contents

1. Creating a bootable ZFS Filesystem
2. Installing FreeBSD to the ZFS filesystem
3. Finish install



1. Creating a bootable ZFS Filesystem

1. Boot FreeBSD install DVD or USB Memstick
2. Choose Fixit option in sysinstall
3. Create MBR disk



If you are installing on an New drive, you will need to create the MBR geometry first:

Fixit# gpart create -s mbr ad0

4.Create Slice using gpart



This example already has two slices defined on the drive.

Fixit# 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 using the beginning parameter and size parameters. Then create a BSD partition table on the new slice.

Fixit# gpart add -b 210130200 -s 415012248 -t freebsd ad0
ad0s3 added
Fixit# gpart create -s BSD ad0s3
ad0s3 created


And examine the result:

Fixit# gpart show ad0
=> 63 625142385 ad0 MBR (289G)
63 209712447 1 !7 (100G)
209712510 417690 2 !136 (204M)
210130200 415012248 3 freebsd (198G)


Note:
* Sizes and offsets are specified in sectors (1 sector is typically 512 bytes).
5.Set partition active (Optional)



Some BIOSes might require setting a Slice active. Here we set partition 1 (the Windows Partiton) as the active partition.

Fixit# gpart set -a active -i 1 ad0

6. Create partitions (ad0s3a and ad0s3b)

Fixit# gpart show ad0s3
=> 0 415012248 ad0s3 BSD (198G)
0 415012248 ad0s3 - free - (198G)


Fixit# gpart add -i 1 -b 0 -s 40663421 -t freebsd-zfs ad0s3
ad0s3a added


Fixit# gpart show ad0s3
=> 0 415012248 ad0s3 BSD (198G)
406631421 1 freebsd-zfs (194G)
406631421 8380827 - free - (4.0G)

Fixit# gpart add -i 2 -b 406626334 -s 8380811 -t freebsd-swap ad0s3
ad0s3b added

Fixit# gpart show ad0s3
=> 0 415012248 ad0s3 BSD (198G)
0 406631421 1 freebsd-zfs (194G)
406631421 8380827 2 freebsd-swap (4.0G)



Note:
1.While a ZFS Swap Volume can be used instead of the freebsd-swap partition, crash dumps can't be created on the ZFS Swap Volume.
2. Sizes and offsets are specified in sectors (1 sector is typically 512 bytes).
7. Load ZFS kernel module

Fixit# kldload /mnt2/boot/kernel/opensolaris.ko
Fixit# kldload /mnt2/boot/kernel/zfs.ko


8. Create ZFS Pool zroot

Fixit# mkdir /boot/zfs
Fixit# zpool create zroot /dev/ad0s3a
Fixit# zpool set bootfs=zroot zroot


Note:
* zroot is the name of the ZFS Pool, it could be anything (i.e. tank, data, ...)
9. Install boot Manager

Fixit# gpart bootcode -b /mnt2/boot/boot0 ad0
ad0 has bootcode


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.
10.

Install ZFS boot

Export zroot, before installing boot code

Fixit# zpool export zroot

Install the boot1 stage:

Fixit# 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:

Fixit# 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).

Fixit# dd if=/mnt2/boot/zfsboot of=/dev/ad0s3a skip=1 seek=1024

Import zroot to continue the install

Fixit# zpool import zroot

2. Installing FreeBSD to the ZFS filesystem

1.Create ZFS filesystem hierarchy



The fletcher4 algorithm should be more robust than the fletcher2 algorithm.

Fixit# zfs set checksum=fletcher4 zroot

Fixit# zfs create -o compression=on -o exec=on -o setuid=off zroot/tmp
Fixit# chmod 1777 /zroot/tmp

Fixit# zfs create zroot/usr
Fixit# zfs create zroot/usr/home
Fixit# cd /zroot ; ln -s /usr/home home

Fixit# zfs create -o compression=lzjb -o setuid=off zroot/usr/ports
Fixit# zfs create -o compression=off -o exec=off -o setuid=off zroot/usr/ports/distfiles
Fixit# 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.

Fixit# zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/usr/src

Fixit# zfs create zroot/var
Fixit# zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/var/crash
Fixit# zfs create -o exec=off -o setuid=off zroot/var/db
Fixit# zfs create -o compression=lzjb -o exec=on -o setuid=off zroot/var/db/pkg
Fixit# zfs create -o exec=off -o setuid=off zroot/var/empty
Fixit# zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/var/log
Fixit# zfs create -o compression=gzip -o exec=off -o setuid=off zroot/var/mail
Fixit# zfs create -o exec=off -o setuid=off zroot/var/run
Fixit# zfs create -o compression=lzjb -o exec=on -o setuid=off zroot/var/tmp
Fixit# chmod 1777 /zroot/var/tmp


Note:
1. Compression may be set to on, off, lzjb, gzip, gzip-N (where N is an integer from 1 (fastest) to 9 (best compresion ratio. gzip is equivalent to gzip-6).
2.Compression will cause some latency when accessing files on the ZFS filesystems. Use compression on ZFS filesystems which will not be accessed that often.


2. Install FreeBSD to zroot

Fixit# cd /dist/8.0-*
Fixit# export DESTDIR=/zroot
Fixit# for dir in base catpages dict doc games info lib32 manpages ports; \
do (cd $dir ; ./install.sh) ; done
Fixit# cd src ; ./install.sh all
Fixit# cd ../kernels ; ./install.sh generic
Fixit# cd /zroot/boot ; cp -Rlp GENERIC/* /zroot/boot/kernel/
3. Make /var/empty readonly

Fixit# zfs set readonly=on zroot/var/empty

4. chroot into /zroot

Fixit# chroot /zroot

5. Create /etc/rc.conf

Fixit# echo 'zfs_enable="YES"' > /etc/rc.conf<br /> Fixit# echo 'hostname="beastie.mydomain.local"' >> /etc/rc.conf<br /> Fixit# echo 'ifconfig_re0="DHCP"' >> /etc/rc.conf<br /></strong><br /> Note:<br /> * Replace re0 with the name of the Network interface for the new system <br /> 6. Create /boot/loader.conf<br /><br /> <strong>Fixit# echo 'zfs_load="YES"' > /boot/loader.conf<br /> Fixit# echo 'vfs.root.mountfrom="zfs:zroot"' >> /boot/loader.conf</strong><br /><br /> 7. Install ZFS aware /boot/loader (Required for 8.0-RELEASE and 7.{0-2}-RELEASE)<br /><br /> <strong>Fixit# echo 'LOADER_ZFS_SUPPORT=YES' > /etc/src.conf<br /> Fixit# mount -t devfs devfs /dev<br /> Fixit# export DESTDIR=""<br /> Fixit# cd /usr/src/sys/boot/<br /> Fixit# make obj<br /> Fixit# make depend<br /> Fixit# make<br /> Fixit# cd i386/loader<br /> Fixit# make install</strong><br /><br /> Note:<br /><br /> This step is now obsoleted since FreeBSD installs a ZFS aware boot loader (/boot/zfsloader)<br /> *<br /><br /> FreeBSD 9.0-CURRENT r199714 (Nov 23, 2009)<br /> *<br /><br /> FreeBSD 8.0-STABLE r200220 (Dec 7, 2009)<br /> *<br /><br /> FreeBSD 7.2-STABLE r200221 (Dec 7, 2009) <br /> 8. Change root's password<br /><br /> <strong>Fixit# passwd</strong><br /><br /> 9. Set the local time zone<br /><br /> <strong>Fixit# tzsetup</strong><br /><br /> 10. Create /etc/mail/aliases.db<br /><br /> <strong>Fixit# cd /etc/mail<br /> Fixit# make aliases</strong><br /><br /> 11. Exit from the /zroot<br /><br /> <strong>Fixit# umount /dev<br /> Fixit# exit<br /></strong> 12. Install zpool.cache to the ZFS filesystem<br /><br /> <strong>Fixit# cp /boot/zfs/zpool.cache /zroot/boot/zfs/zpool.cache</strong><br /><br /><span style="font-size: small;">3. Finish install

1. Create /etc/fstab

Fixit# cat << EOF > /zroot/etc/fstab
# Device Mountpoint FStype Options Dump Pass#
/dev/ad0s3b none swap sw 0 0
EOF
2. export LD_LIBRARY_PATH

Fixit# export LD_LIBRARY_PATH=/mnt2/lib

3. Unmount all zfs filesystems

Fixit# zfs unmount -a



4. Change mount points for zroot pool

Fixit# zfs set mountpoint=legacy zroot
Fixit# zfs set mountpoint=/tmp zroot/tmp
Fixit# zfs set mountpoint=/usr zroot/usr
Fixit# zfs set mountpoint=/var zroot/var
5. Exit Fixit mode, and then sysinstall. Remove the FreeBSD install DVD/Memstick and the system will boot using the ZFS root

source:http://wiki.freebsd.org/RootOnZFS/ZFSBootPartition