From owner-freebsd-rc@FreeBSD.ORG Fri Jan 24 04:01:16 2014 Return-Path: Delivered-To: freebsd-rc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A5EF8258; Fri, 24 Jan 2014 04:01:16 +0000 (UTC) Received: from mail-pd0-x22f.google.com (mail-pd0-x22f.google.com [IPv6:2607:f8b0:400e:c02::22f]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 707E31F9B; Fri, 24 Jan 2014 04:01:16 +0000 (UTC) Received: by mail-pd0-f175.google.com with SMTP id w10so2615918pde.34 for ; Thu, 23 Jan 2014 20:01:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=+rufZd1bq3fyunkepR3cDCV68zr6J+JnUbUltzTDv4M=; b=oXCucE53sXe07bcWcUPfJaiutmrnUlriGSWWjgDOHLtnfgEK4ZNXDy2kYqrYAiGspc rEszKMb5bt5OCxJNxCnlUlTZI5ruMhZxXhbreUB9orQ8ia38HlLV2go/AhuM6RYW/nGJ Tj1GvRH+zePRF45Ym3ziGU6itGCoqrsd3S9jw2CcO7ombR7tXmH1aHZAgBYzCdc8Kha1 8wOdX0G7WRBQWPLNdH1AWoQ/5m5JdFVFWmljPTSgq2SewNsfn1XBJ49XRM0mJMb8cv7u t3+lLabxeBLf4rqMPD9pqoX26lbU/9el+fsUM3MLu3pDjOtUR7Kc/7ibq9ka83ff3aU2 tfWQ== MIME-Version: 1.0 X-Received: by 10.66.192.74 with SMTP id he10mr12055866pac.126.1390536075908; Thu, 23 Jan 2014 20:01:15 -0800 (PST) Received: by 10.68.155.38 with HTTP; Thu, 23 Jan 2014 20:01:15 -0800 (PST) In-Reply-To: References: Date: Thu, 23 Jan 2014 23:01:15 -0500 Message-ID: Subject: Re: rc.d scripts for starting BHyve from rc.d From: Aryeh Friedman To: Craig Rodrigues Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.17 Cc: freebsd-rc@freebsd.org, "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jan 2014 04:01:16 -0000 Except for the consoles petitecloud does it much more smoothly (see thread on getting linux to run on bhyve on -RELEASE for the script).... namely it should not need conditional logic (instead of being autogenerated on demand) On Thu, Jan 23, 2014 at 10:44 PM, Craig Rodrigues wrote: > Hi, > > I put together some scripts for starting a BHyve VM > when a system boots. When the system boots, the console > of the VM uses /dev/nmdm. It is possible to connect > to the console of the VM with: cu -l /dev/nmdm0B > > It is a bit rough, but works nicely. > Does someone out there have better scripts for doing this? > > Can some of the existing rc.d scripts for jails be reused for BHyve? > > > > > I did the following: > > == put following entries in /etc/sysctl.conf == > # BHyve needs this for tap interfaces > net.link.tap.user_open=1 > net.link.tap.up_on_open=1 > ================================================================= > > == put following in /etc/rc.conf == > ##################################################### > # Create tap devices, one tap interface per BHyve VM. > # Add the tap interfaces to bridge0 > #################################################### > cloned_interfaces="bridge0 tap0" > > autobridge_interfaces="bridge0" > # change igb0 to whatever NIC you are using > autobridge_bridge0="tap* igb0" > > > > == put following file in /usr/local/etc/rc.d/bhyvevm == > #!/bin/sh > # > # $FreeBSD$ > # > > # PROVIDE: bhyvevm > # REQUIRE: netif bgfsck sshd LOGIN localpkg > # KEYWORD: shutdown > # > > . /etc/rc.subr > > name="bhyvevm" > rcvar="bhyvevm_enable" > > start_cmd="bhyvevm_start" > stop_cmd="bhyvevm_stop" > > # read configuration and set defaults > load_rc_config "$name" > : ${bhyvevm_enable="YES"} > > > bhyvevm_start() > { > /vm/10.0/start_vm.sh > } > > bhyvevm_stop() > { > /vm/10.0/stop_vm.sh vm1 > } > run_rc_command "$1" > > == put following script in /vm/10.0/start_vm.sh == > #!/bin/sh > VM=vm1 > CONS_A=/dev/nmdm0A > CONS_B=${CONS_A%%A}B > IMG=/vm/10.0/disk.img > TAP=tap0 > BRIDGE=bridge0 > > touch ${CONS_A} > if [ -e /dev/vmm/${VM} ]; then > /usr/sbin/bhyvectl --vm=${VM} --destroy > fi > > echo "Starting BHyve virtual machine named '${VM}'. Use 'cu -l ${CONS_B}' > to access console" > cmd="/usr/sbin/bhyveload -m 8G -d ${IMG} -c ${CONS_A} ${VM}" > $cmd > ret=$? > if [ $ret -ne 0 ]; then > echo "[FAILED]: $cmd" > exit $ret > fi > ifconfig bridge0 up > cmd="/usr/sbin/bhyve -c 16 -m 8G -A -H -P -g 0 -s 0:0,hostbridge -s 1:0,lpc > -s 2:0,virtio-net,${TAP} -s 3:0,virtio-blk,${IMG} -l com1,${CONS_A} ${VM}" > $cmd & > ifconfig bridge0 up > sleep 5 > echo "~." | cu -l ${CONS_B} > ================================================================= > > ==== put following script in /vm/10.0/stop_vm.sh === > #!/bin/sh > > usage() > { > echo $0 "[vm name]" > } > > if [ $# -lt 1 ]; then > usage > exit 1 > fi > VM=$1 > > echo "Stopping BHyve virtual machine named '$VM'" > > PID=`pgrep bhyve` > if [ -n "$PID" ]; then > kill $PID > fi > > COUNT=0 > while [ $COUNT -lt 20 -a -n "$PID" ] ; do > PID2=`pgrep bhyve` > if [ "$PID" != "$PID2" ]; then > break > fi > sleep 5 > done > > if [ -e /dev/vmm/${VM} ]; then > /usr/sbin/bhyvectl --vm=${VM} --destroy > fi > > exit 0 > ================================================================= > > > > -- > Craig > _______________________________________________ > freebsd-virtualization@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-virtualization > To unsubscribe, send any mail to " > freebsd-virtualization-unsubscribe@freebsd.org" > -- Aryeh M. Friedman, Lead Developer, http://www.PetiteCloud.org