A ZFS mirror consists of two or more disks where all information is written to all members of the vdev. Reads are performed in parallel from all disks, thus increasing read performance. The mirror will have the capacity of the smallest device, and up to N-1 disks can fail without data loss. Additionally, any single-disk vdev can be transformed into a mirror using the zpool attach command. In this article, we will explain how to create a mirror and how to expand a vdev to a mirror.
Before continuing with the article, it is advisable to review this previous one so that all concepts are clear.
We check the available disks in the system:
<BHYVE SATA DISK 001> at scbus0 target 0 lun 0 (ada0,pass0)
<BHYVE SATA DISK 001> at scbus1 target 0 lun 0 (ada1,pass1)
<BHYVE SATA DISK 001> at scbus2 target 0 lun 0 (ada2,pass2)
<BHYVE SATA DISK 001> at scbus3 target 0 lun 0 (ada3,pass3)
<BHYVE SATA DISK 001> at scbus4 target 0 lun 0 (ada4,pass4)
We verify that the system disk is ada0:
pool: zroot
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
zroot ONLINE 0 0 0
ada0p3 ONLINE 0 0 0
errors: No known data errors
We create the partitions that ZFS will use on the next two disks that will form the mirror:
ada1 created
ada1p1 added, but partition is not aligned on 8192 bytes
=> 40 2097072 ada1 GPT (1.0G)
40 2097072 1 freebsd-zfs (1.0G)
ada2 created
ada2p1 added, but partition is not aligned on 8192 bytes
=> 40 2097072 ada2 GPT (1.0G)
40 2097072 1 freebsd-zfs (1.0G)
We create the mirror pool indicating the partitions to be used:
We check its status:
pool: mypool
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
mypool ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
ada1p1 ONLINE 0 0 0
ada2p1 ONLINE 0 0 0
errors: No known data errors
We can see that there is 832M since it is two 1G disks in mirror mode.
NAME USED AVAIL REFER MOUNTPOINT
mypool 276K 832M 96K /mypool
Now we will create a pool with one disk and later expand it to mirror:
ada3 created
ada3p1 added, but partition is not aligned on 8192 bytes
root@freeBSD:~ # zpool status mypool2
pool: mypool2
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
mypool2 ONLINE 0 0 0
ada3p1 ONLINE 0 0 0
errors: No known data errors
We prepare the next disk to be attached to the vdev that forms mypool2:
ada4 created
ada4p1 added, but partition is not aligned on 8192 bytes
We add the second disk:
And voilà, vdev converted to mirror:
pool: mypool2
state: ONLINE
scan: resilvered 312K in 0 days 00:00:00 with 0 errors on Thu Nov 12 22:18:11 2020
config:
NAME STATE READ WRITE CKSUM
mypool2 ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
ada3p1 ONLINE 0 0 0
ada4p1 ONLINE 0 0 0
errors: No known data errors
If one of the disks fails, we just need to replace it:
pool: mypool
state: DEGRADED
status: One or more devices could not be used because the label is missing or
invalid. Sufficient replicas exist for the pool to continue
functioning in a degraded state.
action: Replace the device using 'zpool replace'.
see: http://illumos.org/msg/ZFS-8000-4J
scan: none requested
config:
NAME STATE READ WRITE CKSUM
mypool DEGRADED 0 0 0
mirror-0 DEGRADED 0 0 0
10132353784689973799 FAULTED 0 0 0 was /dev/ada1p1
ada1p1 ONLINE 0 0 0
errors: No known data errors
We prepare the new disk:
ada2 created
ada2p1 added, but partition is not aligned on 8192 bytes
We replace the damaged one:
root@freeBSD:~ # zpool status mypool
pool: mypool
state: ONLINE
scan: resilvered 576K in 0 days 00:00:00 with 0 errors on Sun Nov 15 00:20:48 2020
config:
NAME STATE READ WRITE CKSUM
mypool ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
ada2p1 ONLINE 0 0 0
ada1p1 ONLINE 0 0 0
errors: No known data errors