]> git.ipfire.org Git - people/ms/ipfire-3.x.git/commitdiff
Added some things to run a VM by the iso image.
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 23 Dec 2008 12:49:05 +0000 (13:49 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 23 Dec 2008 12:49:05 +0000 (13:49 +0100)
.gitignore
doc/make.sh-usage
tools/make-include
tools/make-interactive
tools/make-vm [new file with mode: 0644]

index 76ce42700bcba0917ce1dbcabc7f901652263794..b3d067528ecf48e3cf9adafdc8d2b6a6b8188437 100644 (file)
@@ -10,6 +10,7 @@
 /doc/packages-list.txt
 /log_*
 /tmp
+/vm
 /*.diff
 /*.iso
 /*.tar.gz
index d623ddbd2daa394c9e7904e36f452cf9b5e437cb..76e74d290c628b2e61992695e45f7b00e5dd3724 100644 (file)
@@ -35,6 +35,10 @@ Maintainer / advanced commands
       |`-   sanity [--fix] : Check full code for errors.
       `--          targets : Returns the target, that the host can build.
 
+     vm        : _Run a virtual machine (which qemu)_
+      |`- boot [cdrom|disk] : Boot machine from cdrom or disk. (Default: cdrom)
+      `-- clean             : Cleanup the virtual environment.
+
         pull      : A macro to pull the latest changes from git and load the
                     source tarballs and patches. Additionally it checks the code
                     for error.
index b44a315a84ad8f0bdcdc373f26d909516b54eca9..11d28cb628db79cbdb53c5d99bad989fae9a1b6f 100644 (file)
@@ -58,6 +58,7 @@ mkdir $BASEDIR/log_${TARGET}/ 2>/dev/null
 . $BASEDIR/tools/make-batch
 . $BASEDIR/tools/make-compilers
 . $BASEDIR/tools/make-git
+. $BASEDIR/tools/make-vm
 
 evaluate() {
        RETVAL=$?
index 4405e6bd3ba663aeadcd4cfe3754a1013c9a4b5c..9bc55ca97641a6b9ce0577ade3667207bfe5a82d 100644 (file)
@@ -250,6 +250,19 @@ pull)
        getsource
        ;;
 
+vm|qemu)
+       case "$2" in
+               boot|start|run)
+                       shift 2
+                       qemu_start $*
+                       ;;
+
+               clean)
+                       rm -rf $BASEDIR/vm
+                       ;;
+       esac
+       ;;
+
 *)
        usage
        ;;
diff --git a/tools/make-vm b/tools/make-vm
new file mode 100644 (file)
index 0000000..87dbc0f
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2008  Michael Tremer & Christian Schmidt                      #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+qemu_start() {
+       # Check if we have a qemu binary
+       if ! which qemu &>/dev/null; then
+               dialogerror "Cannot find qemu."
+               exit 1
+       fi
+
+       # Check if the working directory is present
+       [ -d "$BASEDIR/vm" ] || mkdir $BASEDIR/vm
+       QEMU_DISK=$BASEDIR/vm/qemu-hda-$HOSTNAME.img
+
+       # Create a qemu disk if not present (4G)
+       [ -e $QEMU_DISK ] || qemu-img create $QEMU_DISK 4G
+
+       # Load the kernel module
+       if ! grep -q ^kqemu /proc/modules; then
+               modprobe kqemu 2>/dev/null
+       fi
+
+       # Prepare qemu command
+       QEMU_COMMAND="qemu -name $NAME-$VERSION -m 256"
+       QEMU_COMMAND="$QEMU_COMMAND -k de -localtime -std-vga -usb"
+       QEMU_COMMAND="$QEMU_COMMAND -no-reboot -vnc :2 -hda $QEMU_DISK"
+
+       if ! grep -q ^kqemu /proc/modules; then
+               QEMU_COMMAND="$QEMU_COMMAND -no-kqemu"
+       fi
+
+       case "$1" in
+               ""|cd*)
+                       QEMU_COMMAND="$QEMU_COMMAND -boot d -cdrom"
+                       if [ -n "$2" ]; then
+                               QEMU_COMMAND="$QEMU_COMMAND $2"
+                       else
+                               QEMU_COMMAND="$QEMU_COMMAND $BASEDIR/$IMAGENAME.iso"
+                       fi
+                       ;;
+               disk|hd*)
+                       QEMU_COMMAND="$QEMU_COMMAND -boot c"
+                       ;;
+       esac
+       
+       echo -e "We are going to run a ${BOLD}virtual machine${NORMAL}, now."
+       echo
+       echo "You may connect to this machine with a vnc viewer to $HOSTNAME:2."
+       echo "Kill this vm by pressing Ctrl+C."
+       echo
+       $QEMU_COMMAND
+       if [ $? -eq 0 ]; then
+               echo -n "The virtual machine quit gracefully."
+               beatify message DONE
+       else
+               echo -n "The virtual machine quit with an error!"
+               beautify message FAIL
+       fi
+}