From owner-freebsd-virtualization@FreeBSD.ORG Fri Jan 24 03:44:25 2014 Return-Path: Delivered-To: freebsd-virtualization@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 E0D87E1A; Fri, 24 Jan 2014 03:44:25 +0000 (UTC) Received: from mail-lb0-x233.google.com (mail-lb0-x233.google.com [IPv6:2a00:1450:4010:c04::233]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 26B411E80; Fri, 24 Jan 2014 03:44:24 +0000 (UTC) Received: by mail-lb0-f179.google.com with SMTP id l4so2162325lbv.10 for ; Thu, 23 Jan 2014 19:44:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=baz+ODQiro/KRUCgMRlm1/uk4nzl+jO2yPyFJ2GZ184=; b=hKknHjFFdits4kKW8Qj+qe9Byphm4n/lrAnj144o4YHEI9mLQ6/xzD3BRgiXD2KZ/6 tzDhz9sfWiyDLxZwYedUJE0t1PQoe/zrNamZoOmTv//uxc0Wsb1nHd4Rlft3lAlVn4PK jLq9dxGHTL/QIQ6n5rl4GPhPNq8MBB6vrQl6dSPCsk7k8Uc2an5A0CUCNPHwUOaTGT3Z oYqbDHeux/2zrE1t6ky58v2smLglfa6Vld1HEmzFoosTvvvTZbpfidujpJybGICqg+Ai ylKQY4gzd0SBRLRu9WuAAvGdMieej1xKjWDFfxbkdaLjJQWEB9T+BObPngeETZLTGbqO 4KJA== MIME-Version: 1.0 X-Received: by 10.112.135.9 with SMTP id po9mr7033289lbb.8.1390535062969; Thu, 23 Jan 2014 19:44:22 -0800 (PST) Sender: crodr001@gmail.com Received: by 10.112.148.4 with HTTP; Thu, 23 Jan 2014 19:44:22 -0800 (PST) Date: Thu, 23 Jan 2014 19:44:22 -0800 X-Google-Sender-Auth: KzVcRkipI6rzL7k1Up7AnM8tERI Message-ID: Subject: rc.d scripts for starting BHyve from rc.d From: Craig Rodrigues To: "freebsd-virtualization@freebsd.org" , freebsd-rc@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.17 X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Discussion of various virtualization techniques FreeBSD supports." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jan 2014 03:44:26 -0000 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