Growing / expanding ZFS pools on Linux

So you’ve installed ZFS for Linux on your virtual server, and then ran out of space. Not a problem – it’s super easy to upgrade to the next size up. But wait… what about the ZFS zpool? Will that resize?

The answer is yes, but, you need a little trickery to make it work. Here’s how you do it:

Upgrade your VM storage or plan to the next size up

Typically you’ll need to power off and power on the VM to apply the storage upgrade

Once you’ve booted back up, ensure your disk upgrade went through successfully:
log in via SSH and run df -h and check the disk size

Now we will list the partitons on the server and find out which one ZFS is using:
let’s use parted -l

Once you’ve found your partition, use parted to resize it. Assuming it is vda and partition 2:
execute parted /dev/vda resizepart 2 100%

Finally, we want to use ZFS expand to make use of the extra space:
use zpool online -e zpool /dev/vda2 altering the zpool name and partition accordingly.

Another answer for resize disk in linux use parted

It seems that different versions of parted behave quite differently, so this is applicable to the parted version 3.*, that comes at least with CentOS7 and CentOS8.

  1. Make sure that OS is aware of the disk size increase since the last scan(reboot):
# echo 1 > /sys/block/sda/device/rescan
  1. Check that there is free space available after the last partition:
# parted -s -a opt /dev/sda "print free"
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  32.2GB  31.1GB  primary               lvm
        32.2GB  53.7GB  21.5GB           Free Space
  1. Resize last partition to the maximum available disk space:
# parted -s -a opt /dev/sda "resizepart 2 100%"
# echo $?
0

This operation doesn’t have any indication of it’s success except the exit code.

  1. You can verify that partition size was increased by repeating:
# parted -s -a opt /dev/sda "print free"
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  53.7GB  52.6GB  primary               lvm

As a bonus you can fit all this into one command line(don’t miss step 0):

# parted -s -a opt /dev/sda "print free" "resizepart 2 100%" "print free"
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  32.2GB  31.1GB  primary               lvm
        32.2GB  53.7GB  21.5GB           Free Space

Model: VMware Virtual disk (scsi)
Disk /dev/sda: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  53.7GB  52.6GB  primary               lvm