First of all, a zero-filled image file needs to be created. The current size (as of m0n0wall 1.21) is 11 MB, which should be enough to fit all the files in the root file system. If you add big components, you may need to increase this. However, don't make it much bigger than necessary, as the MFS will take up as much space as you specify here, even if the file system is not full. Put mfsroot somewhere outside of $MWROOT!
dd if=/dev/zero of=mfsroot bs=1k count=11264
Now we'll use vnconfig to attach the file to /dev/vn0:
vnconfig -s labels -c vn0 mfsroot
After that, it's possible to use disklabel and newfs to create an UFS file system, and mount it:
disklabel -rw vn0 auto newfs -b 8192 -f 1024 -o space -m 0 /dev/vn0c mount /dev/vn0c /mnt
The root file system that you prepared in $MWROOT can now be transferred into /mnt.
tar should be used for this task, as it correctly preserves hard links (unlike cp) and thereby saves space:
cd /mnt tar -cf - -C $MWROOT ./ | tar -xvpf -
Cleaning up and gzipping the image (step out of /mnt first):
umount /mnt vnconfig -u vn0 gzip -9 mfsroot