I recently migrated the zroot on r730-01 to a new pair of devices. I did not then configure swap for the swap partitions I set up. I’m going to do that now.
I’m hoping this post from 8 years ago helps.
In this post:
- FreeBSD 14.3
The first few sections include what’s in the system, and detects and fixes a few issues. Look for The real work near the bottom of the page.
What I have now
This is what I have now.
The zpool:
[17:31 r730-01 dvl ~] % zpool status zroot pool: zroot state: ONLINE scan: scrub repaired 0B in 00:01:13 with 0 errors on Thu Dec 4 04:28:41 2025 config: NAME STATE READ WRITE CKSUM zroot ONLINE 0 0 0 mirror-0 ONLINE 0 0 0 gpt/zfs0_20170718AA0000185556 ONLINE 0 0 0 gpt/zfs1_20170719AA1178164201 ONLINE 0 0 0 errors: No known data errors
What is the geom name for that device? I need that to run gpart on the right devices. I could just run gpart and pick, but I’m trying to do this the “proper” way to avoid mistakes.
Here is what I do: glabel list | less – then I search for gpt/zfs0_20170718AA0000185556 (found under mirror-0 above.
I find this:
Geom name: ada0p3 Providers: 1. Name: gpt/zfs0_20170718AA0000185556 Mediasize: 115234181120 (107G)
and this:
Geom name: ada1p3 Providers: 1. Name: gpt/zfs1_20170719AA1178164201 Mediasize: 115234181120 (107G)
Let’s look at those disks:
[17:41 r730-01 dvl ~] % gpart show ada0 ada1
=> 40 242255584 ada0 GPT (116G)
40 2008 - free - (1.0M)
2048 409600 1 efi (200M)
411648 16777216 2 freebsd-swap (8.0G)
17188864 225066760 3 freebsd-zfs (107G)
=> 40 242255584 ada1 GPT (116G)
40 2008 - free - (1.0M)
2048 409600 1 efi (200M)
411648 16777216 2 freebsd-swap (8.0G)
17188864 225066760 3 freebsd-zfs (107G)
There, those are them. I have better names set up. Look here:
[17:41 r730-01 dvl ~] % gpart show -l ada0 ada1
=> 40 242255584 ada0 GPT (116G)
40 2008 - free - (1.0M)
2048 409600 1 efi0_20170718AA0000185556 (200M)
411648 16777216 2 swap0 (8.0G)
17188864 225066760 3 zfs0_20170718AA0000185556 (107G)
=> 40 242255584 ada1 GPT (116G)
40 2008 - free - (1.0M)
2048 409600 1 efi1_20170719AA1178164201 (200M)
411648 16777216 2 swap1 (8.0G)
17188864 225066760 3 zfs1_20170719AA1178164201 (107G)
I want these devices:
[17:41 r730-01 dvl ~] % ls -l /dev/gpt/swap* crw-r----- 1 root operator 0xd5 2025.11.29 17:06 /dev/gpt/swap0 crw-r----- 1 root operator 0xdf 2025.11.29 17:06 /dev/gpt/swap1
They are 8G each.
Let’s go.
Creating the gmirror
Unlike my previous post, I already have a gmirror, loaded:
[17:45 r730-01 dvl ~] % grep mirror /boot/loader.conf geom_mirror_load="YES" [17:42 r730-01 dvl ~] % gmirror list -a [17:43 r730-01 dvl ~] %
Adding in the first half of the mirror – and getting an unexpected result
This statement creates a geom named swap, and adds one device to it:
[17:47 r730-01 dvl ~] % sudo gmirror label -v -b round-robin swap /dev/gpt/swap0 Metadata value stored on /dev/gpt/swap0. Done. [17:47 r730-01 dvl ~] % gmirror list Geom name: swap State: COMPLETE Components: 1 Balance: round-robin Slice: 4096 Flags: NONE GenID: 0 SyncID: 1 ID: 2519922271 Type: AUTOMATIC Providers: 1. Name: mirror/swap Mediasize: 2147483136 (2.0G) Sectorsize: 512 Mode: r0w0e0 Consumers: 1. Name: nda4p2 Mediasize: 2147483648 (2.0G) Sectorsize: 512 Stripesize: 0 Stripeoffset: 1048576 Mode: r1w1e1 State: ACTIVE Priority: 0 Flags: (null) GenID: 0 SyncID: 1 ID: 688737778 [17:47 r730-01 dvl ~] %
nda4p2? 2G? What?
Well, I have more than one device with the same label.
[17:50 r730-01 dvl ~] % gpart show -l | grep swap0
2048 4194304 2 swap0 (2.0G)
411648 16777216 2 swap0 (8.0G)
Deleting the extra swap labels
What do I do when there is more than one device with the same label? Remove one label.
This is the problem device. There may be more.
[17:50 r730-01 dvl ~] % gpart show -l | less
=> 40 488397088 nda4 GPT (233G)
40 1024 1 gptboot0 (512K)
1064 984 - free - (492K)
2048 4194304 2 swap0 (2.0G)
4196352 484200448 3 zfs0 (231G)
488396800 328 - free - (164K)
This removes that label:
[17:53 r730-01 dvl ~] % sudo gpart modify -i 2 -l '' nda4
nda4p2 modified
[17:54 r730-01 dvl ~] % gpart show nda4
=> 40 488397088 nda4 GPT (233G)
40 1024 1 freebsd-boot (512K)
1064 984 - free - (492K)
2048 4194304 2 freebsd-swap (2.0G)
4196352 484200448 3 freebsd-zfs (231G)
488396800 328 - free - (164K)
[17:54 r730-01 dvl ~] % gpart show -l nda4
=> 40 488397088 nda4 GPT (233G)
40 1024 1 gptboot0 (512K)
1064 984 - free - (492K)
2048 4194304 2 (null) (2.0G)
4196352 484200448 3 zfs0 (231G)
488396800 328 - free - (164K)
[17:54 r730-01 dvl ~] %
Let’s check for swap1 while here…
Reviewing the output of gpart show -l | less found only one swap1 and it was the 8G one on the right device.
Undoing the work
[17:57 r730-01 dvl ~] % sudo gmirror remove swap /dev/gpt/swap0 gmirror: No such provider: /dev/gpt/swap0.
Well, yes, we deleted that. However, based on other tests, you can’t remove by that type of name. You have to do what I have below:
[17:58 r730-01 dvl ~] % sudo gmirror remove swap gpt/swap0 gmirror: No such provider: gpt/swap0. [17:58 r730-01 dvl ~] % sudo gmirror remove swap nda4p2 gmirror: swap: Can't remove the last ACTIVE component nda4p2. [17:58 r730-01 dvl ~] % sudo gmirror destroy swap [17:59 r730-01 dvl ~] % sudo gmirror list [17:59 r730-01 dvl ~] %
Starting fresh. Let’s do this again
Recreate the gmirror:
[17:59 r730-01 dvl ~] % sudo gmirror label -v -b round-robin swap /dev/gpt/swap0
gmirror: Can't get informations about /dev/gpt/swap0: No such file or directory.
[18:01 r730-01 dvl ~] % gpart show ada0 ada1
=> 40 242255584 ada0 GPT (116G)
40 2008 - free - (1.0M)
2048 409600 1 efi (200M)
411648 16777216 2 freebsd-swap (8.0G)
17188864 225066760 3 freebsd-zfs (107G)
=> 40 242255584 ada1 GPT (116G)
40 2008 - free - (1.0M)
2048 409600 1 efi (200M)
411648 16777216 2 freebsd-swap (8.0G)
17188864 225066760 3 freebsd-zfs (107G)
[18:01 r730-01 dvl ~] % gpart show -l ada0 ada1
=> 40 242255584 ada0 GPT (116G)
40 2008 - free - (1.0M)
2048 409600 1 efi0_20170718AA0000185556 (200M)
411648 16777216 2 swap0 (8.0G)
17188864 225066760 3 zfs0_20170718AA0000185556 (107G)
=> 40 242255584 ada1 GPT (116G)
40 2008 - free - (1.0M)
2048 409600 1 efi1_20170719AA1178164201 (200M)
411648 16777216 2 swap1 (8.0G)
17188864 225066760 3 zfs1_20170719AA1178164201 (107G)
[18:01 r730-01 dvl ~] %
Oh. It seems you can have only one /dev/gpt/swap0.
Let’s try this to get that device recreated:
[18:01 r730-01 dvl ~] % sudo gpart modify -i 2 -l swap0 ada0 ada0p2 modified [18:03 r730-01 dvl ~] % ls -l /dev/gpt/swap0 crw-r----- 1 root operator 0x216 2025.12.04 18:03 /dev/gpt/swap0 [18:03 r730-01 dvl ~] %
With that command I set the label to the same value. That created the device I needed.
The real work
This one works.
[18:05 r730-01 dvl ~] % sudo gmirror label -v -b round-robin swap /dev/gpt/swap0
Metadata value stored on /dev/gpt/swap0.
Done.
[18:05 r730-01 dvl ~] % gmirror status
Name Status Components
mirror/swap COMPLETE ada0p2 (ACTIVE)
[18:05 r730-01 dvl ~] % gmirror list
Geom name: swap
State: COMPLETE
Components: 1
Balance: round-robin
Slice: 4096
Flags: NONE
GenID: 0
SyncID: 1
ID: 436380494
Type: AUTOMATIC
Providers:
1. Name: mirror/swap
Mediasize: 8589934080 (8.0G)
Sectorsize: 512
Mode: r0w0e0
Consumers:
1. Name: ada0p2
Mediasize: 8589934592 (8.0G)
Sectorsize: 512
Stripesize: 0
Stripeoffset: 210763776
Mode: r1w1e1
State: ACTIVE
Priority: 0
Flags: (null)
GenID: 0
SyncID: 1
ID: 1019612839
[18:05 r730-01 dvl ~] %
Next, I add in the second device:
[18:05 r730-01 dvl ~] % sudo gmirror insert swap /dev/gpt/swap1
[18:06 r730-01 dvl ~] % gmirror status
Name Status Components
mirror/swap DEGRADED ada0p2 (ACTIVE)
ada1p2 (SYNCHRONIZING, 14%)
[18:06 r730-01 dvl ~] % gmirror list
Geom name: swap
State: DEGRADED
Components: 2
Balance: round-robin
Slice: 4096
Flags: NONE
GenID: 0
SyncID: 1
ID: 436380494
Type: AUTOMATIC
Providers:
1. Name: mirror/swap
Mediasize: 8589934080 (8.0G)
Sectorsize: 512
Mode: r1w0e0
Consumers:
1. Name: ada0p2
Mediasize: 8589934592 (8.0G)
Sectorsize: 512
Stripesize: 0
Stripeoffset: 210763776
Mode: r1w1e1
State: ACTIVE
Priority: 0
Flags: (null)
GenID: 0
SyncID: 1
ID: 1019612839
2. Name: ada1p2
Mediasize: 8589934592 (8.0G)
Sectorsize: 512
Stripesize: 0
Stripeoffset: 210763776
Mode: r1w1e1
State: SYNCHRONIZING
Priority: 0
Flags: DIRTY, SYNCHRONIZING
GenID: 0
SyncID: 1
BytesSynced: 3457155072
Synchronized: 40%
ID: 2160596712
[18:06 r730-01 dvl ~] %
That’s much better.
By the time I’d pasted all that into here, the gmirror was stable:
[18:06 r730-01 dvl ~] % gmirror status
Name Status Components
mirror/swap COMPLETE ada0p2 (ACTIVE)
ada1p2 (ACTIVE)
Hold on a minute! 2025-12-08
I’ve created a gmirror, using the swap partitions, but FreeBSD doesn’t know it is to be used for swap.
Based on my recent Mastodon post,
swapinfo
knows nothing:
[23:31 r730-01 dvl ~] % swapinfo Device 1K-blocks Used Avail Capacity
I do have an entry in /etc/fstab, but what it refers to does not exist:
[0:06 r730-01 dvl ~] % cat /etc/fstab # Device Mountpoint FStype Options Dump Pass# /dev/mirror/swap.eli none swap sw 0 0
I also want to enable encryption on that swap partition (that is what the fstab entry is pointing to ). Let’s be extremist and follow the docs.
Let’s create existing swap partitions.
[23:39 r730-01 dvl ~] % gmirror status
Name Status Components
mirror/swap COMPLETE ada0p2 (ACTIVE)
ada1p2 (ACTIVE)
Based on that, this is how I overwrite that:
[23:59 r730-01 dvl ~] % sudo dd if=/dev/random bs=1m of=/dev/mirror/swap load: 3.72 cmd: dd 93474 [physwr] 44.83r 0.03u 23.91s 55% 3440k 6820+0 records in 6820+0 records out 7151288320 bytes transferred in 44.831813 secs (159513698 bytes/sec) dd: /dev/mirror/swap: short write on character device dd: /dev/mirror/swap: end of device 8192+0 records in 8191+1 records out 8589934080 bytes transferred in 53.844142 secs (159533306 bytes/sec)
I pressed ^T there, and it told me it had written about 7.15GB.
Starting swap
Starting swap was… easy?
[0:09 r730-01 dvl ~] % ls -l /dev/mirror total 0 crw-r----- 1 root operator 0x653 2025.12.09 00:00 swap [0:11 r730-01 dvl ~] % sudo service swap start [0:11 r730-01 dvl ~] % ls -l /dev/mirror total 0 crw-r----- 1 root operator 0x653 2025.12.09 00:00 swap crw-r----- 1 root operator 0x61c 2025.12.09 00:11 swap.eli [0:11 r730-01 dvl ~] % swapinfo Device 1K-blocks Used Avail Capacity /dev/mirror/swap.eli 8388604 0 8388604 0% [0:11 r730-01 dvl ~] %
So that’s it now, swap is working. Finally.
Not shown here, is the addition of this value to this file:
[0:11 r730-01 dvl ~] % grep mirror /boot/loader.conf geom_mirror_load="YES"
Hope that helps.











