In previous post, I introduced how to install FreeBSD to ZFS. Now I discover another layout for FreeBSD’s ZFS root. Most of the parts are the same as previous ones. There are only a few differences.
Asus N73SV Notebook
CPU：Intel Core i7 2630QM
12GB DDR3 RAM
Installation media preparation
Download FreeBSD-9.1-RELEASE-amd64-memstick.img, and burn it into your USB flash disk.
Boot FreeBSD 9.1 from USB flash disk.
Enter LiveCD mode
Choose “LiveCD” instead of install
Login name is root without password, then you could enter LiveCD environment.
Create a ramdisk, and mount it at
/tmp to store zpool.cache (optional)
# umount /dev/md1
Create GPT+ZFS partition
Find out your HDD device name, usually, the first AHCI HDD should be
/dev/ada0 (FreeBSD-9.x has AHCI support builtin).
# ls /dev/ad*
Check if there are partitions already in the HDD.
# gpart show ada0
If there are, use gpart to clean them.
Since your HDD partition layout is different from mine, please
man gpart to learn about
gpart delete and
gpart erase by yourself.
After the partitions are clean, we can now create GPT.
# gpart create -s gpt ada0
Create a small parition for FreeBSD to boot from GPT. Attention, if your HDD is AF (Advanced Format) with 4KB sector size, please append “-a 4K” parameter to make sure your partition is correctly aligned.
# gpart add -s 64k -t freebsd-boot ada0
Leave other free space for ZFS. Attention, if your HDD is AF (Advanced Format) with 4KB sector size, please append “-a 4K” parameter to make sure your partition is correctly aligned.
# gpart add -t freebsd-zfs ada0
Write FreeBSD GPT+ZFS bootcode into first partition.
# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0
Create ZFS as single pool mode in second parition, and assign the “/“.
# zpool create -R /mnt -m none rpool /dev/ada0p2
zfs create command to create swap volume in ZFS volume group.
# zfs create -o sync=always -o primarycache=metadata -o secondarycache=none -V 8G rpool/swap
zfs create command to create system layout.
# zfs create -o mountpoint=/usr rpool/USR
Mount ZFS under
zpool export and
zpool import for installation.
# zpool export rpool
Now, your ZFS is mounted under
/mnt, you can see there would be
/mnt/tmp directories. Please type below commands.
# chmod 1777 /mnt/tmp
Let’s install FreeBSD 9.x into ZFS under
/mnt. It is better to change your shell to sh. Please note the line start with “for”, since it is too long, so it’s better to use \ to split it.
Congratulations! You have installed FreeBSD base system into
/mnt. Remember to do the following steps, or your system will fail to boot. Copy zpool.cache to your new system.
# cp /tmp/zpool.cache /mnt/boot/zfs/zpool.cache
At last, set
/boot/loader.conf for your new system.
# echo 'zfs_enable="YES"' >> /mnt/etc/rc.conf
# echo 'zfs_load="YES"' >> /mnt/boot/loader.conf
Set fstab (usually, this file should be empty, because all mountpoints and swap will be automatically mounted after you boot from ZFS)
# touch /mnt/etc/fstab
One last step! Set your ZFS mountpoints.
# zfs set readonly=on rpool/FREEBSD/empty
Then you can reboot, and you should be able to boot into your new FreeBSD-9.x based on ZFS. Now you can link
# ln -sf /usr/home /home
Set root password
OK! Everything is done, enjoy your new FreeBSD system!