Avoiding Device Confusion in FreeBSD with ZFS

Avoiding Device Confusion in FreeBSD with ZFS

January 25, 2012 in FreeBSD

In tutorial after tutorial, I find people creating zpools using a method that looks like:

% zpool create tank /dev/da2 /dev/da3 /dev/da4 /dev/da5

But, what happens when you reboot without /dev/da2 plugged in? /dev/da3 becomes /dev/da2 and your pool is confused and weird and all that junk.

A simple tip is to create a GPT on each disk you plan to add to a pool and rather than using the device node of /dev/da#p#, use the GPT partition ID device node that’s automatically created under /dev/gptid.

First, wipe the partition table on each of your disks, using:


% dd if=/dev/zero of=/dev/da2 bs=512 count=1
% dd if=/dev/zero of=/dev/da3 bs=512 count=1
% dd if=/dev/zero of=/dev/da4 bs=512 count=1
% dd if=/dev/zero of=/dev/da5 bs=512 count=1

Now create a new GPT on each disk, using:


% gpart create -s gpt da2
% gpart create -s gpt da3
% gpart create -s gpt da4
% gpart create -s gpt da5

Now create a FreeBSD ZFS partition on each disk. This is easy because we’re only making one partition per disk.


% gpart add -t freebsd-zfs da2
% gpart add -t freebsd-zfs da3
% gpart add -t freebsd-zfs da4
% gpart add -t freebsd-zfs da5

You should now see the gptids listed in /dev/gptid/


# ls -l /dev/gptid
total 0
crw-r----- 1 root operator 0, 126 Jan 23 15:44 1bcdc07f-4603-11e1-bd02-003048bb1b96
crw-r----- 1 root operator 0, 135 Jan 23 15:44 1cf8bda4-4603-11e1-bd02-003048bb1b96
crw-r----- 1 root operator 0, 143 Jan 23 15:44 1da00324-4603-11e1-bd02-003048bb1b96
crw-r----- 1 root operator 0, 151 Jan 23 15:45 1e83229b-4603-11e1-bd02-003048bb1b96

Now simply create your zpool however you like, using the gptid device node instead of the device ID.


# zpool create external \
/dev/gptid/1bcdc07f-4603-11e1-bd02-003048bb1b96 \
/dev/gptid/1cf8bda4-4603-11e1-bd02-003048bb1b96 \
/dev/gptid/1da00324-4603-11e1-bd02-003048bb1b96 \
/dev/gptid/1e83229b-4603-11e1-bd02-003048bb1b96

And check on it…


# zpool status external
pool: external
state: ONLINE
scan: none requested
config:

NAME STATE READ WRITE CKSUM
external ONLINE 0 0 0
gptid/1bcdc07f-4603-11e1-bd02-003048bb1b96 ONLINE 0 0 0
gptid/1cf8bda4-4603-11e1-bd02-003048bb1b96 ONLINE 0 0 0
gptid/1da00324-4603-11e1-bd02-003048bb1b96 ONLINE 0 0 0
gptid/1e83229b-4603-11e1-bd02-003048bb1b96 ONLINE 0 0 0

errors: No known data errors

You can use the gpart utility to see all kinds of data about your partitions as well. This is useful to figure out which gptid belongs to which disk.

Copyright © 2009 Christopher J. Umina - Powered by WordPress - Portfolio WordPress Theme by ThemeShift.com.