How to grow zfs on FreeBSD running inside VMWare

Live ZFS resizing inside VMWare should be possible, but there are several steps:

First you should resize your virtual disk in VMWare configuration. Recomendation is all virtual disks to be similar size for best performance in VMWare.

Then check what is disk configuration using:

# gpart show
=>       34  629145526  da0  GPT  (300G)
         34       1024    1  freebsd-boot  (512K)
       1058    4194304    2  freebsd-swap  (2.0G)
    4195362  624950198    3  freebsd-zfs  (298G)

=>       34  629145526  da1  GPT  (300G)
         34    1048576    1  freebsd-boot  (512M)
    1048610    4194304    2  freebsd-swap  (2.0G)
    5242914  623902646    3  freebsd-zfs  (297G)

=>       34  629145526  da2  GPT  (300G)
         34    1048576    1  freebsd-boot  (512M)
    1048610    4194304    2  freebsd-swap  (2.0G)
    5242914  623902646    3  freebsd-zfs  (297G)
# zpool status -v
  pool: zroot
 state: ONLINE
  scan: scrub in progress since Mon Apr  4 17:16:38 2022
	458G scanned at 670M/s, 319G issued at 466M/s, 458G total
	0B repaired, 69.54% done, 00:05:06 to go
config:

	NAME        STATE     READ WRITE CKSUM
	zroot       ONLINE       0     0     0
	  gpt/zfs0  ONLINE       0     0     0
	  gpt/zfs1  ONLINE       0     0     0
	  gpt/zfs2  ONLINE       0     0     0


VMware should notify guest OS that resize happened. You should be able to see that with `diskinfo -v /dev/daX` command. If it didn't happen - you'll probably need to execute at this point following commands:

camcontrol reprobe da0 ;\
camcontrol reprobe da1 ;\
camcontrol reprobe da2

Next it is good to made:

gpart recover da0 ; \
gpart recover da1 ; \
gpart recover da2

The new space will appear visible after partition 3 on each disk.

# gpart show
=>       34  629145526  da0  GPT  (300G)
         34       1024    1  freebsd-boot  (512K)
       1058    4194304    2  freebsd-swap  (2.0G)
    4195362  331348925    3  freebsd-zfs  (158G)
  335544287  293601273       - free -  (140G)

=>       34  629145526  da1  GPT  (300G)
         34    1048576    1  freebsd-boot  (512M)
    1048610    4194304    2  freebsd-swap  (2.0G)
    5242914  330301373    3  freebsd-zfs  (157G)
  335544287  293601273       - free -  (140G)

=>       34  629145526  da2  GPT  (300G)
         34    1048576    1  freebsd-boot  (512M)
    1048610    4194304    2  freebsd-swap  (2.0G)
    5242914  351272893    3  freebsd-zfs  (167G)
  356515807  272629753       - free -  (130G)

Next you should resize your partition with `gpart resize ...`. Hope it is the past one, otherwise this problem may have no easy solution. Please note that additional free space appears after partition 3. It should be doable for mounted filesystem. In my example commands are:

gpart resize -i 3 da0 ; \
gpart resize -i 3 da1 ; \
gpart resize -i 3 da2

Next you should make ZFS to resize with `zpool online -e ...`. So in the example you must execute following commands:

zpool online -e zroot gpt/zfs0 ; \
zpool online -e zroot gpt/zfs1 ; \
zpool online -e zroot gpt/zfs2

It’s good to execute `zpool scrub zroot`.