Expanding Disk Space

by Tykling


24. jan 2020 13:00 UTC


Sometimes a VM is low on disk and I add some more in the hypervisor. After resizing the block device I still need to resize the GPT partition with gpart and I need to tell ZFS about it. This blog post explains how to extend the partition as well as the ZFS VDEV. This is mostly relevant in virtual machines, but the zpool online -e trick can also be used when replacing physical disks with larger ones in a real server.

The server ran out of diskspace during a buildworld so it is very low on space:

[root@certgrinder ~]# zfs list
NAME                          USED  AVAIL  REFER  MOUNTPOINT
zroot                        13.5G  65.6M    96K  /zroot
zroot/ROOT                   11.9G  65.6M    96K  none
zroot/ROOT/12-STABLE-357075  11.9G  65.6M  11.9G  /
zroot/tmp                     104K  65.6M   104K  /tmp
zroot/usr                    1.53G  65.6M    96K  /usr
zroot/usr/home               14.9M  65.6M  14.9M  /usr/home
zroot/usr/ports                96K  65.6M    96K  /usr/ports
zroot/usr/src                1.52G  65.6M  1.52G  /usr/src
zroot/var                    4.29M  65.6M    96K  /var
zroot/var/audit                96K  65.6M    96K  /var/audit
zroot/var/crash                96K  65.6M    96K  /var/crash
zroot/var/log                3.12M  65.6M  3.12M  /var/log
zroot/var/mail                808K  65.6M   808K  /var/mail
zroot/var/tmp                 104K  65.6M   104K  /var/tmp
[root@certgrinder ~]# zpool list
NAME    SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
zroot  14.0G  13.5G   512M        -         -    86%    96%  1.00x  ONLINE  -

After shutting down the VM and enlarging the block device I can see the extra free space with gpart show:

[root@certgrinder ~]# gpart show
=>      40  67108791  da0  GPT  (32G)
        40      1024    1  freebsd-boot  (512K)
      1064       984       - free -  (492K)
      2048   4194304    2  freebsd-swap  (2.0G)
   4196352  29358040    3  freebsd-zfs  (14G)
  33554392  33554439       - free -  (16G)

With the gpart resize subcommand the default is to use all unused space if the -s argument is not given:

[root@certgrinder ~]# gpart resize -i 3 da0
da0p3 resized
[root@certgrinder ~]# gpart show
=>      40  67108791  da0  GPT  (32G)
        40      1024    1  freebsd-boot  (512K)
      1064       984       - free -  (492K)
      2048   4194304    2  freebsd-swap  (2.0G)
   4196352  62912479    3  freebsd-zfs  (30G)

Now the partition is resized but ZFS still doesn't now about it. This can be remedied with the -e flag to the zpool online subcommand:

[root@certgrinder ~]# zpool list
NAME    SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
zroot  14.0G  13.5G   511M        -         -    86%    96%  1.00x  ONLINE  -
[root@certgrinder ~]# zpool status
  pool: zroot
 state: ONLINE
  scan: scrub repaired 0 in 0 days 00:02:15 with 0 errors on Fri Jan 24 03:58:03 2020
config:

        NAME        STATE     READ WRITE CKSUM
        zroot       ONLINE       0     0     0
          da0p3     ONLINE       0     0     0

errors: No known data errors
[root@certgrinder ~]# zpool online -e zroot da0p3
After informing ZFS about the enlarged block device the extra space is now usable:
[root@certgrinder ~]# zpool list
NAME    SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
zroot  30.0G  13.5G  16.5G        -         -    40%    44%  1.00x  ONLINE  -
[root@certgrinder ~]# zfs list
NAME                          USED  AVAIL  REFER  MOUNTPOINT
zroot                        13.5G  15.6G    96K  /zroot
zroot/ROOT                   11.9G  15.6G    96K  none
zroot/ROOT/12-STABLE-357075  11.9G  15.6G  11.9G  /
zroot/tmp                     104K  15.6G   104K  /tmp
zroot/usr                    1.53G  15.6G    96K  /usr
zroot/usr/home               14.9M  15.6G  14.9M  /usr/home
zroot/usr/ports                96K  15.6G    96K  /usr/ports
zroot/usr/src                1.52G  15.6G  1.52G  /usr/src
zroot/var                    4.29M  15.6G    96K  /var
zroot/var/audit                96K  15.6G    96K  /var/audit
zroot/var/crash                96K  15.6G    96K  /var/crash
zroot/var/log                3.12M  15.6G  3.12M  /var/log
zroot/var/mail                808K  15.6G   808K  /var/mail
zroot/var/tmp                 104K  15.6G   104K  /var/tmp
[root@certgrinder ~]# 

All done!

Search this blog

Tags for this blogpost