How to Convert a Stripe into a Mirror in FreeNAS

http://techblog.danielpellarini.com/sysadmin/how-to-convert-a-stripe-into-a-mirror-in-freenas/

Ideally, with FreeNAS, if you plan on using mirrored drives, you should start directly with 2 physical drives. This holds for every combination of drives actually, because modifying existing vdevs is not allowed (you can only add new vdevs to an existing zpool).

The only exception consists in converting a striped vdev into a mirrored vdev. In my case, I started using FreeNAS in a test machine with a single physical drive, but then decided to add a second drive to keep testing it a little bit more thoroughly. Obviously, one solution consisted in taking a copy of my data, wipe out both disks, create a mirror vdev and then reimport the data from the backup, but why go through the hassle when you can do this quickly and easily from the CLI?

These instructions are taken from a post on the official FreeNAS forum. I have decided to include them here because there are several discussions on the topic on the forum, but not all of them include comprehensive instructions on how to do this.

gpart create -s gpt /dev/ada1
gpart add -i 1 -b 128 -t freebsd-swap -s 2g /dev/ada1
gpart add -i 2 -t freebsd-zfs /dev/ada1

Run

zpool status

and note the gptid of the existing disk
Run

glabel status

and find the gptid of the newly created partition. It is the gptid associated with ada1p2.

zpool attach tank /dev/gptid/[gptid_of_the_existing_disk] /dev/gptid/[gptid_of_the_new_partition]

In FreeNAS, hard drives are normally named ada<n>, with <n> starting from 0 and being incremented by one every time a new hard drive is added. Therefore, if you are only using one hard drive and want to add a second one, your new drive will likely be called ada1.

Also, replace tank with your zpool name.

I vehemently recommend testing this in a virtualized environment before attempting it on your physical system. Dealing with vdevs and zpools is a delicate operation, and you really don’t want to risk losing your data just because of a wrong command.

Note: if the new hard drive already contains some data, you need to wipe it first. This can be easily done from the GUI:

If everything went fine, you should see the resilvering process take place after running a zpool status:

1429970946_thumb.png

And at the end of the resilvering process you should see something like this:

Screenshot 2015-04-25 16.26.37