OPNSense Resize Disk Space

After while of using OPNSense firewall, i needed to resize my disk on ESXi and scale up the disk space for OPNSense.

After investigating this issue online, i found that i need to resize the disk from command line and i could not find one clear source to help me on this task.

The problem for me was the swap partition, cause the new free space appended on the end of the disk and i can’t used it because the swap partition is on my way. To scale up root partition the free space should be continuous and available after the target partition.

I had two options

  • Remove the swap partition (Not recommended)
  • Move the swap partition to the end of the disk (Recommended)

In this article i will describe how to move the swap partition to the end of the disk and scale up root partition for OPNSense.

The steps don’t require shut downing the firewall or use live usb, it’s straight forward steps while the firewall is operational, but be caution and alert to what you are doing.


  • Increase virtual machine disk size from ESXi vShpere Client (Web or Desktop) to the desired new larger size.
  • Connect to OPNSense console and login with root account.
  • Choose shell command (Num 8) to access shell and use freeBSD commands.
  • Start using these commands in sequence [<# = Comments>, so use only commands]
gpart show #get the available partitions
#after executing show command you gonna get this info 
#disk = da0
#freebsd-usf = get id (~3)
#freebsd-swap = get id (~4)
gpart recover da0 #recover the new space added
gpart show #check the new free space is added
#let's remove swap from current location
swapoff -a #disable swap on freebsd
gpart delete -i 4 da0 #freebsd-swap id = 4
gpart show #get free space sector start and size in notepad
#lets move swap to the end of disk (download the calculator down to help and use sector start & free size in calculator)
gpart add -t freebsd-swap -b <Swap Start (Sector)> da0 #get the swap start from calculator and replace in the placeholder.
gpart show #confirm the swap place and size is correct (if something wrong, delete it and recalculate and repeat the previous step)
gpart modify -i 4 -l swapfs da0 #assign label for the new partition for opnsense booting
swapon /dev/gpt/swapfs #start the swapping on the system
#we moved now the swap to the end of disk, let's increase root partition size
gpart resize -i 3 da0 #freebsd-usf id = 3
gpart show #check the resize is done
growfs /dev/gpt/rootfs #scanning the new space added to the partition mount.
exit #exit shell
  • After these steps go open OPNSense admin panel and check the dashboard to confirm swap and disk space is configured correctly.
  • You can reboot the firewall now to check that swap is starting with the booting.

2 Comments on “OPNSense Resize Disk Space

  1. Thanks for this guide. Was continually running into swap size issues with Suricata and Sensei, and services would stop with out of swap space errors. Instead of resizing an existing virtual drive, I just created a new 10G virtual drive, then was able to GPT format it
    gpart create -s GPT da1

    Then create the partition on the disk
    gpart add -t freebsd-swap da1

    Then label the GPT partition, as in your guide
    gpart modify -i 1 -l swapfs da1

    To persist across reboots, I did need to add the entry to /etc/fstab
    /dev/gpt/swapfs none swap sw 0 0

    Liked by 3 people

  2. I having challengies with this comman:
    gpart add -t freebsd-swap -b da0


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: