From owner-svn-src-projects@FreeBSD.ORG Sat Jul 12 22:27:22 2014 Return-Path: Delivered-To: svn-src-projects@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 4159AF10; Sat, 12 Jul 2014 22:27:22 +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 2E3472989; Sat, 12 Jul 2014 22:27:22 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6CMRMUL057143; Sat, 12 Jul 2014 22:27:22 GMT (envelope-from gjb@svn.freebsd.org) Received: (from gjb@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s6CMRM55057142; Sat, 12 Jul 2014 22:27:22 GMT (envelope-from gjb@svn.freebsd.org) Message-Id: <201407122227.s6CMRM55057142@svn.freebsd.org> From: Glen Barber Date: Sat, 12 Jul 2014 22:27:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r268577 - projects/release-embedded/release/cloudware X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Jul 2014 22:27:22 -0000 Author: gjb Date: Sat Jul 12 22:27:21 2014 New Revision: 268577 URL: http://svnweb.freebsd.org/changeset/base/268577 Log: Initial commit of a script to generate VHD files for the Microsoft Azure environment. There are a few issues outstanding with the image in the Azure environment, however this script does generate images that boot in Hyper-V. Sponsored by: The FreeBSD Foundation Added: projects/release-embedded/release/cloudware/release-azure.sh (contents, props changed) Added: projects/release-embedded/release/cloudware/release-azure.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/release-embedded/release/cloudware/release-azure.sh Sat Jul 12 22:27:21 2014 (r268577) @@ -0,0 +1,108 @@ +#!/bin/sh +#- +# Copyright (c) 2014 The FreeBSD Foundation +# All rights reserved. +# +# This software was developed by Glen Barber +# under sponsorship from the FreeBSD Foundation. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin +export PATH + +if [ $# -ne 2 ]; then + echo "make-memstick.sh /path/to/directory /path/to/image/file" + exit 1 +fi + +if [ -e ${2} ]; then + echo "won't overwrite ${2}" + exit 1 +fi + +main() { + mkdir -p ${1} + touch ${2}.raw + truncate -s 3G ${2}.raw + mddev=$(mdconfig -a -t vnode -f ${2}.raw) + + gpart create -s gpt /dev/${mddev} + gpart add -t freebsd-boot -s 512k -l bootfs /dev/${mddev} + gpart add -t freebsd-ufs -l rootfs /dev/${mddev} + newfs -L rootfs /dev/${mddev}p2 + mount /dev/${mddev}p2 ${1} + mkdir -p ${1}/dev + + for i in base kernel lib32; do + tar -xzf ${i}.txz -C ${1} + done + + gpart bootcode -b ${1}/boot/pmbr -p ${1}/boot/gptboot -i 1 /dev/${mddev} + + echo "# Custom /etc/fstab for Microsoft Azure VM images" \ + > ${1}/etc/fstab + echo "/dev/gpt/rootfs / ufs rw 2 2" \ + >> ${1}/etc/fstab + + cp /etc/resolv.conf ${1}/etc/resolv.conf + mount -t devfs devfs ${1}/dev + + chroot ${1} /etc/rc.d/ldconfig forcestart + chroot ${1} env ASSUME_ALWAYS_YES=1 /usr/sbin/pkg install -y \ + python python2 python27 py27-asn1 sudo bash + fetch -o ${1}/usr/sbin/waagent http://people.freebsd.org/~gjb/waagent + chmod +x ${1}/usr/sbin/waagent + chroot ${1} ln -s /usr/local/bin/python /usr/bin/python + rm -f ${1}/etc/resolv.conf + + chroot ${1} /usr/sbin/waagent -verbose -install + cat ${1}/var/log/waagent.log + yes | chroot ${1} /usr/sbin/waagent -deprovision + + echo 'sshd_enable="YES"' > ${1}/etc/rc.conf + echo 'ifconfig_hn0="SYNCDHCP"' >> ${1}/etc/rc.conf + echo 'waagent_enable="YES"' >> ${1}/etc/rc.conf + + # Make sure we wait until the md(4) is unmounted before destroying it. + while ! umount ${1}/dev; do + sleep 1 + done + while ! umount ${1}; do + sleep 1 + done + + /usr/bin/mkimg -f vhd \ + -s gpt -b /boot/pmbr \ + -p freebsd-boot:=/dev/${mddev}p1 \ + -p freebsd-ufs/rootfs:=/dev/${mddev}p2 \ + -p freebsd-swap::1M \ + -p freebsd-ufs::1G \ + -o ${2} + + mdconfig -d -u ${mddev} +} + +main "$@"