5

I've been testing pfsense on ESXi for a while. And now I'm almost running out of space. Currently it holds around 30GB and I would like to expand it to 150GB as I'm planning on installing squid for caching. So far what I did is;

  • Tried to expand the disk on ESXi for pfsense (its a thick provisioned drive) which expanded and showing as free.
  • Tried gparted by booting and iso into the pfsense VM which showed that the installed partition is an unknown one & the unallocated didn't even show options to resize (guess it is because pfsense uses UFS file system)
  • Tried installing a fresh copy which was successful but the UI was pretty strange as I couldn't see the total usage, memory usage.. etc.. not even the status bars properly.

My pfsense is making a lot of trouble. All I need is to expand the disk on the old pfsense if possible else a fix for the new one (where the GUI looks pretty sluggish).

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
AzkerM
  • 153
  • 1
  • 2
  • 8
  • It might be possible to a add a new partition/filesystem, then moving/linking things there. The easier way is still getting your configuration (`config.xml`) and re-install everything properly. – Ouki Feb 26 '14 at 13:30
  • It might even be possible to grow the fs through `gpart` and `growfs` ... but re-installing everything properly is still the easiest way. – Ouki Feb 26 '14 at 13:43
  • It is always not a good option to keep on installing each time I have issues. Better the hard way where the easiest will be always easy. – AzkerM Feb 27 '14 at 05:08
  • In that case, it means anyway downtime. Re-installing is more simple and quicker than doing it the hard way. pfSense is not a full-grown system, the configuration is just 1 file to backup and restore. (Anyway I did the exercice and will post how to grow fs) – Ouki Feb 27 '14 at 10:21
  • Sure! BTW, currently the network traffic is being routed through MS forefront TMG & I'm testing pfsense in parallel; having few users. – AzkerM Feb 27 '14 at 10:59

1 Answers1

6

pfSense is currently based on FreeBSD 8.x. The ability to grow a UFS filesystem live is only coming with FreeBSD 10.x, so all this should be done from a rescue/install mode.

First do a backup of your config.xml file !

To grow the pfSense root filesystem you must first properly re-size the BSD partition scheme (aka "bsd slices"):

  • re-size the BSD partition

    On console mode or through ssh, start a Shell (example is only 4GB install with 4GB free disk):

    [admin]:gpart show

    =>      63  16777153  ad0  MBR  (8.0G)
            63   8388513    1  freebsd  [active]  (4G)
       8388576   8388640       - free -  (4.0G)
    
    =>      0  8388513  ad0s1  BSD  (4G)
            0       16         - free -  (8.0k)
           16  7339921      1  freebsd-ufs  (3.5G)
      7339937  1048576      2  freebsd-swap  (512M)
    

    (assuming your disk is seen as ad0)

    [admin]:gpart resize -i 1 ad0

    ad0s1 resized
    

    Due to a bug in gpart regarding the old MBR partitioning schemes, we need to force a global size update, as the MBR is still having the old global size.

    Get the freebsd real partition size (2nd column of the gpart show ad0 output):

    [admin]:gpart show ad0

    =>      63  16777153  ad0  MBR  (8.0G)
            63  16777152    1  freebsd  [active]  (8G)
      16777215         1       - free -  (512B)
    

    Using bsdlabel to edit this value onto the zise of c: line:

    [admin]:bsdlabel -e /dev/ad0s1

    # /dev/ad0s1:
    8 partitions:
    #          size     offset    fstype   [fsize bsize bps/cpg]
      a:   15728640         16    4.2BSD        0     0     0
      b:    1048496   15728656      swap
      c:    8388513          0    unused        0     0     # "raw" part, don't edit
    

    So edit it to match this number; in our example: 16777152 (editor is vi):

    # /dev/ad0s1:
    8 partitions:
    #          size     offset    fstype   [fsize bsize bps/cpg]
      a:   15728640         16    4.2BSD        0     0     0
      b:    1048496   15728656      swap
      c:   16777152          0    unused        0     0     # "raw" part, don't edit`
    

    The partitions have now been re-sized properly.

  • Growing pfSense root filesystem

    As the default disk partioning is setting a swap at the end of the disk, we must first note down its size and remove it before growing the root filesystem:

    (Just be sure it the 2nd filesystem of your ad0s1 - 3rd column value in gpart show output)

    [admin]:gpart delete -i 2 ad0s1

    Re-sizing our root partition to all, but the swap partition size (gpart -s option do accept only integer values, so 7.5G = 7680M):

    [admin]:gpart resize -i 1 -s 7680M ad0s1

    ad0s1a resized
    

    [admin]:growfs /dev/ad0s1a

    We strongly recommend you to make a backup before growing the Filesystem
    
     Did you backup your data (Yes/No) ? Yes
    new file systemsize is: 3932160 frags
    Warning: 302144 sector(s) cannot be allocated.
    growfs: 7532.5MB (15426496 sectors) block size 16384, fragment size 2048
            using 41 cylinder groups of 183.72MB, 11758 blks, 23552 inodes.
    super-block backups (for fsck -b #) at:
     7525280, 7901536, 8277792, 8654048, 9030304, 9406560, 9782816, 10159072, 10535328, 10911584,
     11287840, 11664096, 12040352, 12416608, 12792864, 13169120, 13545376, 13921632, 14297888,
     14674144, 15050400
    

    And re-creating the swap partition:

    [admin]:gpart add -t freebsd-swap ad0s1

    ad0s1b added
    

    Done. Our partition table is now as follow and the root filesystem has been properly expanded to use its full partition:

    [admin]:gpart show

    =>      63  16777153  ad0  MBR  (8.0G)
            63  16777152    1  freebsd  [active]  (8G)
      16777215         1       - free -  (512B)
    
    =>       0  16777152  ad0s1  BSD  (8G)
             0        16         - free -  (8.0k)
            16  15728640      1  freebsd-ufs  (7.5G)
      15728656   1048496      2  freebsd-swap  (512M)
    

For more information about FreeBSD gpart and growfs commands:

Note: gpart bug regarding the old MBR partitioning scheme is still true as of FreeBSD-10.0.

Ouki
  • 5,842
  • 4
  • 23
  • 31
  • +1 for the detailed explanation.. Let me check this & post back soon. :) – AzkerM Mar 01 '14 at 05:00
  • 1
    Good answer. Lacking some troubleshooting info. Here is a link that will complete this answer for people getting stuck with "operation not permitted error" https://forum.pfsense.org/index.php?topic=93967.10;wap2 – iamauser Sep 02 '16 at 20:50