Skip to main content

zonena.me

Growing the Capacity of a ZFS Mirror

When I set up my OpenSolaris server, in order to save on money I had to skimp a little on the disks. I’m only at about 33% capacity right now, but once I pass the 50% mark it will be a good idea to start shopping around for larger disks. By then nice cheap 2TB or 3TB drives should be available. But there’s no reason I can’t get prepared now!

The process for growing a zpool is fairly straightforward.

  1. Attach new devices
  2. Wait for resilver
  3. Detach old devices
  4. Export/import pool (or reboot if operating on the root pool)

First, let’s get set up by creating some file vdevs for testing. Two 128MB to represent the old drives and two 256MB representing the new ones.

# mkfile 128m /vdev/v0
# mkfile 128m /vdev/v1
# mkfile 256m /vdev/v0
# mkfile 256m /vdev/v1
# ls -l /vdev
-rw-------   1 root     root     134217728 Apr  3 06:16 /vdev/v0
-rw-------   1 root     root     134217728 Apr  3 06:17 /vdev/v1
-rw-------   1 root     root     268435456 Apr  3 06:21 /vdev/x0
-rw-------   1 root     root     268435456 Apr  3 06:21 /vdev/x1

Now I’ll create my play area, and check the size.

# zpool create play mirror /vdev/v0 /vdev/v1
# zpool list
NAME     SIZE   USED  AVAIL    CAP  HEALTH  ALTROOT
play     123M  74.5K   123M     0%  ONLINE  -

Okay, 123MB. Next I’ll attach one of my larger vdevs and wait for it to resilver. Since I’m using empty files as stand-ins for disks they’ll resilver almost instantly. MAKE SURE YOU DO NOT DETACH A DISK BEFORE THE NEW DISK IS DONE RESILVERING. You will destroy your data.

# zpool attach play /vdev/v0 /vdev/x0
# zpool detach play /vdev/v0
# zpool attach play /vdev/v1 /vdev/x1
# zpool detach play /vdev/v1

With the new devices attached my pool still doesn’t look any different.

# zpool list
NAME     SIZE   USED  AVAIL    CAP  HEALTH  ALTROOT
play     123M  74.5K   123M     0%  ONLINE  -

Until I re-import the pool.

# zpool export play
# zpool import -d /vdev play
# zpool list
NAME     SIZE   USED  AVAIL    CAP  HEALTH  ALTROOT
play     251M    91K   251M     0%  ONLINE  -
#

Obviously you will need down time to perform this operation since you need to fully export the pool (or reboot the system if operating on the root pool).