b0rken.org / freebsd / Installing FreeBSD on a mirrored ZFS pool
Installing FreeBSD on a mirrored ZFS pool
Synopsis:
These notes describe my method of installing FreeBSD on a mirrored ZFS pool. It is based mostly on Scot Hetzel's excellent guide on the FreeBSD Wiki.
My method differs from Scot's in that I employ a ZFS filesystem layout that is based on the default filesystem layout of OpenSolaris, avoiding use of the top-level dataset in the pool as the root filesystem, in accordance with the ZFS Best Practices. It says, "Consider using the top-level dataset as a container for other file systems" which I interpret as meaning "use the top-level dataset only as a container for other filesystems". This helps avoid potential adminstrative difficulties later on, and makes it possible to set up a complete set of filesystems "parallel" with the existing ones, if, for example, you want to create an alternative boot environment. It isn't possible to create a filesystem "parallel" to the top-level dataset.
I also like to keep my user data as seperate from the OS data as possible, so I put the home filesystems into an entirely seperate branch of the ZFS tree. I am thus able to perform recursive ZFS actions on either the OS data or the user data without affecting or including the other.
I have not used GEOM labels for the GPT partitions either. ZFS seems intelligent enough to automatically spot when a device name has changed. When I originally built a FreeBSD box on ZFS, I was unaware of the existence of the AHCI module, so my pool was built on ad4 and ad6 devices. After I enabled the module the disks changed to ada0 and ada1, but ZFS seamlessly continued to recognise their freebsd-zfs partitions as components of the root pool, referencing them by their gptid instead.
Prerequisites:
- FreeBSD 8.1 RELEASE memstick image, written to a USB flash drive, or
- FreeBSD 8.1 RELEASE dvd1 image burnt to a DVD-R.
Process:
- Boot from the USB stick or DVD
- At the loader menu, press 6 to escape to a loader prompt
- Load required modules, then continue booting:
- In sysinstall, set your keyboard language and then choose Fixit from the main menu, specifying the appropriate device to run the environment from (DVD or USB)
- GPT partition first disk, ada0, and install bootcode:
- Repeat the previous steps for second disk, ada1.
- Show GPT layout so far:
- Set the single partition defined in the protective MBR as active. Some systems that have a BIOS that checks for the existence of an active MBR partition on the boot drive and fails to boot if it isn't found. Intel motherboards seem to do this:
- Create /boot/zfs directory for zpool.cache file:
- Create mirrored zpool from freebsd-zfs partitions on each disk:
- Create ZFS hierarchy, mounted under /mnt:
- Extract FreeBSD distribution to ZFS filesystems:
- Copy GENERIC kernel to expected location:
- Edit loader.conf and rc.conf to load modules and start ZFS on boot:
- Set up fstab to mount swap and tmpfs* on boot:
- Copy zpool.cache to /mnt/boot:
- Export LD_LIBRARY_PATH:
- Unmount all ZFS filesystems and then change their mountpoints:
- Set bootfs property on pool:
- Exit Fixit environment and reboot
- Set root's password
- Configure hostname and networking
- Configure timezone
- Configure services to start on boot; sshd, ntpd, etc
Type '?' for a list of commands, 'help' for more detailed help.
OK load ahci
/boot/kernel/ahci.ko size 0xfd88 at 0x126b000
OK load zfs
/boot/kernel/zfs.ko size 0x19eb18 at 0x127b000
loading required module 'opensolaris'
/boot/kernel/opensolaris.ko size 0x3868 at 0x141a000
OK boot
(* Using tmpfs with zfs is apparently not a good idea - see ZFSKnownProblems on the FreeBSD wiki)
The system should now boot into the new ZFS-based FreeBSD installation. At this stage, it is very minimally configured. The following still needs to be done:
Last modified: 2011-07-14 09:54