Skip to main content

FreeBSD - growfs to increase partition virtual instance

Need to increase capacity on OPNSense freebsd box running as VM on Proxmox

First assign new disk space on proxmox, resize disk and increase capacity, make sure to backup everything before proceeding.

##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.

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