Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Jul 2014 22:27:22 +0000 (UTC)
From:      Glen Barber <gjb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r268577 - projects/release-embedded/release/cloudware
Message-ID:  <201407122227.s6CMRM55057142@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 "$@"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201407122227.s6CMRM55057142>