From owner-svn-src-all@FreeBSD.ORG Fri Aug 1 21:00:18 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 94C43847; Fri, 1 Aug 2014 21:00:18 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 80DEF2679; Fri, 1 Aug 2014 21:00:18 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s71L0Ixs006525; Fri, 1 Aug 2014 21:00:18 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s71L0I2D006524; Fri, 1 Aug 2014 21:00:18 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <201408012100.s71L0I2D006524@svn.freebsd.org> From: John Baldwin Date: Fri, 1 Aug 2014 21:00:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r269397 - stable/10/share/examples/bhyve X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Aug 2014 21:00:18 -0000 Author: jhb Date: Fri Aug 1 21:00:18 2014 New Revision: 269397 URL: http://svnweb.freebsd.org/changeset/base/269397 Log: MFC 256657,257423,264837,267559: Sync vmrun.sh with HEAD: - Add -e option to vmrun.sh passed to bhyveload(8) to set loader environment variables. - Stop passing unused -I option to bhyve(8). - Reformat the usage to fit in 80 colums and other cleanups. - Add -C option to specify the console device. - Add -H option to pass a host path to bhyveload(8). - Support for multiple disk and tap devices. Modified: stable/10/share/examples/bhyve/vmrun.sh Directory Properties: stable/10/ (props changed) Modified: stable/10/share/examples/bhyve/vmrun.sh ============================================================================== --- stable/10/share/examples/bhyve/vmrun.sh Fri Aug 1 20:49:27 2014 (r269396) +++ stable/10/share/examples/bhyve/vmrun.sh Fri Aug 1 21:00:18 2014 (r269397) @@ -34,17 +34,25 @@ FBSDRUN=/usr/sbin/bhyve DEFAULT_MEMSIZE=512M DEFAULT_CPUS=2 DEFAULT_TAPDEV=tap0 +DEFAULT_CONSOLE=stdio DEFAULT_VIRTIO_DISK="./diskdev" DEFAULT_ISOFILE="./release.iso" usage() { - echo "Usage: vmrun.sh [-hai][-g ][-m ][-d ][-I ][-t ] " + echo "Usage: vmrun.sh [-ahi] [-c ] [-C ] [-d ]" + echo " [-e ] [-g ] [-H ]" + echo " [-I ] [-m ]" + echo " [-t ] " + echo "" echo " -h: display this help message" - echo " -a: force memory mapped local apic access" + echo " -a: force memory mapped local APIC access" echo " -c: number of virtual cpus (default is ${DEFAULT_CPUS})" + echo " -C: console device (default is ${DEFAULT_CONSOLE})" echo " -d: virtio diskdev file (default is ${DEFAULT_VIRTIO_DISK})" + echo " -e: set FreeBSD loader environment variable" echo " -g: listen for connection from kgdb at " + echo " -H: host filesystem to export to the loader" echo " -i: force boot of the Installation CDROM image" echo " -I: Installation CDROM image location (default is ${DEFAULT_ISOFILE})" echo " -m: memory size (default is ${DEFAULT_MEMSIZE})" @@ -68,24 +76,37 @@ fi force_install=0 isofile=${DEFAULT_ISOFILE} memsize=${DEFAULT_MEMSIZE} +console=${DEFAULT_CONSOLE} cpus=${DEFAULT_CPUS} -virtio_diskdev=${DEFAULT_VIRTIO_DISK} -tapdev=${DEFAULT_TAPDEV} +tap_total=0 +disk_total=0 apic_opt="" gdbport=0 +loader_opt="" -while getopts haic:g:I:m:d:t: c ; do +while getopts ac:C:d:e:g:hH:iI:m:t: c ; do case $c in - h) - usage - ;; a) apic_opt="-a" ;; + c) + cpus=${OPTARG} + ;; + C) + console=${OPTARG} + ;; d) - virtio_diskdev=${OPTARG} + eval "disk_dev${disk_total}=\"${OPTARG}\"" + disk_total=$(($disk_total + 1)) ;; - g) gdbport=${OPTARG} + e) + loader_opt="${loader_opt} -e ${OPTARG}" + ;; + g) + gdbport=${OPTARG} + ;; + H) + host_base=`realpath ${OPTARG}` ;; i) force_install=1 @@ -93,21 +114,29 @@ while getopts haic:g:I:m:d:t: c ; do I) isofile=${OPTARG} ;; - c) - cpus=${OPTARG} - ;; m) memsize=${OPTARG} ;; t) - tapdev=${OPTARG} + eval "tap_dev${tap_total}=\"${OPTARG}\"" + tap_total=$(($tap_total + 1)) ;; - \?) + *) usage ;; esac done +if [ $tap_total -eq 0 ] ; then + tap_total=1 + tap_dev0="${DEFAULT_TAPDEV}" +fi +if [ $disk_total -eq 0 ] ; then + disk_total=1 + disk_dev0="${DEFAULT_VIRTIO_DISK}" + +fi + shift $((${OPTIND} - 1)) if [ $# -ne 1 ]; then @@ -115,26 +144,35 @@ if [ $# -ne 1 ]; then fi vmname="$1" - -# Create the virtio diskdev file if needed -if [ ! -f ${virtio_diskdev} ]; then - echo "virtio disk device file \"${virtio_diskdev}\" does not exist." - echo "Creating it ..." - truncate -s 8G ${virtio_diskdev} > /dev/null -fi - -if [ ! -r ${virtio_diskdev} ]; then - echo "virtio disk device file \"${virtio_diskdev}\" is not readable" - exit 1 +if [ -n "${host_base}" ]; then + loader_opt="${loader_opt} -h ${host_base}" fi -if [ ! -w ${virtio_diskdev} ]; then - echo "virtio disk device file \"${virtio_diskdev}\" is not writable" - exit 1 -fi +make_and_check_diskdev() +{ + local virtio_diskdev="$1" + # Create the virtio diskdev file if needed + if [ ! -f ${virtio_diskdev} ]; then + echo "virtio disk device file \"${virtio_diskdev}\" does not exist." + echo "Creating it ..." + truncate -s 8G ${virtio_diskdev} > /dev/null + fi + + if [ ! -r ${virtio_diskdev} ]; then + echo "virtio disk device file \"${virtio_diskdev}\" is not readable" + exit 1 + fi + + if [ ! -w ${virtio_diskdev} ]; then + echo "virtio disk device file \"${virtio_diskdev}\" is not writable" + exit 1 + fi +} echo "Launching virtual machine \"$vmname\" ..." +virtio_diskdev="$disk_dev0" + while [ 1 ]; do ${BHYVECTL} --vm=${vmname} --destroy > /dev/null 2>&1 @@ -163,18 +201,40 @@ while [ 1 ]; do installer_opt="" fi - ${LOADER} -m ${memsize} -d ${BOOTDISK} ${vmname} + ${LOADER} -c ${console} -m ${memsize} -d ${BOOTDISK} ${loader_opt} \ + ${vmname} if [ $? -ne 0 ]; then break fi - ${FBSDRUN} -c ${cpus} -m ${memsize} ${apic_opt} -AI -H -P \ + # + # Build up args for additional tap and disk devices now. + # + nextslot=2 # slot 0 is hostbridge, slot 1 is lpc + devargs="" # accumulate disk/tap args here + i=0 + while [ $i -lt $tap_total ] ; do + eval "tapname=\$tap_dev${i}" + devargs="$devargs -s $nextslot:0,virtio-net,${tapname} " + nextslot=$(($nextslot + 1)) + i=$(($i + 1)) + done + + i=0 + while [ $i -lt $disk_total ] ; do + eval "disk=\$disk_dev${i}" + make_and_check_diskdev "${disk}" + devargs="$devargs -s $nextslot:0,virtio-blk,${disk} " + nextslot=$(($nextslot + 1)) + i=$(($i + 1)) + done + + ${FBSDRUN} -c ${cpus} -m ${memsize} ${apic_opt} -A -H -P \ -g ${gdbport} \ -s 0:0,hostbridge \ -s 1:0,lpc \ - -s 2:0,virtio-net,${tapdev} \ - -s 3:0,virtio-blk,${virtio_diskdev} \ - -l com1,stdio \ + ${devargs} \ + -l com1,${console} \ ${installer_opt} \ ${vmname} if [ $? -ne 0 ]; then