How to Increase the Size of a FreeBSD Disk

By | 2019-12-21

I am assuming you just increased the size of a disk on a virtualization platform such as VMware or VirtualBox. Perhaps it is a SAN device. Either way, you will follow the same process. If your machine is on a SAN or it is a virtual machine running on a hypervisor that supports online resizing, you don’t even need to reboot.

If you are growing a ZFS pool that is using mirroring or RAIDZ, you must increase the size of all disks before ZFS will use the additional storage.

On the example machine there is a single ZFS pool called zroot. The disk was expanded from 10GB to 15GB.

# zpool list
NAME    SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
zroot  7.94G  6.06G  1.88G        -         -    69%    76%  1.00x  ONLINE  -
# gpart show
=>      40  20971440  da0  GPT  (10G)
        40      1024    1  freebsd-boot  (512K)
      1064       984       - free -  (492K)
      2048   4194304    2  freebsd-swap  (2.0G)
   4196352  16773120    3  freebsd-zfs  (8.0G)
  20969472      2008       - free -  (1.0M)

Notice how I have a single disk, da0, with 3 partitions. Also notice how partition 3 has my ZFS pool and is at the end of the disk.

If you are able to resize the disk while the machine is running, you need to instruct the kernel to check the device for changes and update its internal structures with the results.

# camcontrol reprobe da0
# gpart show da0
=>      40  31457200  da0  GPT  (15G)
        40      1024    1  freebsd-boot  (512K)
      1064       984       - free -  (492K)
      2048   4194304    2  freebsd-swap  (2.0G)
   4196352  16773120    3  freebsd-zfs  (8.0G)
  20969472  10487768       - free -  (5.0G)

Notice how I now have 5GB of free space at the end of da0.

Now resize the partition with gpart:

# gpart recover da0
da0 recovering is not needed
# gpart resize -i 3 da0
da0p3 resized

If the partition you are trying to grow is in the middle of the disk, follow these instructions in the FreeBSD handbook. Be careful if you do this, a mistake can lead to data loss.

Now expand the ZFS pool with zpool:

# zpool online -e zroot da0p3
# zpool list
NAME    SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
zroot  12.9G  6.06G  6.88G        -         -    42%    46%  1.00x  ONLINE  -

If you are using UFS, use growfs instead of zpool. I followed the same procedure as above to expand partition 1 on ada1.

# growfs /dev/ada1p1
It's strongly recommended to make a backup before growing the file system.
OK to grow filesystem on /dev/ada1p1 from 2.0GB to 5.0GB? [yes/no] yes
super-block backups (for fsck_ffs -b #) at:
 4194752, 5243392, 6292032, 7340672, 8389312, 9437952

References