Opnsense – Expand Disk – Grow partition FreeBSD

by | Feb 13, 2025 | IT Tips | 0 comments

Azure VM Size Standard B1ms (1 vcpu, 2 GiB memory)

Recommended VM size https://docs.opnsense.org/manual/hardware.html

https://docs-archive.freebsd.org/doc/11.4-RELEASE/usr/local/share/doc/freebsd/handbook/disks-growing.html

Boot to single user mode by pressing the 2 key when booting. If running in Azure you may need to connect to the serial console and reboot first to see the boot menu

This is the command to show the partitions

1
2
3
4
5
6
7
8
9
root@:/ # gpart show
=> 40 16777136 da0 GPT (40G) [CORRUPT]
40 532480 1 efi (260M)
532520 1024 2 freebsd-boot (512K)
533544 16243632 3 freebsd-ufs (7.7G)
=> 63 8388545 da1 MBR (4.0G)
63 1985 - free - (993K)
2048 8384512 1 ntfs (4.0G)
8386560 2048 - free - (1.0M)

This is the sysctl command to run before resizing the partition

1
sysctl kern.geom.debugflags=16

This is the partition resize command. See below for how I calculated the size of the new partition as 83352496

1
gpart resize -i 3 -s 83352496 -a 4k da0

This is the command to resize the file system

1
growfs /dev/gpt/rootfs

This is the calculation I did to get the size of the new partition from the output of gpart show

1
16243632 + 67108864 = 83352496

Copy and paste from the serial console in Azure

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
root@:/ # gpart show
 
=> 40 16777136 da0 GPT (40G) [CORRUPT]
 
40 532480 1 efi (260M)
 
532520 1024 2 freebsd-boot (512K)
 
533544 16243632 3 freebsd-ufs (7.7G)
 
=> 63 8388545 da1 MBR (4.0G)
 
63 1985 - free - (993K)
 
2048 8384512 1 ntfs (4.0G)
 
8386560 2048 - free - (1.0M)
 
root@:/ # gpart recover da0
 
da0 recovered
 
root@:/ # gpart show
 
=> 40 83886000 da0 GPT (40G)
 
40 532480 1 efi (260M)
 
532520 1024 2 freebsd-boot (512K)
 
533544 16243632 3 freebsd-ufs (7.7G)
 
16777176 67108864 - free - (32G)
 
=> 63 8388545 da1 MBR (4.0G)
 
63 1985 - free - (993K)
 
2048 8384512 1 ntfs (4.0G)
 
8386560 2048 - free - (1.0M)
 
root@:/ # sysctl kern.geom.debugflags=16
 
kern.geom.debugflags: 0 -> 16
 
root@:/ # gpart resize -i 3 -s 40G -a 4k da0
 
gpart: size '83886080': Invalid argument
 
root@:/ # gpart resize -i 3 -s 83352496 -a 4k da0
 
da0p3 resized
 
root@:/ # gpart show
 
=> 40 83886000 da0 GPT (40G)
 
40 532480 1 efi (260M)
 
532520 1024 2 freebsd-boot (512K)
 
533544 83352496 3 freebsd-ufs (40G)
 
=> 63 8388545 da1 MBR (4.0G)
 
63 1985 - free - (993K)
 
2048 8384512 1 ntfs (4.0G)
 
8386560 2048 - free - (1.0M)
 
root@:/ # gpart show
 
=> 40 83886000 da0 GPT (40G)
 
40 532480 1 efi (260M)
 
532520 1024 2 freebsd-boot (512K)
 
533544 83352496 3 freebsd-ufs (40G)
 
=> 63 8388545 da1 MBR (4.0G)
 
63 1985 - free - (993K)
 
2048 8384512 1 ntfs (4.0G)
 
8386560 2048 - free - (1.0M)
 
root@:/ # growfs /dev/da0p3
 
It's strongly recommended to make a backup before growing the file system.
 
OK to grow filesystem on /dev/da0p3 from 7.7GB to 40GB? [yes/no] yes
 
growfs: /dev/da0p3: Operation not permitted
 
root@:/ # growfs /dev/da0p3
 
It's strongly recommended to make a backup before growing the file system.
 
OK to grow filesystem on /dev/da0p3 from 7.7GB to 40GB? [yes/no] yes
 
growfs: /dev/da0p3: Operation not permitted
 
root@:/ # growfs /dev/gpt/rootfs
 
It's strongly recommended to make a backup before growing the file system.
 
OK to grow filesystem on /dev/gpt/rootfs, mounted on /, from 7.7GB to 40GB? [yes/no] yes
 
super-block backups (for fsck_ffs -b #) at:
 
16646016, 17926464, 19206912, 20487360, 21767808, 23048256, 24328704, 25609152, 26889600, 28170048,
 
29450496, 30730944, 32011392, 33291840, 34572288, 35852736, 37133184, 38413632, 39694080, 40974528,
 
42254976, 43535424, 44815872, 46096320, 47376768, 48657216, 49937664, 51218112, 52498560, 53779008,
 
55059456, 56339904, 57620352, 58900800, 60181248, 61461696, 62742144, 64022592, 65303040, 66583488,
 
67863936, 69144384, 70424832, 71705280, 72985728, 74266176, 75546624, 76827072, 78107520, 79387968,
 
80668416, 81948864, 83229312
 
root@:/ #

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.