From patchwork Thu Jun 18 21:50:58 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Huff X-Patchwork-Id: 31255 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n5ILpi8v025069 for ; Thu, 18 Jun 2009 21:51:45 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753830AbZFRVvh (ORCPT ); Thu, 18 Jun 2009 17:51:37 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753905AbZFRVvg (ORCPT ); Thu, 18 Jun 2009 17:51:36 -0400 Received: from mx2.redhat.com ([66.187.237.31]:59639 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753350AbZFRVvd (ORCPT ); Thu, 18 Jun 2009 17:51:33 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n5ILpavX026011 for ; Thu, 18 Jun 2009 17:51:36 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n5ILpZr2000898; Thu, 18 Jun 2009 17:51:35 -0400 Received: from localhost.localdomain (dhcp231-89.rdu.redhat.com [10.11.231.89]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n5ILpXd7018970; Thu, 18 Jun 2009 17:51:34 -0400 From: David Huff To: kvm@vger.kernel.org Cc: David Huff Subject: [PATCH] added unattended.sh script Date: Thu, 18 Jun 2009 17:50:58 -0400 Message-Id: <1245361860-26726-4-git-send-email-dhuff@redhat.com> In-Reply-To: <1245361860-26726-1-git-send-email-dhuff@redhat.com> References: <1245361860-26726-1-git-send-email-dhuff@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org this script gets run by the preprocesser and setup a floppy disk image containing the answers file will also setup a pxe envrionment if tftp parameter is supplied. --- client/tests/kvm/scripts/unattended.sh | 157 ++++++++++++++++++++++++++++++++ 1 files changed, 157 insertions(+), 0 deletions(-) create mode 100755 client/tests/kvm/scripts/unattended.sh \ No newline at end of file diff --git a/client/tests/kvm/scripts/unattended.sh b/client/tests/kvm/scripts/unattended.sh new file mode 100755 index 0000000..9624887 --- /dev/null +++ b/client/tests/kvm/scripts/unattended.sh @@ -0,0 +1,157 @@ +#!/bin/bash +# +# unattended.sh - sets up environment for an unattended install for kvm_autotest +# +# Copyright (C) 2009 Red Hat, Inc. +# Written by: +# David Huff +# Darryl L. Pierce +# +# 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") +log() { printf '%s: %s\n' "$*" >&2; } +die() { log "Aborting: $*"; exit 1; } +debug() { if $debugging; then log "[DEBUG] $*"; fi } + +debugging=true + +set -e + +# creates a floppy disk image and adds unattended config file +# this is prefered over vvfat b/c of know issues with fat16 +# uses loop back mout b/c -i wasent available unitil mtools > 4.0 +# $CONFIG file to put on floppy disk image +create_floppy_disk () { + local size="144" + local filename="images/$KVM_TEST_floppy" + + #create floppy disk image + debug "Creating floppy disk: filename=${filename} size=${size}" + qemu-img create -f raw $filename "${size}M" > /dev/null 2>&1 + if [ $? != 0 ]; then die "Unable to create disk image: $filename"; fi + + mkfs.msdos $filename + if [ $? != 0 ]; then die "Unable to format disk image: $filename"; fi + + #mount floppy disk image + mp=$(mktemp -d floppytmp.XXXXXX) + mount -t vfat -v -o loop $filename $mp + if [ $? != 0 ]; then die "Unable to mount disk image: $filename to: $mp"; fi + + #copy config file to disk + if [[ "$CONFIG" =~ \.ks\$ ]] || [[ "$CONFIG" =~ \.cfg\$ ]]; then + cp $CONFIG $mp/ks.cfg + elif [[ "$CONFIG" =~ \.sif\$ ]]; then + cp $CONFIG $mp/winnt.sif + else + cp $CONFIG $mp + fi + + #unmount floppy + df | grep $mp > /dev/null 2>&1 && umount -v $mp + rmdir $mp +} + + +# setup pxeboot evironment +# $PXE - iso image +# $ARGS - kernel arguments +setup_pxeboot () { + local workdir="images/$KVM_TEST_tftp" + 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 -t iso9660 -v -o ro,loop "$iso" $mp + if [ $? != 0 ]; then die "Unable to mount cd image: $iso to: $mp"; fi + + + # Does it look like an ISO? + if [ ! -d $mp/$cdlocation ]; then + die "The ISO image does not 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 APPEND initrd=initrd.img $ARGS" + + debug "pxeboot definition=\n${definition}" + printf "${definition}\n" > $pxedefault +} + +CONFIG=$KVM_TEST_unattended_file +NAME=$KVM_TEST_image +PXE=isos/$KVM_TEST_cdrom +ARGS=$KVM_TEST_kernel_args + + +# check to see we are root +if [ $( id -u ) -ne 0 ]; then + die "Must run as root" +fi + +# Require "CONFIG_FILE" +if [[ ! -e $CONFIG ]]; then + die "no unattended config file found: "$CONFIG"" +fi + +log "using unattended config file: $CONFIG" + +# create teh floppy image +create_floppy_disk $CONFIG + +if [[ ! -z $KVM_TEST_tftp ]]; then + log "using $PXE to set up pxe environmet" + setup_pxeboot +fi