Skip to main content

Expand a RAIDZ Pool by Adding a Disk

This guide adds one more disk to an existing RAIDZ vdev, for example to grow a 3-disk raidz1 into a 4-disk raidz1. This feature is called RAIDZ expansion. The pool stays online while ZFS spreads the existing data over the new disk. By the end the pool has more usable space, and you will have verified that the data is still correct.

The commands work on any OS that runs OpenZFS 2.3 or later (Proxmox VE 9, Ubuntu, Debian, TrueNAS, and so on).

What RAIDZ expansion does not do​

  • It does not change the parity level. A raidz1 stays raidz1, it cannot become raidz2.
  • Data written before the expansion keeps its old ratio of data to parity (for example 2 data + 1 parity). Only data written after the expansion uses the new, wider stripe (3 data + 1 parity). So the new space is available, but old data does not get smaller on its own.
  • It adds one disk at a time. To add more disks, wait until the first expansion is finished, then repeat the procedure.
info

This is a one-way change. You cannot remove the disk from the vdev again after you attach it. Decide before you start.

Prerequisites​

  • root access on a system with OpenZFS 2.3 or later.
  • A ZFS pool with a raidz1, raidz2, or raidz3 vdev, in ONLINE state.
  • An empty disk that is the same size as the smallest disk in the vdev or larger.
  • A backup of the data that matters. The expansion is a long and heavy operation on all disks, and raidz1 has no room for a second failure.
warning

The pool and its disks stay in use during the expansion, but everything is slower and it takes hours on large HDDs. Plan it for a quiet period.

Set the names​

Define the names once, so you can copy and paste the rest of the commands. Replace the values with your own. For VDEV, copy the name of the raidz group exactly as zpool status shows it:

POOL="tank"
VDEV="raidz1-0"
NEW_DISK="/dev/disk/by-id/<new-disk-id>"
tip

These variables only exist in the current shell. If you lose the session (for example the SSH connection drops), run the lines again before you continue.

Pre-check​

Run these commands before you touch anything. Confirm each result matches what is described. If one does not, stop and fix it first.

Check the OpenZFS version​

zfs version

Expected: both the zfs and the zfs-kmod version are 2.3 or later. If they are 2.2.x, RAIDZ expansion is not available.

Check the feature flag​

zpool get feature@raidz_expansion "$POOL"

Expected: the value is enabled or active. If it is disabled, you will turn it on in the procedure.

warning

Turning on a feature flag cannot be undone. A pool that uses RAIDZ expansion cannot be imported by a system with an older OpenZFS that does not know the feature.

Check the pool health and find the vdev​

ZPool Before

zpool status -v "$POOL"

Expected: the pool state is ONLINE, every disk is ONLINE with 0 in READ, WRITE, and CKSUM, and errors: No known data errors. Check that the name of the raidz group (for example raidz1-0) matches VDEV.

Check that no scrub or resilver is running​

zpool status "$POOL" | grep -A3 'scan:'

Expected: no in progress message. Wait until a running scrub or resilver is done.

Check the last scrub and the SMART data​

The last scrub should say 0B repaired and 0 errors. If it says something like repaired 13.3M, one of the disks returned bad data and ZFS had to fix it. Check the SMART data of every disk in the vdev before you start, because the expansion reads and writes all of them:

smartctl -H /dev/disk/by-id/<disk-id>
smartctl -A /dev/disk/by-id/<disk-id> | grep -E 'Reallocated_Sector_Ct|Current_Pending_Sector|Offline_Uncorrectable|UDMA_CRC_Error_Count'

Expected: PASSED, and 0 for the pending and uncorrectable counters. If a disk looks weak, replace it first, then expand.

Check the new disk​

Find the new disk and its stable ID:

ls -l /dev/disk/by-id/ | grep -v -- '-part'

Use the ID under /dev/disk/by-id/ (for example ata-...), not /dev/sdX. Put it in NEW_DISK, then check it:

smartctl -H "$NEW_DISK"
lsblk -b -o NAME,SIZE,MODEL,SERIAL

Expected: SMART says PASSED, and the size in bytes is the same or larger than the smallest disk in the vdev.

Record the current size​

You will compare against it in the post-check.

zpool list -v "$POOL"
zfs list "$POOL"

Procedure​

Follow the sections in order.

Enable the feature​

Skip this step if the feature is already enabled or active.

zpool set feature@raidz_expansion=enabled "$POOL"
zpool get feature@raidz_expansion "$POOL"

Expected: the value is enabled.

tip

zpool upgrade "$POOL" also works, but it turns on every available feature at once. Turning on only this one keeps the change small.

Wipe the new disk​

If the disk is brand new, you can skip this. If it was used before, this removes old partition tables, filesystem signatures, and ZFS labels:

wipefs -a "$NEW_DISK"
warning

This step is destructive and cannot be undone. Make sure NEW_DISK is the new disk and not a disk of the pool.

Attach the disk​

zpool attach "$POOL" "$VDEV" "$NEW_DISK"

The command prints nothing when it works and returns to the prompt. The expansion starts right away and the pool stays online.

