From: David Huff <dhuff@redhat.com>
To: kvm@vger.kernel.org
Cc: David Huff <dhuff@redhat.com>
Subject: [PATCH][KVM_AUTOTEST] added script for unattended install
Date: Tue, 2 Jun 2009 18:24:43 -0400 [thread overview]
Message-ID: <1243981484-6391-2-git-send-email-dhuff@redhat.com> (raw)
In-Reply-To: <1243981484-6391-1-git-send-email-dhuff@redhat.com>
---
client/tests/kvm_runtest_2/scripts/unattended.sh | 220 ++++++++++++++++++++++
1 files changed, 220 insertions(+), 0 deletions(-)
create mode 100755 client/tests/kvm_runtest_2/scripts/unattended.sh
diff --git a/client/tests/kvm_runtest_2/scripts/unattended.sh b/client/tests/kvm_runtest_2/scripts/unattended.sh
new file mode 100755
index 0000000..7928117
--- /dev/null
+++ b/client/tests/kvm_runtest_2/scripts/unattended.sh
@@ -0,0 +1,220 @@
+#!/bin/bash
+#
+# unattended.sh - sets up environment for an unattended install for kvm_autotest
+#
+# Copyright (C) 2009 Red Hat, Inc.
+# Written by:
+# David Huff <dhufff@redhat.com>
+# Darryl L. Pierce <dpierce@redhat.com>
+#
+# 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; version 2 of the License.
+#
+# 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, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+
+ME=$(basename "$0")
+warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
+die() { warn "$*"; exit 1; }
+debug() { if $debugging; then log "[DEBUG] %s" "$*"; fi }
+
+set -e
+
+log () {
+ date=$(date)
+ printf "${date} $*\n"
+}
+
+usage () {
+ cat <<EOF
+Usage: $ME [-c unattended_config_file] [-n name] [LOGFILE]
+ -a: auto, pulls parameters from environment
+ -c: unattended config file to use
+ -n: name to append to floppy.img
+ -p: pxeboot and use iso image provided to setup pxe tree
+ -k: extra kernel args to use when pxe booting
+ -d: enable more verbose output (default: disabled)
+ -v: enable tracing (default: disabled)
+ -h: display this help and exit
+EOF
+}
+
+# creates a folder to use as virtual floppy disk
+# copys correct config file to this dir
+create_virtual_floppy_disk () {
+ local dir="floppy"
+
+ if [ -d $dir ]; then
+ rmdir $dir
+ fi
+
+ mkdir $dir
+
+ #copy config file to disk
+ if [[ "$CONFIG" =~ \.ks\$ ]] || [["$CONFIG" =~ \.cfg\$ ]]; then
+ cp $CONFIG $dir/ks.cfg
+ else
+ cp $CONFIG $dir
+ fi
+
+ #change permissions
+ #chmod 755 $filename
+}
+
+
+# creates a floppy disk file and adds unattended config file
+# $CONFIG file to stick on floppy disk
+create_floppy_disk () {
+ local size="144"
+ local filename="images/floppy.img"
+
+ #create floppy disk image
+ debug "Creating floppy disk: filename=${filename} size=${size}"
+ qemu-img create -f raw $filename "${size}M" > /dev/null 2>&1
+ mkfs.msdos $filename
+
+ #mount floppy disk image
+ mp=$(mktemp -d floppytmp.XXXXXX)
+ mount -t vfat -v -o loop $filename $mp
+
+ #copy config file to disk
+ if [[ "$CONFIG" =~ \.ks\$ ]] || [["$CONFIG" =~ \.cfg\$ ]]; then
+ cp $CONFIG $mp/ks.cfg
+ else
+ cp $CONFIG $mp
+ fi
+
+ #unmount floppy
+ df | grep $mp > /dev/null 2>&1 && umount -v $mp
+ rmdir $mp
+
+ #change permissions
+ chmod 755 $filename
+}
+
+
+# setup pxeboot evironment
+# $PXE - iso image
+# $ARGS - kernel arguments
+setup_pxeboot () {
+ local workdir=$PWD/tftpboot
+ local iso=$PXE
+ local pxedefault=$workdir/pxelinux.cfg/default
+ local pxelinux="/usr/lib/syslinux/pxelinux.0"
+ local cdlocation="images/pxeboot/"
+
+ # Check pxelinux.0 exists.
+ if [ ! -f /usr/share/syslinux/pxelinux.0 -a ! -f /usr/lib/syslinux/pxelinux.0 ]; then
+ die "Warning: pxelinux.0 not found, Make sure syslinux or pxelinux is installed on this system."
+ fi
+
+ #create clean tftpboot dir
+ if [ -d $workdir ]; then
+ log "$ME: subdirectory $workdir exists already. overwriting"
+ rm -rf $workdir
+ fi
+
+ mkdir -p $workdir/pxelinux.cfg
+
+ # pxelinux bootloader.
+ if [ -f /usr/share/syslinux/pxelinux.0 ]; then
+ cp /usr/share/syslinux/pxelinux.0 $workdir
+ elif [ -f /usr/lib/syslinux/pxelinux.0 ]; then
+ cp /usr/lib/syslinux/pxelinux.0 $workdir
+ else
+ die "Warning: pxelinux.0 not found, Make sure syslinux or pxelinux is installed on this system."
+ fi
+
+ # get vmlinz and initrd form image
+ mp=$(mktemp -d cdtmp.XXXXXX)
+ mount -v -o loop "$iso" $mp
+
+ # Does it look like an ISO?
+ if [ ! -d $mp/$cdlocation ]; then
+ die "The ISO image doesn't look like a ISO image to me."
+ fi
+
+ cp $mp/$cdlocation/initrd.img $mp/$cdlocation/vmlinuz $workdir
+ df | grep $mp > /dev/null 2>&1 && umount -v $mp
+ rmdir $mp
+
+ # set default kernel arguments if none were provided
+ if [ -z "$ARGS" ]; then
+ local $ARGS=""
+ fi
+
+ local definition="DEFAULT pxeboot"
+ definition="${definition}\nTIMEOUT 20"
+ definition="${definition}\nPROMPT 0"
+ definition="${definition}\nLABEL pxeboot"
+ definition="${definition}\n KERNEL vmlinuz"
+ definition="${definition}\n IPAPPEND 2"
+ definition="${definition}\n APPEND initrd=initrd.img $ARGS"
+
+ debug "pxeboot definition=\n${definition}"
+ printf "${definition}\n" > $pxedefault
+}
+
+debugging=false
+CONFIG=
+NAME=
+PXE=
+ARGS=
+
+while getopts adc:n:p:k:vh c; do
+ case $c in
+ a) CONFIG=$KVM_TEST_unattended_file
+ NAME=$KVM_TEST_image
+ PXE=isos/$KVM_TEST_cdrom
+ ARGS=$KVM_TEST_kernel_args;;
+ d) debugging=true;;
+ c) CONFIG=$OPTARG;;
+ n) NAME=$OPTARG;;
+ p) PXE=$OPTARG;;
+ k) ARGS=$OPTARG;;
+ v) set -v;;
+ h) usage; exit 0;;
+ '?') die "invalid option \`-$OPTARG'";;
+ :) die "missing argument to \`-$OPTARG' option";;
+ *) die "internal error";;
+ esac
+done
+
+shift $(($OPTIND - 1))
+
+set +u
+if [ $# -gt 0 -a -n "$1" ]; then RESULTS=$1; else RESULTS=unattended.log; fi
+set -u
+
+# check to see we are root
+if [ $( id -u ) -ne 0 ]; then
+ die "Must run as root"
+fi
+
+log "$ME: Logging results to file: ${RESULTS}"
+
+# Require "-o OUTPUT_FILE"
+if test -z $CONFIG; then
+ die "no config file for unattended install"
+fi
+
+log "$ME: using unattended config file: $CONFIG"
+
+# create teh floppy image
+create_floppy_disk $CONFIG
+#create_virtual_floppy_disk $CONFIG
+
+#if [ $PXE ]; then
+ debug "$ME: using $PXE to set up pxe environmet"
+ setup_pxeboot
+#fi
--
1.6.0.6
next prev parent reply other threads:[~2009-06-02 22:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-02 22:24 [KVM_AUTOTEST] unattended installs David Huff
2009-06-02 22:24 ` David Huff [this message]
2009-06-02 22:24 ` [PATCH][KVM_AUTOTEST] modified sample config file to include one example of unattended install David Huff
2009-06-02 22:30 ` [KVM_AUTOTEST] unattended installs David Huff
2009-06-03 1:25 ` Charles Duffy
2009-06-03 11:25 ` Lucas Meneghel Rodrigues
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1243981484-6391-2-git-send-email-dhuff@redhat.com \
--to=dhuff@redhat.com \
--cc=kvm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.