ZPOOL: Add a mirror to a concat zpool

ZPOOL: Add a mirror to a concat zpool

# Tested on RHEL 6 & 7

# Even if ZFS can use individual slices or partitions, it is recommended to use whole disks.


# Having a concat zpool like following one

POOLNAME=my_pool

zpool status $POOLNAME
     pool: my_pool
    state: ONLINE
    scan: none requested
   config:

           NAME        STATE     READ WRITE CKSUM
           my_pool     ONLINE       0     0     0
             sdb       ONLINE       0     0     0
             sdc       ONLINE       0     0     0

   errors: No known data errors


zpool list
   NAME      SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
   my_pool  19.9G   104K  19.9G     0%  1.00x  ONLINE  -



# we would like to add a mirror

DEVICE01_ORIG=/dev/sdb
DEVICE02_ORIG=/dev/sdc

DEVICE01_MIRR=/dev/sdd
DEVICE02_MIRR=/dev/sde


# We add one by one the new devices to the existing ones to form the new mirrors

zpool attach $POOLNAME $DEVICE01_ORIG $DEVICE01_MIRR

# If you have an error like this one:

   invalid vdev specification
   use '-f' to override the following errors:
   /dev/sdd does not contain an EFI label but it may contain partition
   information in the MBR.

# you should use '-f' option to create the pool - first ensure that disk(s) are the
# right one(s):

# zpool attach -f $POOLNAME $DEVICE01_ORIG $DEVICE01_MIRR



# Check

zpool status $POOLNAME
     pool: my_pool
    state: ONLINE
    scan: resilvered 36.5K in 0h0m with 0 errors on Tue Sep  1 15:18:06 2015
   config:

           NAME        STATE     READ WRITE CKSUM
           my_pool     ONLINE       0     0     0
             mirror-0  ONLINE       0     0     0
               sdb     ONLINE       0     0     0
               sdd     ONLINE       0     0     0   <----
             sdc       ONLINE       0     0     0

   errors: No known data errors



zpool attach $POOLNAME $DEVICE02_ORIG $DEVICE02_MIRR

# If you have an error like this one:

   invalid vdev specification
   use '-f' to override the following errors:
   /dev/sde does not contain an EFI label but it may contain partition
   information in the MBR.

# you should use '-f' option to create the pool - first ensure that disk(s) are the
# right one(s):

# zpool attach -f $POOLNAME $DEVICE02_ORIG $DEVICE02_MIRR


# Check

zpool status $POOLNAME
     pool: my_pool
    state: ONLINE
    scan: resilvered 64K in 0h0m with 0 errors on Tue Sep  1 15:18:45 2015
   config:

           NAME        STATE     READ WRITE CKSUM
           my_pool     ONLINE       0     0     0
             mirror-0  ONLINE       0     0     0
               sdb     ONLINE       0     0     0
               sdd     ONLINE       0     0     0   <----
             mirror-1  ONLINE       0     0     0
               sdc     ONLINE       0     0     0
               sde     ONLINE       0     0     0   <----

   errors: No known data errors


zpool list
   NAME      SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
   my_pool  19.9G   116K  19.9G     0%  1.00x  ONLINE  -






# ------------------------------------------------------------------------------------------
# Adding a mirror to a concat zpool using disks of different sizes
# ------------------------------------------------------------------------------------------

# I will use two asymmetric disk partitions with the aim of giving an example:

lvmdiskscan | egrep "sdb1|sdc1"
     /dev/sdb1           [       5.00 GiB]
     /dev/sdc1           [      10.00 GiB]


# 1.- If we try to mirror a pool using a disk that is smaller than the existing one, this
# is what happens:

zpool create my_pool sdc1

zpool list my_pool
   NAME      SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
   my_pool  9.94G  77.5K  9.94G     0%  1.00x  ONLINE  -

zpool attach my_pool sdc1 sdb1
   cannot attach sdb1 to sdc1: device is too small

# No problem so far: System prevents us from creating a mirror in a wrong way; that's all




# 2.- When adding a mirror using a disk that is larger than the existing one, we have to
# use the "autoexpand" property, that must be enabled for the whole size of the new disk
# to be used instead of limiting the pool to the original size. This will happens once
# the original disk has been removed from the pool, otherwise we would have an "asymmetric"
# mirror.

# Create a simple pool

zpool create my_pool sdb1

zpool list my_pool
   NAME      SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
   my_pool  4.97G   109K  4.97G     0%  1.00x  ONLINE  -


# Enable "autoexpand"

zpool set autoexpand=on my_pool


# Add the mirror (new disk bigger than existing one)

zpool attach my_pool sdb1 sdc1


# Size remains constant
...

zpool list my_pool
   NAME      SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
   my_pool  4.97G   159K  4.97G     0%  1.00x  ONLINE  -


# ... until I detach the original disk. At that moment the pool is "autoexpanded"

zpool detach my_pool sdb1

zpool list my_pool
   NAME      SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
   my_pool  9.97G   168K  9.97G     0%  1.00x  ONLINE  -




# If we had forgotten to enable auto-expansion before detaching the original disk, pool's
# size is not expanded even if we change "autoexpand" property afterwards. To get to
# expand the pool we have to run a "zpool online" command on the new disk(s)

zpool create my_pool sdb1

zpool attach -f my_pool sdb1 sdc1

zpool list my_pool
   NAME      SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
   my_pool  4.97G   156K  4.97G     0%  1.00x  ONLINE  -

zpool detach my_pool sdb1

zpool list my_pool
   NAME      SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
   my_pool  4.97G   156K  4.97G     0%  1.00x  ONLINE  -


# Ooops, I forgot to enable the autoexpand property, I will do it now...

zpool get autoexpand my_pool
   NAME     PROPERTY    VALUE   SOURCE
   my_pool  autoexpand  off     default

zpool set autoexpand=on my_pool

# No way, it doesn't work:

zpool list my_pool
   NAME      SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
   my_pool  4.97G   172K  4.97G     0%  1.00x  ONLINE  -

# No problem, let's run an "online" on the new disk (even if it is already online)

zpool online my_pool sdc1

# and voilà!, the pool has been expanded:

zpool list my_pool
   NAME      SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
   my_pool  9.97G   153K  9.97G     0%  1.00x  ONLINE  -
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
Find All Large Files On A Linux System
Viewed 622 times since Mon, Oct 29, 2018
How to create stunnel with systemd? stunnel
Viewed 298 times since Thu, Jan 16, 2020
RHCS6: Debug and test multicast traffic between two hosts
Viewed 634 times since Sun, Jun 3, 2018
How To Set Up an SSL Tunnel Using Stunnel on Ubuntu
Viewed 713 times since Fri, Sep 28, 2018
OpenSSL: Check SSL Certificate Expiration Date and More
Viewed 568 times since Mon, Feb 18, 2019
ZPOOL: Verify/change properties of a zpool
Viewed 586 times since Sun, Jun 3, 2018
Applescript: Run or Call a Shell Script
Viewed 577 times since Tue, Aug 6, 2019
Script to Offline and Remove A Disk In Linux
Viewed 414 times since Mon, Jan 28, 2019
LVM: Move allocated PE between Physical Volumes
Viewed 747 times since Sat, Jun 2, 2018
How To Find Largest Top 10 Files and Directories On Linux / UNIX / BSD find
Viewed 427 times since Mon, Oct 29, 2018