Hi all,
I have been working with the QEMU VM's, VMDE-0.2 and and m0n0dev in testing images that came with the QEMU builds, in preperation to customising my own image.
I have been using m0n0image.php and workon4.sh that also came pre-installed with the QEMU image.
I have tried to decompress the images that came with the m0n0dev VM using the following commands:
m0n0image.php -x generic-pc1.2.img
This is the output from that command produces no errors and a clean extraction.
I then compressed the image again WITH NO modifications with the following command:
m0n0image.php -c DEVEL_generic-pc1.2.img
compressing.......cannot create dev/null: directory nonexistent
.mount: /dev/vn0c on mnt: incorrect super block
.cp: symlink: /var/run/htpasswd: File Exists
.cp: symlink: /var/etc/resolve.conf: File Exists
.cp: symlink: /var/etc/hosts: File Exists
.cp: symlink: /cf/conf: File Exists
.umount: /mnt: not currently mounted
...............................
Compression complete
This produces a 1.9mb file that fails to load.
If I run workon4.sh generic-pc1.2.img I get the following result:
vnconfig: /dev/vn1: No such file or directory
mount: /dev/vn1c: No Such file or directory
when I type Exit I get the following result:
umount: mnt2: not currently mounted
vnconfig: /dev/vn1: No suh file or directory
Can ANYONE please assist me with this, I have over the past 5 days build and test freeBSD 4.11, 6.2, and get exactly the same results.
below is the two scripts I am using
Regards
Dave
m0n0image.php script
#!/usr/local/bin/php
<?php
/*
* m0n0image.php (c)2004-2005
*
* michael iedema -
mdi@michael-i.com *
* simple script made to ease the build process for m0n0wall
*
* -x extracts contents into DEVEL_imagename
* -c compresses contents of a DEVEL_imagename directory into a bootable image
*
* usage: ./m0n0image.php [-x,-c] imagename.img
*
* changelog:
* 31.03.05 - v0.1.2
* - two bugs pointed out by Flemming Munk and Matias Bagini (thanks!)
*
* v0.1.1
* - fixed size issue with newer m0n0wall versions
*
* v0.1.0
* - initial release
*/
$version = "0.1.2";
if((!$argv[1]) || (!$argv[2]) || (($argv[1] != "-x") && ($argv[1] != "-c")))
{
print("m0n0image.php v$version (C)2004-2005 michael iedema <
mdi@michael-i.com>");
print("\nusage: $argv[0] [-x,-c] imagename.img\n");
print("\t-x\textract contents of image into DEVEL_imagename\n");
print("\t-c\tcompress DEVEL_imagename folder into a bootable image\n\n");
}
elseif($argv[1] == "-x")
{
$image = substr("$argv[2]", 0, -4);
$image_dir = "DEVEL_".$image;
$commands = array(
/* directory creation */
"mkdir $image_dir",
"mkdir $image_dir/fs",
"mkdir $image_dir/kern",
/* rename image and decompress */
"mv $image.img $image.bin.gz",
"gzip -d $image.bin.gz",
/* setup our virtual device & mount on /mnt */
"vnconfig -s labels -c vn0 $image.bin",
"mount /dev/vn0a /mnt",
/* copy out our kernel.gz, mfsroot.gz, boot, and conf */
"cp -p /mnt/kernel.gz $image_dir/kern/",
"cp -p /mnt/mfsroot.gz $image_dir",
"cp -Rp /mnt/boot $image_dir/boot",
"cp -Rp /mnt/conf $image_dir/conf",
/* unmount and destroy the virtual device */
"umount /mnt",
"vnconfig -u vn0",
/* rezip our image and rename back to .img */
"gzip -9 $image.bin",
"mv $image.bin.gz $image.img",
/* unzip our mfsroot.gz */
"gzip -d $image_dir/mfsroot.gz",
/* setup our virtual device & mount on /mnt */
"vnconfig -s labels -c vn0 $image_dir/mfsroot",
"mount /dev/vn0c /mnt",
/* copy out our mfsroot into our devel/fs directory */
"cp -Rp /mnt/* $image_dir/fs",
/* unmount, destroy and clean up our mfsroot virtual device */
"umount /mnt",
"vnconfig -u vn0",
"rm $image_dir/mfsroot");
/* loop through and execute with pretty dots denoting completed commands */
print("extracting.");
foreach($commands as $command)
{
exec($command);
print(".");
}
print("\nextraction complete\n");
}
elseif($argv[1] == "-c")
{
$directory = $argv[2];
/* removes trailing slash of a directory path */
if(($directory[strlen($directory)-1])=="/")
{
$directory = substr("$directory", 0, -1);
}
$commands = array(
/* make a temp directory to do all this within */
"mkdir tmp",
/* create an image file for the root file system */
"dd if=/dev/zero of=tmp/mfsroot.bin bs=1k count=12288 2>/dev/null",
"vnconfig -s labels -c vn0 tmp/mfsroot.bin",
"disklabel -rw vn0 auto 2>/dev/null",
"newfs -b 8192 -f 1024 /dev/vn0c 2>dev/null",
/* mount up our image and copy in our root file system */
"mount /dev/vn0c /mnt",
"cp -Rp $directory/fs/* /mnt",
/* unmount and destroy our virtual device */
"umount /mnt",
"vnconfig -u vn0",
/* compress and rename our root file system */
"gzip -9 tmp/mfsroot.bin",
"mv tmp/mfsroot.bin.gz tmp/mfsroot.gz",
/* build our memory filesystem image */
"dd if=/dev/zero of=tmp/$directory.bin bs=1k count=6144 2>/dev/null",
"vnconfig -s labels -c vn0 tmp/$directory.bin",
"disklabel -BR vn0 label.proto",
"newfs -b 8192 -f 1024 /dev/vn0a",
/* mount our empty image, and copy everything into it */
"mount /dev/vn0a /mnt",
"cp -Rp $directory/boot /mnt",
"cp -Rp $directory/conf /mnt",
"cp -p tmp/mfsroot.gz $directory/kern/kernel.gz /mnt",
/* unmount and destroy our virtual device */
"umount /mnt",
"vnconfig -u vn0",
/* compress and rename our image to DEVEL_originalimagename */
"gzip -9 tmp/$directory.bin",
"mv tmp/$directory.bin.gz $directory.img",
/* clean up after ourselves */
"rm -rf tmp",
"rm label.proto");
/* write out our label prototype */
$fd = fopen("label.proto", "w");
$labelproto=<<<EOD
# /dev/vn0c:
type: unknown
disk: amnesiac
label:
flags:
bytes/sector: 512
sectors/track: 32
tracks/cylinder: 64
sectors/cylinder: 2048
cylinders: 5
sectors/unit: 12288
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: 12288 0 4.2BSD 1024 8192 26 # (Cyl. 0 - 4)
c: 12288 0 unused 0 0 # (Cyl. 0 - 4)
EOD;
fwrite($fd, $labelproto);
fclose($fd);
print("compressing.");
foreach($commands as $command)
{
exec($command);
print(".");
}
print("\ncompression complete\n");
}
?>
# End m0n0image.php Script
workon4.sh script
#!/bin/sh
# Instructions (as root)-- make a directory and put this script inside it.
# chmod +x workon.sh
# Download or copy an image file into the directory
# ./workon.sh wrap-1.11.img
# This will start your SHELL inside the mounted image.
# When you are done, type exit. This exits your SHELL and lets
# this script proceed (umount, gzip, etc).
# The image file now contains your changes (and is no longer signed).
# Set your shell -- /bin/csh will always work
SHELL=/usr/local/bin/bash
[ ! -x $SHELL ] && echo "${SHELL} not executable (try /bin/csh)" && exit 1
# No more edits
IMAGE=$1
# Make dirs
mkdir -p tmp; mkdir -p mnt1; mkdir -p mnt2
# Decompress IMAGE
gzip -dc < ${IMAGE} > tmp/${IMAGE}
# Mount IMAGE
#mdconfig -a -t vnode -f tmp/${IMAGE} -u 90
vnconfig -s labels -c vn0 tmp/${IMAGE}
#mount /dev/md90 mnt1
mount /dev/vn0c mnt1
# Decompress mfsroot
gzip -dc < mnt1/mfsroot.gz > tmp/${IMAGE}-mfsroot
# Mount mfsroot
#mdconfig -a -t vnode -f tmp/${IMAGE}-mfsroot -u 91
vnconfig -s labels -c vn1 tmp/${IMAGE}-mfsroot
#mount /dev/md91 mnt2
mount /dev/vn1c mnt2
# cd to 2nd mount and exec SHELL
cd mnt2
${SHELL}
# SHELL has exited -- clean up and compress
for vtmp in `find . | grep '~$'`; do
echo Removing: ${vtmp}
rm -f ${vtmp}
done
cd ../
umount mnt2
#mdconfig -d -u 91
vnconfig -u vn1
gzip -c9 < tmp/${IMAGE}-mfsroot > mnt1/mfsroot.gz
rm -f tmp/${IMAGE}-mfsroot
umount mnt1
#mdconfig -d -u 90
vnconfig -u vn0
gzip -c9 < tmp/${IMAGE} > ${IMAGE}
rm -f tmp/${IMAGE}
## End Script workon4.sh