info

Do not add -f just to make an error go away. If ZFS refuses with a message about an existing filesystem or pool, the disk is not clean or is the wrong disk. Check it first.

Watch the expansion​

ZPool After

zpool status "$POOL"

Expected: the new disk is listed inside the raidz group, and there is an expand: line with the progress, the speed, and the estimated time. For example, on a pool of 4x 1 TB HDDs with 1.65 TB of data:

pool: tank
state: ONLINE
scan: scrub repaired 0B in 00:33:06 with 0 errors on ...
expand: expansion of raidz1-0 in progress since ...
104G / 1.65T copied at 253M/s, 6.17% done, 01:46:54 to go
config:

NAME STATE READ WRITE CKSUM
tank ONLINE 0 0 0
raidz1-0 ONLINE 0 0 0
ata-<disk-id-1> ONLINE 0 0 0
ata-<disk-id-2> ONLINE 0 0 0
ata-<disk-id-3> ONLINE 0 0 0
ata-<new-disk-id> ONLINE 0 0 0

To follow it live:

watch -n 30 zpool status "$POOL"

Press Ctrl+C to leave watch. The expansion keeps running without you.

While it runs:

  • Do not start a scrub, a replace, or zpool add, and do not start another expansion on the same vdev.
  • Watch the READ, WRITE, and CKSUM columns. If a number grows on one disk, check that disk with smartctl -a.
tip

The time depends on how much data is stored in the vdev, not on the size of the new disk. In the example above it took about 2.5 hours for 1.65 TB. A reboot or a power loss in the middle is safe: ZFS saves its progress and continues by itself when the pool is imported again.

When it is done, the expand: line says expanded raidz1-0 copied ... in ...:

expand: expanded raidz1-0 copied 1.65T in 02:25:18, on ...

Post-check​

Run these after the expansion is finished to confirm that the procedure succeeded.

Check the pool​

zpool status -v "$POOL"

Expected: the pool is ONLINE, every disk (including the new one) is ONLINE with 0 in READ, WRITE, and CKSUM, the expand: line says it is finished, and errors: No known data errors.

Check the capacity​

zpool list -v "$POOL"
zfs list "$POOL"

Expected: the size grew by about one disk. For example, going from 3x 1 TB to 4x 1 TB in a raidz1:

BeforeAfter
Raw size (zpool list)about 2.7 TiBabout 3.6 TiB
Usable size (zfs list)about 1.8 TiBabout 2.7 TiB

A 1 TB disk is about 931 GiB, so the numbers are a bit lower than the marketing size. zpool list shows the raw size, including parity. zfs list shows the space you can actually use. Old data still uses the old ratio, so the free space does not grow as much as the math suggests until that data is rewritten.

Run a scrub​

A scrub reads every block and checks it against its checksum. It proves that all the data is correct on the new layout:

zpool scrub "$POOL"
zpool status "$POOL"

Expected: the scrub finishes with 0B repaired and 0 errors. On HDDs it takes a few hours for a pool with a lot of data. The scanned number grows fast at the start, but the issued number is the real read speed, and the percentage follows issued.

Troubleshooting​

SymptomCause and fix
zpool attach is refused, and feature@raidz_expansion is missing or disabledOpenZFS is older than 2.3, or the feature is not turned on. Check zfs version, then run zpool set feature@raidz_expansion=enabled "$POOL".
no such device in poolVDEV does not match the name in zpool status. Copy the name of the raidz group exactly, for example raidz1-0.
invalid vdev specification or contains a valid ZFS labelThe new disk still has old data or labels. Run wipefs -a "$NEW_DISK" again. Use -f only when you are sure it is the right disk.
zpool attach is refused because the pool is DEGRADED, or a resilver or another expansion is runningThe vdev must be healthy and idle. Fix the pool or wait until it is finished, then try again.
The expansion is very slow, or the expand: line does not moveNormal for large HDDs, but check dmesg -T for I/O errors or link resets, and check that all disks are ONLINE.
READ, WRITE, or CKSUM grow on one disk during the expansionThat disk, or its cable or port, is weak. Check smartctl -a and dmesg -T. If the disk fails, replace it with zpool replace.
The pool is missing after a reboot or a power lossRun zpool import to list importable pools, then zpool import "$POOL". The expansion continues by itself after the import.

Rollback​

RAIDZ expansion cannot be undone. Once the disk is attached, it is part of the vdev, and ZFS cannot remove a disk from a raidz vdev. You also cannot cancel a running expansion.

If the new disk turns out to be bad, replace it like any other failed disk:

zpool replace "$POOL" "$NEW_DISK" /dev/disk/by-id/<other-disk-id>

If you want the old layout back, back up the data, destroy the pool, and create it again.

warning

This is why the pre-check and the backup matter. Do not start the expansion on a pool that has no backup of its important data.

What's next​

The pool is bigger and healthy. To add more capacity later, repeat this guide with another disk, one at a time. To find the next failure early, run a scrub on a schedule and keep an eye on the SMART data of the disks.