How to Resize a Disk in FreeBSD

Updated on November 21, 2023
How to Resize a Disk in FreeBSD header image

The FreeBSD operating system utilizes UFS (Unix File System) for its root partition's file system; otherwise known as freebsd-ufs

In the event of an upgraded disk size, we will illustrate how to expand this file system.

Prerequisites

1) To follow this tutorial, deploy one of the following:

OR

We utilized the following plan to begin our deployment:

CPU:        1 vCore
RAM:        1024 MB
Storage:    25 GB SSD

2) Prior to upgrading your intance, confirm its current disk allocation & partition table:

# df -h  
Filesystem         Size    Used   Avail Capacity  Mounted on
/dev/ufs/rootfs     24G    924M     21G     4%    /
devfs              1.0K    1.0K      0B   100%    /dev

# gpart show
=>      40  52428720  vtbd0  GPT  (25G)
        40      1024      1  freebsd-boot  (512K)
      1064  52427696      2  freebsd-ufs  (25G)

3) Upgrade your instance's plan:

  1. Visit your Vultr management page
  2. Select the instance that you'd like to upgrade.
  3. Choose the "Settings" link near the top of the page.
  4. Click the "Change Plan" link on the Side to show a dropdown menu of available upgrade choices.

In this case, we upgraded our plan to the following:

CPU:        1 vCore
RAM:        2048 MB
Storage:    40 GB SSD

##1. Confirm New Disk Space

Although the disk allocation appears the same at first, gpart illustrates a change::

# df -h
Filesystem         Size    Used   Avail Capacity  Mounted on
/dev/ufs/rootfs     24G    924M     21G     4%    /
devfs              1.0K    1.0K      0B   100%    /dev

# gpart show
=>      40  52428720  vtbd0  GPT  (40G) [CORRUPT]
        40      1024      1  freebsd-boot  (512K)
      1064  52427696      2  freebsd-ufs  (25G)

##2. Recover the Corrupt Partition

# gpart recover vtbd0
vtbd0 recovered

# gpart show
=>      40  83886000  vtbd0  GPT  (40G)
        40      1024      1  freebsd-boot  (512K)
      1064  52427696      2  freebsd-ufs  (25G)
  52428760  31457280         - free -  (15G)

##3. Resize the freebsd-ufs Partition

WARNING!!!
Per the FreeBSD Handbook:

There is risk of data loss when modifying the partition table of a mounted file system. It is best to perform the following steps on an unmounted file system while running from a live CD-ROM or USB device.

Since this is a recently deployed instance, there is no sensitive data to backup; however, in the event of upgrading an instance currently in production, its best practice to perform an offsite backup prior to making any changes to the partition table.

Once you're ready to proceed, do the following:

# gpart resize -i 2 vtbd0
vtbd0p2 resized

# gpart show
=>      40  83886000  vtbd0  GPT  (40G)
        40      1024      1  freebsd-boot  (512K)
      1064  83884976      2  freebsd-ufs  (40G)

##4. Grow the UFS File System

In order to expand the freebsd-ufs or /dev/vtbd0p2 paritition, start the growfs service:

# service growfs onestart
Growing root partition to fill device
vtbd0 recovering is not needed
vtbd0p2 resized
super-block backups (for fsck_ffs -b #) at:
 53224896, 54248448, 55272000, 56295552, 57319104, 58342656, 59366208, 60389760, 61413312,
 62436864, 63460416, 64483968, 65507520, 66531072, 67554624, 68578176, 69601728, 70625280,
 71648832, 72672384, 73695936, 74719488, 75743040, 76766592, 77790144, 78813696, 79837248,
 80860800, 81884352, 82907904

Alternatively, you can run the following command.

growfs /dev/ufs/rootfs

##5. Confirm the Changes

# gpart show
=>      40  83886000  vtbd0  GPT  (40G)
        40      1024      1  freebsd-boot  (512K)
      1064  83884976      2  freebsd-ufs  (40G)

# df -h
Filesystem         Size    Used   Avail Capacity  Mounted on
/dev/ufs/rootfs     39G    924M     35G     3%    /
devfs              1.0K    1.0K      0B   100%    /dev