OPNsense Forum

Archive => 20.7 Legacy Series => Topic started by: DanMc85 on September 22, 2020, 04:32:13 pm

Title: Resize OPNSense Partition
Post by: DanMc85 on September 22, 2020, 04:32:13 pm

Question about OPNSense Partition Expansion. 

I have the paid Business Edition OPNSense and I deployed it to VMWware using the OVF Package.

However, the deployment has a small primary partition size.

If I resize the allocated partition size in vCenter. Is there a simple way to expand the partition size in the FreeBSD shell for OPNsense?  Short of reinstalling everything including plug ins and reimporting config on a custom install.
Title: Re: Resize OPNSense Partition
Post by: franco on September 22, 2020, 04:43:28 pm
Hi,

If the partition layout is simple using the growfs hook should work:

# touch /.probe.for.growfs.nano

Shut down, adjust disk size, boot up.


Cheers,
Franco
Title: Re: Resize OPNSense Partition
Post by: bunchofreeds on September 22, 2020, 10:41:06 pm
A walk-through of this process would be great for OPNsense users!

I had the same issue a while back and after reading a load on FreeBSD (I'm noob to it) and how to resize, testing and making changes, I ended up reinstalling OPNsense as a new VM with the size I needed.

Resizing the primary partition in FreeBSD is a dark art to me. There's loads of info for resizing other partitions...
Title: Re: Resize OPNSense Partition
Post by: franco on September 23, 2020, 10:26:17 am
As long as there is only one partition and the memory added to the disk is contiguous behind the partition the growfs method works. There is no dark magic involved. For further reference this man page can help.

https://www.freebsd.org/cgi/man.cgi?growfs(8)

Or this FreeBSD handbook entry if you will:

https://www.freebsd.org/doc/handbook/disks-growing.html


Cheers,
Franco
Title: Re: Resize OPNSense Partition
Post by: allebone on December 07, 2020, 06:18:37 am
I was able to do this although not being an expert the procedure was not perfect in the sense that some space would not grow and I cant really explain why.

What I did was the following.
I had a 10GB disk. I wanted to grow it to 20GB. In KVM/Your choice of Hypervisor I increased the disk allocation to 20GB with OPNsense turned off.

Now after booting OPNsense I typed "gpart show"
This displayed 2 areas for me. An MBR section (vtbd0) and a BSD device (vtbd0s1) both 10GB in size.
Under vtbd0 I had one partition labelled '1' which is 10GB right before the free space.
Similarly under the BSD section I had one partition labelled '1' right before the free space.

I could also see 10 GB of free unallocated space in each.

First I typed

"gpart resize -i 1 -s 19G vtbd0"

When I tried 20G it said there was not enough space and I did not know how to extend it to the last GB so I just used 19G. In my case I was using a dynamic disk so the hypervisor only grows the disk as used anyway. I imagine you could spend more time here getting every last byte but I did not need to.

This grew the MBR section to 19G. The -i 1 signifies the partition number. I wanted partition 1 to increase. the -s 19G is the size to grow to.

I then typed

"gpart resize -i 1 vtbd0s1"

This grew the BSD section to fill the space I had allocated within the MBR (I think).

'gpart show' now showed both sections grown to 19GB.

I then typed 'df -h' to list my mountpoints and the current size (not grown yet).

I then wanted the specific mount point of my choosing to take up the new space.

"growfs /dev/ufs/OPNsense"

This grew the partition. i got some warnings but all seemed fine (would recommend you have a backup obviously).

Then 'df -h' now showed disk was bigger. However for some reason I only got a 18GB as the size listed by df -h.

I could not explain this discrepancy, however everything seemed to be working.

I then rebooted into single user mode and did an fsck /dev/ufs/OPNsense and let it run. It didnt find any issue.

I rebooted OPNsense into normal mode and it seemed to be fine, however as I mentioned it displays I have a partition of 18GB despite growing it to 19GB and allocating 20GB.

So the procedure was possible and I dont have any issues, all is working normally and I did get extra space but somehow couldnt allocate all the space I wanted and lost 1GB and 1GB again during the procedure. This is no doubt due to my ignorance of the perfect settings to type when performing the procedure.

In terms of stability and functionality all seems totally fine, no errors, no problems, rebooted multiple times without an issue. As I mentioned its a dynamically expanding virtual disk so Im not really worried that the last 2GB couldnt be grown, and probably I can just grow it again if I need but seems like the procedure would need a bit of tweaking before its perfect. This was what I managed on my own just reading the man pages for freebsd.

Pete
Title: Re: Resize OPNSense Partition
Post by: allebone on December 07, 2020, 02:24:49 pm
Took a look at this again when i woke up. I think the mistake I made was specifying a size. Reading the manpages I see this is not required and you can let the system fill up all the contiguous space if no size is specified.

Today I did the following:

gpart show
(attachment 1)

gpart resize -i 1 vtbd0
gpart resize -i 1 vtbd0s1
gpart show

(-i 1 is partition 1 in both cases see attachment 2)

df -h
growfs /dev/ufs/OPNsense
df -h

(attachment 3)

I believe now at this point the 19GB shown as the disk size is a visual error as when i run df -m It shows the disk is 19831MB so probably just shows 19GB in the webGUI due to truncation:

(attachment 4)

I did not reboot and all seems working right now. Will report back if anything ever breaks but I dont see any reason it will.

If anyone disagrees let me know :)

Kind regards
Peter

Title: Re: Resize OPNSense Partition
Post by: miruoy on January 21, 2021, 08:14:10 pm
Today I did the following:
Peter

Good howto. I've just used your steps to resize my root partition. Worked flawlessly. Maybe with a little doc-fu it can be added to the docs or pinned?
Title: Re: Resize OPNSense Partition
Post by: allebone on January 21, 2021, 10:17:11 pm
Today I did the following:
Peter

Good howto. I've just used your steps to resize my root partition. Worked flawlessly. Maybe with a little doc-fu it can be added to the docs or pinned?

No worries, Nothing broke for me still since I did this and I just updated OPNsense yesterday to the latest version so its still in use and working fine.
Title: Re: Resize OPNSense Partition
Post by: gary201 on October 11, 2021, 02:35:29 pm
I tried this, but "gpart resize -i 1 vtbd0" just returns "gpart: no such geom: vtbd0".  Seems like the partition names differ between installs.  Finally did get it to work though.  Thanks.
Title: Re: Resize OPNSense Partition
Post by: Patrick M. Hausen on October 11, 2021, 02:48:13 pm
I tried this, but "gpart resize -i 1 vtbd0" just returns "gpart: no such geom: vtbd0".
Please post the output of `gpart show`.
Probably your disk uses a different device name.
Title: Re: Resize OPNSense Partition
Post by: allebone on October 11, 2021, 08:56:34 pm
Yeah this is not a "just type in commands and hope" kind of example above. Its more like a "I did this and this was my output between each steps, you check yours and reconfigure as appropriate" style guide.
Title: Re: Resize OPNSense Partition
Post by: Patrick M. Hausen on October 11, 2021, 09:16:24 pm
Yeah this is not a "just type in commands and hope" kind of example above. Its more like a "I did this and this was my output between each steps, you check yours and reconfigure as appropriate" style guide.

A novice was trying to fix a broken Lisp machine by turning the power off and on.

Knight, seeing what the student was doing, spoke sternly: “You cannot fix a machine by just power-cycling it with no understanding of what is going wrong.”

Knight turned the machine off and on.

The machine worked.


-- http://www.catb.org/jargon/html/koans.html