Date: Wed, 12 Feb 2014 15:37:04 -0700 From: John Nielsen <lists@jnielsen.net> To: Neel Natu <neel@freebsd.org> Cc: freebsd-virtualization@freebsd.org Subject: Proposed patch for vmrun.sh Message-ID: <7414975C-B9E6-4B13-8F08-9940FF895546@jnielsen.net>
next in thread | raw e-mail | index | archive | help
--Apple-Mail=_9C1C27D8-519D-4B6F-9C2A-02955E3A8600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii See attached patch for vmrun.sh. It contains two changes: * Use an "err" function that prints to stderr instead of "echo" for = text output * Use "file -s" instead of "file" to allow it to check block devices = (zvol, etc) Feel free to commit it if you find it useful. Thanks! --Apple-Mail=_9C1C27D8-519D-4B6F-9C2A-02955E3A8600 Content-Disposition: attachment; filename=vmrun.sh.patch Content-Type: application/octet-stream; name="vmrun.sh.patch" Content-Transfer-Encoding: 7bit --- share/examples/bhyve/vmrun.sh.orig 2014-02-12 15:20:37.695377968 -0700 +++ share/examples/bhyve/vmrun.sh 2014-02-12 15:25:09.366589771 -0700 @@ -30,6 +30,7 @@ LOADER=/usr/sbin/bhyveload BHYVECTL=/usr/sbin/bhyvectl FBSDRUN=/usr/sbin/bhyve +FILE="/usr/bin/file -s" DEFAULT_MEMSIZE=512M DEFAULT_CPUS=2 @@ -38,21 +39,25 @@ DEFAULT_VIRTIO_DISK="./diskdev" DEFAULT_ISOFILE="./release.iso" +err() { + echo "$*" >&2 +} + usage() { - echo "Usage: vmrun.sh [-hai][-g <gdbport>][-m <memsize>][-d <disk file>][-e <name=value>][-I <location of installation iso>][-t <tapdev>] <vmname>" - echo " -h: display this help message" - echo " -a: force memory mapped local apic access" - echo " -c: number of virtual cpus (default is ${DEFAULT_CPUS})" - 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 <gdbport>" - 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})" - echo " -t: tap device for virtio-net (default is $DEFAULT_TAPDEV)" - echo "" - echo " This script needs to be executed with superuser privileges" - echo "" + err "Usage: vmrun.sh [-hai][-g <gdbport>][-m <memsize>][-d <disk file>][-e <name=value>][-I <location of installation iso>][-t <tapdev>] <vmname>" + err " -h: display this help message" + err " -a: force memory mapped local apic access" + err " -c: number of virtual cpus (default is ${DEFAULT_CPUS})" + err " -d: virtio diskdev file (default is ${DEFAULT_VIRTIO_DISK})" + err " -e: set FreeBSD loader environment variable" + err " -g: listen for connection from kgdb at <gdbport>" + err " -i: force boot of the Installation CDROM image" + err " -I: Installation CDROM image location (default is ${DEFAULT_ISOFILE})" + err " -m: memory size (default is ${DEFAULT_MEMSIZE})" + err " -t: tap device for virtio-net (default is $DEFAULT_TAPDEV)" + err "" + err " This script needs to be executed with superuser privileges" + err "" exit 1 } @@ -62,7 +67,7 @@ kldstat -n vmm > /dev/null 2>&1 if [ $? -ne 0 ]; then - echo "vmm.ko is not loaded!" + err "vmm.ko is not loaded!" exit 1 fi @@ -123,30 +128,30 @@ # 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 ..." + err "virtio disk device file \"${virtio_diskdev}\" does not exist." + err "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" + err "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" + err "virtio disk device file \"${virtio_diskdev}\" is not writable" exit 1 fi -echo "Launching virtual machine \"$vmname\" ..." +err "Launching virtual machine \"$vmname\" ..." while [ 1 ]; do ${BHYVECTL} --vm=${vmname} --destroy > /dev/null 2>&1 - file ${virtio_diskdev} | grep ": x86 boot sector" > /dev/null + ${FILE} ${virtio_diskdev} | grep ": x86 boot sector" > /dev/null rc=$? if [ $rc -ne 0 ]; then - file ${virtio_diskdev} | grep ": Unix Fast File sys" > /dev/null + ${FILE} ${virtio_diskdev} | grep ": Unix Fast File sys" > /dev/null rc=$? fi if [ $rc -ne 0 ]; then @@ -157,8 +162,8 @@ if [ $force_install -eq 1 -o $need_install -eq 1 ]; then if [ ! -r ${isofile} ]; then - echo -n "Installation CDROM image \"${isofile}\" " - echo "is not readable" + err -n "Installation CDROM image \"${isofile}\" " + err "is not readable" exit 1 fi BOOTDISK=${isofile} --Apple-Mail=_9C1C27D8-519D-4B6F-9C2A-02955E3A8600 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_9C1C27D8-519D-4B6F-9C2A-02955E3A8600--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7414975C-B9E6-4B13-8F08-9940FF895546>