Floating Octothorpe

Building a NAS: part 4 - ZFS mirror

At the end of the previous post I had a ZFS pool backed by a single vdev. This is all well and good until a disk fails. To improve fault tolerance ZFS allows you to add a mirror disk. This obviously isn't a backup; but should make life easier if a disk fails unexpectedly.

Layout diagram showing an extra vdev being added to a pool

Adding a mirror

Assuming you are starting from a pool backed by a single vdev, adding an additional vdev to mirror the content is relatively straightforward.

  1. First make sure the pool is online:

    $ zpool status pool: mypool state: ONLINE
      scan: none requested
    config:
    
            NAME        STATE     READ WRITE CKSUM
            mypool      ONLINE       0     0     0
              sdc       ONLINE       0     0     0
    
    errors: No known data errors
    
  2. Then identify the device to join to the pool using lsblk:

    $ lsblk
    NAME                MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
    sda                   8:0    0 37.3G  0 disk
    ├─sda1                8:1    0  731M  0 part  /boot
    ├─sda2                8:2    0    1K  0 part
    └─sda5                8:5    0 36.6G  0 part
      └─sdb5_crypt      253:0    0 36.6G  0 crypt
        ├─vghost-root   253:1    0 35.6G  0 lvm   /
        └─vghost-swap_1 253:2    0  976M  0 lvm   [SWAP]
    sdb                   8:16   1  492M  0 disk
    └─sdb1                8:17   1  491M  0 part
    sdc                   8:32   0  3.7T  0 disk
    ├─sdc1                8:33   0  3.7T  0 part
    └─sdc9                8:41   0    8M  0 part
    sdd                   8:48   0  3.7T  0 disk
    ├─sdd1                8:49   0  3.7T  0 part
    └─sdd9                8:57   0    8M  0 part
    

    Note: in this case /dev/sdd is the device we want to use.

  3. Clear any existing partitions from the disk (make sure you have the correct disk!):

    $ parted /dev/sdd mklabel gpt
    Warning: The existing disk label on /dev/sdd will be destroyed and all data on this disk will be lost. Do you want to continue?
    Yes/No? yes
    Information: You may need to update /etc/fstab.
    
  4. Finally attach the blank disk to the pool, ZFS will automatically start resilvering the new disk to setup a mirror:

    $ zpool attach mypool /dev/sdc /dev/sdd
    
    $ zpool status
      pool: mypool
     state: ONLINE
    status: One or more devices is currently being resilvered.  The pool will
            continue to function, possibly in a degraded state.
    action: Wait for the resilver to complete.
      scan: resilver in progress since Mon Apr  6 22:40:24 2020
            38.6G scanned at 963M/s, 432K issued at 10.5K/s, 2.76T total
            0B resilvered, 0.00% done, no estimated completion time
    config:
    
            NAME        STATE     READ WRITE CKSUM
            mypool      ONLINE       0     0     0
              mirror-0  ONLINE       0     0     0
                sdc     ONLINE       0     0     0
                sdd     ONLINE       0     0     0
    
    errors: No known data errors
    

    Eventually ZFS will finish resilvering and the mirror setup will be complete.