There were a series of issues preventing the use of a swap-backed memory
disk in NanoBSD.
First, to create a memory disk using "-t swap", the size must align to a
valid geometry, otherwise the operation fails with:
mdconfig: ioctl(/dev/mdctl): Numerical argument out of domain
The value used for the size did not include the MBR sectors needed for a
valid CHS geometry. Fix this by adding them when creating the md
device.
When adding the freebsd-ufs partition inside the code slice, explicitly
set the size to the CODE_SIZE minus the 16 sectors that bsdlabel(8) (now
gpart(8)) used as an offset, which are reserved for metadata.
Finally, when issuing the final dd operation that writes the contents of
the rounded-up swap-backed memory device to the image file, trim the
size to CODE_SIZE in order for it to fit the full image accordingly.