Monday, April 20, 2009

Mirroring a ZFS Root on FreeBSD

You guys have to check on FreeBSD Installation and ZFS first if you haven't configured your FreeBSD b0x's root on ZFS as this article is just a continuation from that post ;)

Now let's get our hands on having a mirror or RAID-1 with ZFS and FreeBSD.

  • Well first off, we have to install the hard disk to your system and boot up
  • Login as root
  • Type in sysinstall
  • Select Custom Installation
  • Partition the Hard Disk (Use A = Use Entire Disk and Press Q = Quit)
  • Label the Hard Disk (Use A = Auto Defaults)
  • Select the /usr, /var, /tmp Mount Points one at a time and press D (Delete)
  • Leave only the / and the swap partitions
  • Press C to create a new partition and then type /anything as the Mount Point
  • Select the newly created partition and press M (Mount pt) to clear the field by deleting /anything and then press on W to write on the disk and Q to quit
  • Press on
  • Exit from sysinstall
And now we could check out initially what we have:
#zpool status
Then we add the 2nd drive to our mirror (our second drive comes up as ad6)
# zpool attach tank ad4s1d ad6s1d
# zpool status

It will now show the two hard disks on a mirror
pool: tank
state: ONLINE
scrub: none requested


config:

NAME STATE READ WRITE CKSUM
tank ONLINE 0 0 0
mirror ONLINE 0 0 0
ad4s1d ONLINE 0 0 0
ad6s1d ONLINE 0 0 0

errors: No known data errors
Seeing that we have a new mirror, we now copy the contents from our UFS slice to the second drive.
# newfs /dev/ad6s1a
# mkdir /mnt/bootdir
# mount /dev/ad6s1a /mnt/bootdir
# find -x /bootdir | cpio -pmd /mnt
Now supposed that we have a failure on the 1st HDD, we have configured the 2nd HDD to be ready.

We also have to stop fsck during the bootup process should the first HDD fail (in this case ad4). Edit /etc/fstab so our UFS slice is mounted in the right location for when ZFS boots.

We also NEED to make sure that the /bootdir/zfs/zpool.cache file is the same on both HDDs and edit /etc/fstab as:
/dev/ad4s1a  /bootdir       ufs      rw      1       0
/dev/ad6s1a /mnt/bootdir ufs rw 1 0
And that's it!


"Now What?"