This is an old revision of the document!
Table of Contents
ZFS - Add a Mirror to an Existing ZFS Drive
Convert the most basic ZFS pool, a system with a single disk, to a Mirror or Stripe.
Current Setup:
- We have a single disk attached to our system, /dev/da1
- This disk is used as a simple zfs pool, tank
- You bought another disk and want to mirror the pool to the new disk, /dev/da2
Ensure the disk names are correct
Make sure you’ve got the disk names correct.
Use dmesg to see the system messages, to determine which disk is which.
ALERT: This can be dangerous if you use the wrong disk, as it will destroy all data on the selected disk.
Prepare Your Drive
Delete any existing partitions if needed.
sudo gpart destroy -F /dev/da2
Format the drive as gpt:
sudo gpart create -s gpt /dev/da2
Create a zfs partition:
sudo gpart add -t freebsd-zfs /dev/da2
This new partition is /dev/da2p1, and will nbe added to the existing partition next.
Get the Partition IDs
Get the information needed to feed to zfs so that it will configure the drives correctly.
We will need the gpt ID of the existing partition as well as the new one we’re adding.
The zpool status command will show all we need to know about the existing drive, partition, and pool.
zpool status
returns:
pool: Internal state: ONLINE scan: none requested config: NAME STATE READ WRITE CKSUM Tank ONLINE 0 0 0 gptid/799a169a-aa2f-11ea-bfaa-00d861fcb7d8 ONLINE 0 0 0 errors: No known data errors
NOTE: The bit after “gptid/” is the unique ID of our existing zfs disk: 799a169a-aa2f-11ea-bfaa-00d861fcb7d8.
Determine the ID of the new partition we just created.
Here’s an abbreviated output of gpart list:
gpart list
returns:
Geom name: da2 modified: false state: OK fwheads: 255 fwsectors: 63 last: 7814037127 first: 40 entries: 128 scheme: GPT Providers: 1. Name: da2p1 Mediasize: 4000786984960 (3.6T) Sectorsize: 512 Stripesize: 4096 Stripeoffset: 0 Mode: r0w0e0 rawuuid: 8229a169a-aa2f-11ea-bfaa-00d861fcb7d8 rawtype: 5539a169a-aa2f-11ea-bfaa-00d861fcb7d8 label: (null) length: 4000786984960 offset: 20480 type: freebsd-zfs index: 1 end: 7814037119 start: 40 Consumers: 1. Name: da2 Mediasize: 4000787029504 (3.6T) Sectorsize: 512 Stripesize: 4096 Stripeoffset: 0 Mode: r0w0e0 ....
NOTE: The rawuuid is what is needed, in this example, this is 8229a169a-aa2f-11ea-bfaa-00d861fcb7d8.
Mirror the disks
Tell zfs that these two disks need to be joined together as a mirrored set.
Here are the inputs:
The pool name: Tank The existing partition uuid: 799a169a-aa2f-11ea-bfaa-00d861fcb7d8 The new partition uuid: 8229a169a-aa2f-11ea-bfaa-00d861fcb7d8
Mirror the disks:
sudo zpool attach Tank /dev/gptid/799a169a-aa2f-11ea-bfaa-00d861fcb7d8 /dev/gptid/8229a169a-aa2f-11ea-bfaa-00d861fcb7d8
ZFS will attach the new partition to the existing drive set, mirroring all data from the old drive to the new one.
NOTE: This process of copying data (“resilvering” in zfs parlance) will take a while.
You can use the “zpool status Tank” command to see the progress, including an estimated time of completion.
With two 4 TB drives containing a little over 1 TB of data) it took about 3 hours.
NOTE: zpool attach can only add mirrors to an existing zpool device.
You can’t mess with RAID-Z sets in this manner, even though that would be much more useful.