1.14. Putting it all together: creating the image

This is very similar to creating the mfsroot. Again, a zero-filled image file needs to be created first. This needs to be big enough to accomodate the kernel, mfsroot, boot loader and config.xml. As of 1.21, 7 MB is used.

dd if=/dev/zero of=image.bin bs=1k count=7168
vnconfig -s labels -c vn0 image.bin

This time, the first and second stage boot loaders need to be written into the special reserved area at the beginning of the image too.

disklabel -Brw -b $BOOTDIR/boot1 -s $BOOTDIR/boot2 vn0 auto
disklabel -e vn0

You will be dropped into your favorite text editor. Duplicate the line that starts with c:, and change the c: to a: and the fstype from unused to 4.2BSD. Now create and mount the root file system:

newfs -b 8192 -f 1024 -o space -m 0 /dev/vn0a
mount /dev/vn0a /mnt

Copy kernel.gz, mfsroot.gz, the boot loader and the default config file (which is going to be the initial configuration of your new image):

cp /sys/compile/M0N0WALL_[PLATFORM]/kernel.gz /mnt
cp mfsroot.gz /mnt
mkdir /mnt/boot
cp $BOOTDIR/{loader,loader.rc} /mnt/boot
mkdir /mnt/conf
cp $MWROOT/conf.default/config.xml /mnt/conf

Time to finalize the image (step out of /mnt first):

umount /mnt
vnconfig -u vn0
gzip -9 image.bin

Et voilà! Rename the image as per standard m0n0wall conventions to make sure that the webGUI firmware upgrade works (which insists that the filename starts with the platform name followed by a dash):

mv image.bin.gz [platform]-[version].img