FreeBSD, FreeNAS

How to use GPT labels on FreeNAS – Part 1

I’ve recently been on a mission to make FreeNAS use GPT labels. By default, FreeNAS uses the GPT GUID format which makes it difficult to track down a drive in the event of a failure.

For example, the zpool status of a default FreeNAS setup will look something similar to:

[root@freenas] ~# zpool status tank
  pool: tank
 state: ONLINE
  scan: none requested
config:

	NAME                                            STATE     READ WRITE CKSUM
	tank                                            ONLINE       0     0     0
	  mirror-0                                      ONLINE       0     0     0
	    gptid/c16b5f1a-2abf-11e5-874b-000c29f1f845  ONLINE       0     0     0
	    gptid/c181b4bb-2abf-11e5-874b-000c29f1f845  ONLINE       0     0     0

errors: No known data errors

Unfortunately, this only tells you the GUID of the disk which is not available in the UI at all. Therefore, in the event of a failure, you’ll have to poke around to pinpoint which disk has failed.

Let’s fix that…

Step 1 – Detach / Export the Volume

In the FreeNAS UI, navigate to Storage » Volumes. Select the volume you want to detach and click the “Detach Volume” button on the bottom of the screen.

WARNING – Do NOT check “Mark the disks as new (destroy data):” – you will be re-importing the volume using your new GPT labels shortly.

Click “Yes” to detach the volume. Wait for it to finish. The volume should no longer appear under Storage » Volumes. Don’t worry, your data is safe.

Verify the volume has been detached / exported:

[root@freenas] ~# zpool status tank
cannot open 'tank': no such pool

Step 2 – Get to Know Your Disks

There may be a little manual work involved here. You need to know which drive is in which bay. Hopefully you made a list of your HDD Serial #s and their respective bay positions when you setup your box. You did make a list right?

You should have something similar to:

+-----+-----------------+------+
| Bay | Serial          | Name |
+-----+-----------------+------+
|  0  | WD-WCC4EHVNCTEX |  ?   |
|  1  | WD-WCC4E4ERC8DN |  ?   |
|  .  |       ...       |  .   |
+-----+-----------------+------+

If you already have this, you can skip to “Step 3 – Add the GPT labels”.

If not, you will need to make this list. This involves opening your case and inspecting each bay’s HDD Serial #. Go do that now and come back, I’ll wait…

Now that you have your list and it looks similar to the above, you need to know the raw device names (as seen by FreeNAS kernel) before you can label the drives.

Navigate to Storage » View Disks and compare the Serial #s and update your list:

+-----+-----------------+------+
| Bay | Serial          | Name |
+-----+-----------------+------+
|  0  | WD-WCC4EHVNCTEX | da1  |
|  1  | WD-WCC4E4ERC8DN | da2  |
|  .  |       ...       |  .   |
+-----+-----------------+------+

Step 3 – Add the GPT labels

Now that you know where each disk is located and the raw device names, now you can add the GPT labels.

Here you are free to use any labeling scheme you want.

I have a Fractal Design R4 case with a single column of 8 bays so I’m going to keep it simple. I will use bayX labels and follow the convention that bay0 is the top most bay and bay7 is the bottom most bay.

Now label each drive:

[root@freenas] ~# gpart modify -i `gpart show da1 | grep freebsd-zfs | awk '{print $3}'` -l bay0 da1
da1p2 modified
[root@freenas] ~# gpart modify -i `gpart show da2 | grep freebsd-zfs | awk '{print $3}'` -l bay1 da2
da2p2 modified
...

After adding the GPT labels, you may expect the new devices to appear under /dev/gpt/ but they’re not there:

[root@freenas] ~# ls -al /dev/gpt
ls: /dev/gpt: No such file or directory

This is because you need to force the kernel to “retaste” the drives by opening and closing a file descriptor. Here’s the easiest way to do that:

[root@freenas] ~# true > /dev/da1
[root@freenas] ~# true > /dev/da2
...
[root@freenas] ~# ls -al /dev/gpt
total 1
dr-xr-xr-x   2 root  wheel      512 Jul 15 01:30 ./
dr-xr-xr-x  11 root  wheel      512 Jul 14 23:59 ../
crw-r-----   1 root  operator  0x62 Jul 15 01:30 bay0
crw-r-----   1 root  operator  0x6b Jul 15 01:31 bay1

Now your drives have GPT labels and the devices are present under /dev/gpt/bayX

Step 4 – Update the Volume

To get FreeNAS to start using your new GPT labels, you first need to manually import the zpool from the CLI. This will update the pool’s metadata with the new location of the devices. To do this you pass the -d dir parameter to the zpool import command which instructs it to look for devices in a specific location

[root@freenas] ~# zpool import -d /dev/gpt -R /mnt tank
[root@freenas] ~# zpool status tank
  pool: tank
 state: ONLINE
  scan: none requested
config:

	NAME          STATE     READ WRITE CKSUM
	tank          ONLINE       0     0     0
	  mirror-0    ONLINE       0     0     0
	    gpt/bay0  ONLINE       0     0     0
	    gpt/bay1  ONLINE       0     0     0

errors: No known data errors

Now the zpool is using our GPT labels for the devices.

Before we can re-import the volume using the FreeNAS UI, we need to export it so that FreeNAS can find it. This simply unmounts the pool and makes it available for import.

[root@freenas] ~# zpool export tank

Step 5 – Import the Volume

Now you can import the volume using the FreeNAS UI. Navigate to Storage and click “Import Volume”. Since this is not an encrypted ZFS volume, leave “No: Skip to import” selected and click OK.

In Step 2 of 2, you should see your ‘tank’ listed in the Volume drop down. Leave it selected and click OK.

Your zpool should now appear under Storage » Volumes.

Conclusion

Now your zpool status should like similar to:

[root@freenas] ~# zpool status tank
  pool: tank
 state: ONLINE
  scan: resilvered 128K in 0h0m with 0 errors on Wed Jul 15 01:48:37 2015
config:

	NAME          STATE     READ WRITE CKSUM
	tank          ONLINE       0     0     0
	  mirror-0    ONLINE       0     0     0
	    gpt/bay0  ONLINE       0     0     0
	    gpt/bay1  ONLINE       0     0     0

errors: No known data errors

This has the added advantage that when a disk fails, you can easily pinpoint which bay contains the failed disk.

As a simple example, if I manually offline one of my disks, zpool status will tell me exactly which bay the failed HDD is in:

[root@freenas] ~# zpool status -x
all pools are healthy
[root@freenas] ~# zpool offline tank gpt/bay1
[root@freenas] ~# zpool status -x
  pool: tank
 state: DEGRADED
status: One or more devices has been taken offline by the administrator.
	Sufficient replicas exist for the pool to continue functioning in a
	degraded state.
action: Online the device using 'zpool online' or replace the device with
	'zpool replace'.
  scan: none requested
config:

	NAME                      STATE     READ WRITE CKSUM
	tank                      DEGRADED     0     0     0
	  mirror-0                DEGRADED     0     0     0
	    gpt/bay0              ONLINE       0     0     0
	    13146268604721863594  OFFLINE      0     0     0  was /dev/gpt/bay1

From this, I can easily see that bay1 contains the failed HDD.

In Part 2 of this series, I’m going to show you how to do the same thing but using an encrypted zpool.

Stay tuned!

Advertisements

One thought on “How to use GPT labels on FreeNAS – Part 1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s