2.4. Unpacking/Editing/Packing the Source

The next thing is, if you are really confident with your system to create a new image that you can use to upgrade tha m0n0wall flash. The best way to do that is build an image like Manual has on his web site, so you can update the m0n0wall using the GUI tool. First reconstruct the root filesystem to its initial state with respect to the link and the location of the config file: (not really needed, the CF card will be mounted "over" the /cf directory even when not empty) but to keep everything as clean as possible you might do that

rm -rf cf/conf

Creating a flash image works about the same way as creating a rootfs file, but we will need a disklabel that suits the flash card. After creating a file device, we will be putting the kernel.gz file, the rootfilesystem file, the conf directory and the default configuration on the card (file). Also needed is the /boot directory, containing the boot loader files A suitable disklabel (put it in the label.proto file) might be:

# /dev/vn0c:
type: unknown
disk: amnesiac
label: 
flags:
bytes/sector: 512
sectors/track: 32
tracks/cylinder: 64
sectors/cylinder: 2048
cylinders: 5
sectors/unit: 10240
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # milliseconds
track-to-track seek: 0  # milliseconds
drivedata: 0
8 partitions:
#        size   offset    fstype   [fsize bsize bps/cpg]
  a:    10240        0    4.2BSD     1024  8192    26   # (Cyl.    0 - 4)
  c:    10240        0    unused        0     0         # (Cyl.    0 - 4)

First you might compress the rootfilesystem to save space:

gzip -9 mfsroot.bin; mv mfsroot.bin mfsroot.gz

Create the boot directory for inclusion on the flash image, and populate it with the appropriate files:

mkdir -m 0755 -p boot; cd boot
cp /boot/boot? .
cp /boot/loader .
cp /boot/loader.help .
cp /boot/loader.4th .
cp /boot/mbr .
cp /boot/support.4th .
mkdir -m 0755 -p defaults
cp /boot/defaults/loader.conf defaults

Now create the custom files for the loader:

loader.conf:

kernfs_load="NO"                # Kernel filesystem

loader.rc:

load /kernel
load -t mfs_root /mfsroot
autoboot 0

Now you might start building the actual memory filesystem image ....

dd if=/dev/zero of=image.bin bs=1k count=5120
vnconfig -s labels -c vn0 image.bin
disklabel -BR vn0 label.proto
newfs -b 8192 -f 1024 /dev/vn0a

mount /dev/vn0a /mnt
cp -Rp boot /mnt
cp -p mfsroot.bin kernel.gz /mnt
mkdir /mnt/conf
cp -p /conf.default/config.xml /mnt/conf
umount /mnt
vnconfig -u vn0
gzip -9 image.bin

Now your new-and-improved-with-your-most-wanted-feature m0n0wall image is ready to be loaded !!