vkernel manager

Nuno Antunes nuno.antunes at gmail.com
Sat Feb 9 05:11:22 PST 2008


On Feb 9, 2008 7:04 AM, Aggelos Economopoulos <aoiko at cc.ece.ntua.gr> wrote:
> Working with vkernels involves a lot of vnconfig, mount, installworld etc
> commands and there's always the posibility that you'll try to write to
> a filesystem that is in use by a running vkernel. Some months ago I was
> using a set of scripts to help with managing vkernel instances and
> diskimages. I took some time to convert them to a single script and expand
> them a bit (probably adding some bugs in the process). I suppose other
> people have their own scripts; if so, please share them.
>
> You use the script like this:
>
> vkernmgr init -m /mnt/vkern -s 1024 -w /usr/src -k /path/to/vkernel test
> [creates and formats an 1G disk image, installs base system from /usr/src]
>
> vkernmgr run test [extra vkernel flags, if any]
> [ensures no vn device is configured for access to the diskimage, runs
> vkernel]
>
> vkernmgr iw test
> [ensures no vkernel is using the diskimage, installs world from /usr/src]
>
> vkernmgr {start,stop}vn test
> vkernmgr {,u}mount test
> vkernmgr halt test
> vkernmgr kill test
> [These do the obvious; stopvn may need to run umount, mount may need to run
> startvn]
>
> Hopefully this will be useful to someone.

Yah, this looks nice. Maybe this should go in somewhere
(/usr/src/tools?). Although I see the value of this script, I tend to
use the same rootimg and vkernel binary with different arguments each
time depending on the scenario I'm trying to build. I also often copy
the rootimg files around to create an instant replica of the virtual
machine.

To create the rootimgs, I use a (rudimentary) script which is
basically just a rip-off from the instructions on the vkernel manpage.

#!/bin/sh

UID=`/usr/bin/id -u`
if [ "x$UID" != "x0" ]; then
	echo "This utility must be run with root privileges."
	exit
fi

ROOTIMG=$1
if [ "x$ROOTIMG" = "x" ]; then
	echo "usage: $0 root_image_file [image_size]"
	exit
fi

IMGSIZE=$2
if [ "x$IMGSIZE" = "x" ]; then
	IMGSIZE=1024M
fi

MOUNTPOINT=/mnt/vkernel

truncate -s $IMGSIZE $ROOTIMG
chmod 664 $ROOTIMG
vnconfig -c -s labels /dev/vn0 ${ROOTIMG}
disklabel -r -w vn0s0 auto
disklabel vn0s0 > /tmp/vdisklabel.txt
echo "  a: * 0 4.2BSD" >> /tmp/vdisklabel.txt
disklabel -R -r /dev/vn0s0 /tmp/vdisklabel.txt
rm -f /tmp/vdisklabel.txt
newfs -i 1024 /dev/vn0s0a
mount /dev/vn0s0a $MOUNTPOINT
make installworld DESTDIR=$MOUNTPOINT
cd etc
make distribution DESTDIR=$MOUNTPOINT
echo "/dev/vn0s0a / ufs rw 1 1" >$MOUNTPOINT/etc/fstab
echo 'console "/usr/libexec/getty Pc" cons25 on secure' >$MOUNTPOINT/etc/ttys
umount $MOUNTPOINT
vnconfig -u /dev/vn0

Its only mandatory argument is the name of the rootimg, with an
optional argument for its size. If the size is not specified, then it
defaults to 1Gb in order to accommodate a full instalworld with debug
symbols.

This is still very rudimentary and could use more arguments
validation. I thought that something like this could be used by some
additional target in /usr/src/Makefile. Something like:
make buildrootimg ROOTIMG=/var/vkernel/rootimg.01 ROOTIMGSIZE=512m
But don't have a formal proposal for it so I never brought it up.
Another use of such a target would be to create a disk image for
dd'ing into a compact flash for embedded applications or so.

Nuno





More information about the Kernel mailing list