The Tridecadal Korean (astralblue) wrote,
The Tridecadal Korean

  • Mood:

ZFS-only installation of FreeBSD 9.0 from DVD

This is a step-by-step guide, mostly for my own reference, but you might find this useful too.

Disclaimer: This article is about clean installation of operating system, where “clean” means that, if you follow these instructions, all existing contents of the hard drive will be destroyed.  Do not follow these instructions except on an empty hard drive.  I shall not be held responsible for any loss of data.

  1. Boot using the FreeBSD 9.0 DVD.

  2. Proceed with installation until the installer asks you how to partition the disk.  Choose “Shell”.

  3. Wipe out any existing partition table on the disk (da0 in this example):

    # dd if=/dev/zero of=/dev/da0 bs=1m count=128 128+0 records in 128+0 records out 134217728 bytes transferred in 1.475510 secs (90963625 bytes/sec)
  4. Initialize the disk with a GUID partition table (GPT), then install stage 1 (GPT) boot code “pmbr” into the MBR:

    # gpart create -s GPT da0 da0 created # gpart bootcode -b /boot/pmbr da0 bootcode written to da0
  5. Create the boot partition that pmbr expects1, then install stage 2 boot code “gptzfsboot” into it:

    # gpart add -t freebsd-boot -l crimson-boot -s 128 da0 da0p1 added # gpart bootcode -p /boot/gptzfsboot -i 1 da0
  6. Create a swap partition (1GB in this example):

    # gpart add -t freebsd-swap -l crimson-swap -s 1G da0 da0p2 added
  7. Create a ZFS partition, then create a ZFS pool with it:

    # gpart add -t freebsd-zfs -l crimson-root da0 da0p3 added # zpool create -o altroot=/mnt -o cachefile=/tmp/zpool.cache crimson gpt/crimson-root # df -h /mnt Filesystem Size Used Avail Capacity Mounted on crimson 897G 31k 897G 0% /mnt
  8. Make the ZFS pool available for booting2:

    # zpool set bootfs=crimson crimson
  9. Set the mountpoint of the root filesystem to /3:

    # zfs set mountpoint=/ crimson
  10. Copy zpool.cache, which was created earlier when we ran zfs create) into /boot/zfs5:

    # mkdir -p /mnt/boot/zfs # cp -p /tmp/zpool.cache /mnt/boot/zfs/zpool.cache
  11. Add the swap partition:

    # echo '/dev/gpt/crimson-swap none swap sw 0 0' >> /tmp/bsdinstall_etc/fstab
  12. Return to the installer:

    # exit
  13. Continue with regular installation procedure, until it asks you: “The installation is now finished. Before exiting the installer, would you like to open a shell in the new system to make any final manual modifications?”  Choose “Yes”, which will drop you into a shell again.

  14. Now we need to do additional, ZFS-specific configuration.  But before doing so, first mount /dev:

    # mount -t devfs devfs /dev
  15. Load the ZFS kernel module when booting:

    # cd /boot # echo 'zfs_load="YES"' >> loader.conf
  16. Instruct that the ZFS root pool (“crimson”) is also the root filesystem:

    # echo 'vfs.root.mountfrom="zfs:crimson"' >> loader.conf
  17. Tell ZFS not to disable prefetch:

    # echo 'vfs.zfs.prefetch_disable="0"' >> loader.conf
  18. Enable ZFS in /etc/rc.conf:

    # cd /etc # echo 'zfs_enable="YES"' >> rc.conf
  19. Exit the shell.

    # exit
  20. Installation is completed; the system will ask you to reboot.  Do so, with your fingers crossed. :-p

1 ^ pmbr locates a GUID partition of freebsd-boot type then loads and executes the next-stage boot code from it.

2 ^ gptzfsboot locates a ZFS pool with the bootfs (boot filesystem) property set, then loads and executes BTX loader (a.k.a. /boot/loader) from that filesystem.

3 ^ In fact we don't have to do this, at least as of FreeBSD 8.1/8.2/9.0.  As a little-known and undocumented side effect of specifying an altroot at the time of pool creation, the mountpoint property of root filesystem has already been set to /.  I included this step just in case the default behavior of “zpool create -o altroot=…” changes in a future version of ZFS.

5 ^ zpool.cache contains information about system pools (i.e. pools imported without the -R option).  Various stages of booting process need it in order to locate the root/boot pool.

Tags: freebsd, zfs

  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 1 comment