#!/bin/bash ###################################################################################### # Derived from the following pust by Alvin Cura # https://bugs.launchpad.net/ubuntu/+source/xen-3.1/+bug/144631/comments/25 # Largely modified by Austin Godber (godber@uberhip.com) ###################################################################################### usage() { printf "USAGE:\t ${0} [root part size] [swap part size]\n\n" printf "\t ${0} ldapvm 5G 1G\n" printf "\t Partition sizes must be acceptible dd sizes: 1G, 512M\n" exit } if [ -z ${1} ]; then usage; else xendomu=${1}; fi if [ -z ${2} ]; then rootsize="4G"; else rootsize=${2}; fi if [ -z ${3} ]; then swapsize="512M"; else swapsize=${3}; fi ###################################### # Set up some variables ###################################### # Add an optional mirror mirror="http://10.6.6.2/apt-cacher/us.archive.ubuntu.com/ubuntu/" basedir="/vms/generated" if [ ! -d "${basedir}" ]; then printf "Creating ${basedir}\n" mkdir -p ${basedir} || {echo "Unable to create base VM directory: ${basedir}"; exit} fi xendir="${basedir}/${xendomu}" printf "Creating directory ${xendir}: " mkdir -p -m 0777 ${xendir} || {echo "Unable to create VM directory: ${xendir}"; exit} printf "done.\n" ###################################### # Prepare Block Devices ###################################### printf "Creating sparse root volume ${xendir}/root.img with size ${rootsize}: " dd if=/dev/zero of=${xendir}/root.img bs=1 count=0 seek=${rootsize} printf "done.\n" printf "Creating swap volume ${xendir}/swap.img with size ${swapsize}: " dd if=/dev/zero of=${xendir}/swap.img bs=${swapsize} count=1 printf "done.\n" printf "Creating ext3 filesystem on ${xendir}/root.img: " mkfs.ext3 -F ${xendir}/root.img printf "done.\n" printf "Creating swap partition on ${xendir}/swap.img: " mkswap ${xendir}/swap.img printf "done.\n" printf "Mounting ${xendir}/root.img on /tmp/${xendomu}: " mkdir /tmp/${xendomu} mount ${xendir}/root.img /tmp/${xendomu} -o loop printf "done.\n" ###################################### # Fill it up with Linuxy Goodness ###################################### printf "Debootstrapping ${xendomu}: " debootstrap gutsy /tmp/${xendomu} ${mirror} printf "done.\n" printf "Copying modules to ${xendomu}: " cp -r /lib/modules/`uname -r` /tmp/${xendomu}/lib/modules/ printf "done.\n" printf "Setting up fstab: " cat > /tmp/${xendomu}/etc/fstab < /tmp/${xendomu}/etc/hostname printf "done.\n" printf "Setting up hosts: " printf "127.0.0.1\tlocalhost\n127.0.1.1\t${xendomu}\n" > /tmp/${xendomu}/etc/hosts printf "done.\n" printf "Setting up network interfaces: " cat > /tmp/${xendomu}/etc/network/interfaces < /tmp/${xendomu}/etc/apt/sources.list printf "done.\n" printf "Updating apt: " chroot /tmp/${xendomu} apt-get update printf "done.\n" # This is a Xen compatability thing, Xen Paravirt doesn't work with # TLS (Thread Local Storage) Libraries, moving them is the common work # around. printf "Disabling thread local storage libraries: " mv /tmp/${xendomu}/lib/tls /tmp/${xendomu}/lib/tls.disabled printf "done.\n" # These are workarounds for Ubuntu 7.10 bugs, the bugs require # slight guest (DomU) modification printf "Doing tweaks required for Ubuntu 7.10 Dom0 in DomU: " chroot /tmp/${xendomu} update-rc.d -f hwclock.sh remove chroot /tmp/${xendomu} update-rc.d -f hwclockfirst.sh remove chroot /tmp/${xendomu} rm /etc/udev/rules.d/85-hwclock.rules printf "done.\n" printf "Unmounting /tmp/${xendomu} and removing mount point: " umount /tmp/${xendomu} rmdir /tmp/${xendomu} printf "done.\n" ###################################### # Generate the Xen Configuration File ###################################### printf "Generating Xen config file: " cat > ${xendir}/${xendomu}.cfg <