Building pools from the CLI

Status
Not open for further replies.
J

jpaetzel

Guest
While FreeNAS has the ability to import arbitrary pools, in some cases it's nice to be able to build a pool from the CLI exactly how the system would do it.

From a high level, FreeNAS uses gpart to partition the disks, then uses the gptid's on the partitions as the pool devices. There are two reasons for this. 1) It allows a bit of swap to be placed on the disk. 2) It removes any dependency on the hardware device naming for pool import. If your disks get reordered or renamed imports will proceed as usual.

Say I want to create a pool called tank that is a mirror of two drives, /dev/ada0 and /dev/ada1

I'm going to start by clearing any labels that may be on the disks.

Code:
# gpart destroy -F /dev/ada0
# gpart destroy -F /dev/ada1


Next I'm going to create labels and partition the disks.

Code:
# gpart create -s gpt /dev/ada0
# gpart add -a 4096 -i 1 -s 2g -t freebsd-swap /dev/ada0
# gpart add -a 4096 -i 2 -t freebsd-zfs /dev/ada0
# gpart create -s gpt /dev/ada1
# gpart add -a 4096 -i 1 -s 2g -t freebsd-swap /dev/ada1
# gpart add -a 4096 -i 2 -t freebsd-zfs /dev/ada1


Now I'm going to get the gptid values for each disk. I'll use these when creating my pool.

Code:
# glabel status
Name  Status  Components
gptid/c2c333a8-7af3-11e3-afda-3c970e1092f6     N/A  ada0p1
gptid/d2c333a8-7af3-11e3-afda-3c970e1092f6     N/A  ada0p2
gptid/e2c333a8-7af3-11e3-afda-3c970e1092f6     N/A  ada1p1
gptid/f2c333a8-7af3-11e3-afda-3c970e1092f6     N/A  ada1p2


I've found the values I want, they are the gptids that correspond to ada1p2 and ada2p2 (-i 2 to gpart add sets the index to 2, which is the data partition)

So it's time to create a pool

Code:
# cd /dev
# zpool create -R /mnt poolname -o failmode=continue mirror  gptid/d2c333a8-7af3-11e3-afda-3c970e1092f6 gptid/f2c333a8-7af3-11e3-afda-3c970e1092f6


Why did I cd /dev? So I could tab complete!

Now I have a pool named poolname, which I will export

Code:
# zpool export poolname


And finally, bring it in to the GUI with the autoimporter so FreeNAS can use it.

Protip. If you want backwards compatibility with your pools you can set the version number of the pool in the create statement, something like this:

Code:
# zpool create -R /mnt poolname -o version=28 -o failmode=continue mirror  gptid/d2c333a8-7af3-11e3-afda-3c970e1092f6 gptid/f2c333a8-7af3-11e3-afda-3c970e1092f6
 

Starpulkka

Contributor
Joined
Apr 9, 2013
Messages
179
Hi i really do like this helpful, did create pools from command today because nic failed on motherboard. After my post you can clear this so this topic would be cleaner and easier to read. Can i ask a question? should "correspond to ada1p2 and ada2p2" be ada0p2 and ada1p2 ? Edit: Also some firsttimer might find it helpful that Root comes last before pool vdev. Or was some points screwed up on purposely so newcomers have learn by actually learning how it can be actually done. very sneaky sneaky =)
 
Status
Not open for further replies.
Top