[ previous ] [ next ] [ threads ]
 From:  "Michael Mee" <mm2001 at pobox dot com>
 To:  <m0n0wall at lists dot m0n0 dot ch>
 Subject:  hacking solution for kernel wimps (like me)
 Date:  Sat, 14 Jun 2003 16:23:58 -0700
Undeterred by the zero response to my previous request for help (yes its
barely been 24 hours and it was a Friday :>), I've found a way to do some
simple additions to m0n0wall without exposing myself to the full complexity
of building kernels, image files or even copying to CF using dd. I share
these below in the hope it will promote some more additions to this great

What you need:
+ freeBSD running with a root password and some free disk space (say 20MB?)
+ an existing Soekris .img file from one of the download mirrors
+ Soekris box running m0n0wall (or presumably a PC, but I haven't tested

What you get:
+ the ability to edit files on the Soekris root file system and update your

E.g., I've made some trivial changes to /etc/rc, /etc/syslog.conf and
/usr/local/www/diag_logs.php to show dhcp log entries as preparation for my
more ambitious goal of providing the wishlist item "static DHCP mappings for
MAC address/IP address pairs". (I'll send those changes to Manuel off-list
unless someone else wants them - or as a hacked image :->).

Using Rudi van Drunen's excellent Hackers guide, I've pieced together two
shell scripts that automate extracting the root file system from an image
into a local directory tree and then wrapping it back up again into an image
ready for download via the "Firmware upload' facility. Apologies in advance
for the rough nature of my sh coding - its been too many years. If anyone
has improvements or suggestions, I'll gladly incorporate and redistribute.

Also, the usual caveats apply. If you trash your system (either desktop or
Soekris) using any info contained in this email, then you have my apologies
but nothing else!

1) go to some 'working area' directory
2) copy/create the files listed below, monoextract and monomake to that dir
3) chmod +x monoextract monomake
4) get an image file into that dir, e.g.:
 ftp http://m0n0wall.cac.net/download/m0n0wall/net45xx-pb11r409.img
5) from the shell while logged in as root, type (note, no extension on file
image name):
./monoextract net45xx-pb11r409
6) this will create some intermediate files which you should leave there,
along with the directory 'mfs'. Inside mfs is the root tree as it appears in
the Soekris image.
7) make the changes you desire in the mfs subdirectory
8) type:
./monomake net45xx-pb11r409
note that you MUST use the same image name with this script version, as it
replaces portions of the image but not all of it. The .bin file is the
important one, so you could copy that to another name if you want and then
use that new name
9) log in to your monowall as an administrator, enable firmware uploading
10) ftp the net45xx-pb11r409.img file to your soekris box
11) in the monowall GUI, click the "Upgrade Firmware" and cross your fingers
while it reboots

Enjoy! michael


#======= monoxtract starts here ==========

# monoxtract - extract the root file system from a mono image

if [ ! -f $1.img ]
  echo "Image file $1.img was not found. Exiting." && exit

# rename to suit current Soekris .img naming scheme

cp $1.img $1.bin.gz
gzip -d $1.bin.gz

# get the mfsroot.gz file (the Soekris root file system)
vnconfig -s labels -c vn0 ./$1.bin
mount /dev/vn0a /mnt
cp /mnt/mfsroot.gz .
umount /dev/vn0a
vnconfig -u vn0

# now mount the root file system image and tar it
gzip -d mfsroot.gz
vnconfig -s labels -c vn0 ./mfsroot
mount /dev/vn0c /mnt
tar cvfz ./mfs.tgz -C /mnt .
umount /mnt
vnconfig -u vn0c

# finally untar into a local dir 'mfs'
rm -rf mfs
mkdir mfs
tar xvfzP mfs.tgz -C mfs

#======= monoxtract ends here ==========
#======= monomake starts here ==========

# monomake - create a mono binary from a root file system

if [ ! -f $1.bin ]
  echo "Image file $1.bin was not found. Exiting." && exit

# first tar the local dir mfs that contains the root fs

tar cfz ./mfs.tgz -C mfs .

# now mount an existing root file system image mfsroot
# and replace its contents with the tar file

[ -f mfsroot.gz ] && gzip -d mfsroot.gz
[ ! -f mfsroot ] && echo "Could not find mfsroot, exiting" && exit
vnconfig -s labels -c vn0 ./mfsroot
mount /dev/vn0c /mnt
rm -rf /mnt/*
tar xvfzP ./mfs.tgz -C /mnt
umount /mnt
vnconfig -u vn0c
gzip mfsroot

# put the mfsroot.gz file into the Soekris boot image

vnconfig -s labels -c vn0 ./$1.bin
mount /dev/vn0a /mnt
cp mfsroot.gz /mnt
umount /dev/vn0a
vnconfig -u vn0

# gzip and rename to suit current Soekris .img naming
# (also leaves .bin for subsequent makemono)

gzip -c $1.bin >$1.img

#======= monomake ends here ==========