Resize (grow) a mirror by swapping to larger disks with ZFS

Resize (grow) a mirror with ZFS

I have a non root mirror made up of two 72G drives,
can I replace them with 2 146g drives without a backup
and without loss of data

I knew you could grow a mirror under ZFS by breaking the mirror,
then inserting a larger disk for the broken out smaller disk,
creating a new pool on the larger disk,
cloning the old pool to the new pool,
then destroying the old pool,
then inserting a larger disk for the old (now single drive) pool,
then attaching the second larger drive to the new pool,
then mounting the new pool where
the old pool lived
but this is wild

======================
Resize (grow) a mirror with ZFS
======================

I have a non root mirror made up of two 72G drives,
can I replace them with 2 146g drives without a backup
and without loss of data

Luckly with ZFS you can treat files like drives for test purposes:

=========================
Let’s make 4 test devices
=========================

bash-3.00# cd /export/home/
bash-3.00# ls
lost+found
bash-3.00# mkfile 72m 0 1
bash-3.00# mkfile 156m 2 3

===========================================================
O and 1 become our 72 drives, 2 and 3 become our 156 drives
===========================================================

bash-3.00# ls -la
total 934452
drwxr-xr-x 3 root root 512 Mar 13 00:31 .
drwxr-xr-x 3 root sys 512 Mar 12 21:55 ..
-rw——T 1 root root 75497472 Mar 13 00:31 0
-rw——T 1 root root 75497472 Mar 13 00:31 1
-rw——T 1 root root 163577856 Mar 13 00:31 2
-rw——T 1 root root 163577856 Mar 13 00:31 3
drwx—— 2 root root 8192 Mar 12 21:55 lost+found

===================================
let’s create a mirror with the 72’s
===================================

bash-3.00# zpool create test mirror /export/home/0 /export/home/1
bash-3.00# zpool status
pool: test
state: ONLINE
scrub: none requested
config:

NAME STATE READ WRITE CKSUM
test ONLINE 0 0 0
mirror ONLINE 0 0 0
/export/home/0 ONLINE 0 0 0
/export/home/1 ONLINE 0 0 0

errors: No known data errors
bash-3.00# zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
test 67.5M 92.5K 67.4M 0% ONLINE –

================================
lets put some data on the mirror
================================

bash-3.00# cd /test
bash-3.00# ls
bash-3.00# pwd
/test
bash-3.00# mkfile 1m q w e r t y
bash-3.00# ls -la
total 11043
drwxr-xr-x 2 root root 8 Mar 13 00:33 .
drwxr-xr-x 27 root root 512 Mar 13 00:32 ..
-rw——T 1 root root 1048576 Mar 13 00:33 e
-rw——T 1 root root 1048576 Mar 13 00:33 q
-rw——T 1 root root 1048576 Mar 13 00:33 r
-rw——T 1 root root 1048576 Mar 13 00:33 t
-rw——T 1 root root 1048576 Mar 13 00:33 w
-rw——T 1 root root 1048576 Mar 13 00:33 y
bash-3.00# cd /

=======================================
let’s remove the backside of the mirror
=======================================

bash-3.00# zpool detach test /export/home/1
bash-3.00# zpool status
pool: test
state: ONLINE
scrub: none requested
config:

NAME STATE READ WRITE CKSUM
test ONLINE 0 0 0
/export/home/0 ONLINE 0 0 0

errors: No known data errors
bash-3.00# zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
test 67.5M 6.16M 61.3M 9% ONLINE –

========================================
Now lets replace it with a larger device
========================================

bash-3.00# zpool attach test /export/home/0 /export/home/2
bash-3.00# zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
test 67.5M 6.15M 61.4M 9% ONLINE –
bash-3.00# zpool status
pool: test
state: ONLINE
scrub: resilver completed after 0h0m with 0 errors on Fri Mar 13 00:36:05
2009
config:

NAME STATE READ WRITE CKSUM
test ONLINE 0 0 0
mirror ONLINE 0 0 0
/export/home/0 ONLINE 0 0 0
/export/home/2 ONLINE 0 0 0

errors: No known data errors

===========================================
Now lets detach the frontside of the mirror
===========================================

bash-3.00# zpool detach test /export/home/0
bash-3.00# zpool status
pool: test
state: ONLINE
scrub: resilver completed after 0h0m with 0 errors on Fri Mar 13 00:36:05
2009
config:

NAME STATE READ WRITE CKSUM
test ONLINE 0 0 0
/export/home/2 ONLINE 0 0 0

errors: No known data errors

=========================================
Now let’s replace it with a larger device
=========================================

bash-3.00# zpool attach test /export/home/2 /export/home/3

============
Is it there?
============

bash-3.00# zpool status
pool: test
state: ONLINE
scrub: resilver completed after 0h0m with 0 errors on Fri Mar 13 00:37:38
2009
config:

NAME STATE READ WRITE CKSUM
test ONLINE 0 0 0
mirror ONLINE 0 0 0
/export/home/2 ONLINE 0 0 0
/export/home/3 ONLINE 0 0 0

errors: No known data errors

=======================================================
Note: the resilver will take much longer with more data
=======================================================

=============
Is it bigger?
=============

bash-3.00# zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
test 152M 6.22M 145M 4% ONLINE –
bash-3.00#

=========
Yes it is
=========

========================
Is our data still there?
========================

bash-3.00# ls /test/
e q r t w y
bash-3.00# ls -la /test/
total 12323
drwxr-xr-x 2 root root 8 Mar 13 00:33 .
drwxr-xr-x 27 root root 512 Mar 13 00:32 ..
-rw——T 1 root root 1048576 Mar 13 00:33 e
-rw——T 1 root root 1048576 Mar 13 00:33 q
-rw——T 1 root root 1048576 Mar 13 00:33 r
-rw——T 1 root root 1048576 Mar 13 00:33 t
-rw——T 1 root root 1048576 Mar 13 00:33 w
-rw——T 1 root root 1048576 Mar 13 00:33 y

=========
Yes it is
=========

Leave a Reply

Your email address will not be published. Required fields are marked *