Last active
March 9, 2016 13:08
-
-
Save abythell/5267489 to your computer and use it in GitHub Desktop.
Bash script to install Ubuntu 12.04 as a Xen paravitualized domU guest on a Xen host with LVM.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script to download, configure, and install Ubuntu as a Xen domU | |
# Uses existing LVM Volume Group. Must be run as root/sudo. | |
# Based on instructions at https://help.ubuntu.com/community/Xen | |
# User Configurable Settings | |
NAME=ubuntu # name of Domain to create | |
VG=/dev/domU # existing volume group in which to create a logical volume | |
LV=$NAME # name of the new logical volume to create | |
LV_SIZE=5G # size of the new logical volume | |
MEM_SIZE=512 # memory to allocate to this VM | |
RELEASE=precise # "precise" (12.04LTS) or "quantal" (12.10) | |
# Ubuntu distro settings. Change mirror or version as required. | |
IMAGEDIR=/var/lib/xen/images/ubuntu-netboot | |
MIRROR=http://ubuntu.arcticnetwork.ca/ | |
DISTRO=/ubuntu/dists/$RELEASE/main/installer-amd64/current/images/netboot/xen | |
#Create Disk | |
lvcreate -L $LV_SIZE -n $LV $VG | |
#Get Ubuntu Netboot kernel and ramdisk | |
if [ ! -d "$IMAGEDIR" ]; then | |
mkdir -p $IMAGEDIR | |
cd $IMAGEDIR | |
wget $MIRROR/$DISTRO/initrd.gz | |
wget $MIRROR/$DISTRO/vmlinuz | |
fi | |
#Create pre-install Xen Config | |
CONFIG=/etc/xen/$NAME.cfg | |
if [ -f "$CONFIG" ]; | |
then | |
mv $CONFIG $CONFIG.old | |
fi | |
# on_reboot="destroy" is used in the initial config because we need to modify | |
# the Xen config file before restarting when the install is complete. | |
cat >> $CONFIG << EOL | |
name="$NAME" | |
memory=$MEM_SIZE | |
disk=['phy:$VG/$LV,xvda,w'] | |
vif=['bridge=xenbr0'] | |
vfb=['vnc=1'] | |
kernel="$IMAGEDIR/vmlinuz" | |
ramdisk="$IMAGEDIR/initrd.gz" | |
on_reboot="destroy" | |
extra="console=hvc0" | |
EOL | |
#Launch the VM and connect to console to complete Ubuntu installation. | |
xm create /etc/xen/$NAME.cfg -c | |
#Modify the post-install Xen Config | |
sed -i '/kernel/d' $CONFIG | |
sed -i '/ramdisk/d' $CONFIG | |
sed -i '/on_reboot/d' $CONFIG | |
echo "bootloader=\"pygrub\"" >> $CONFIG | |
#Launch the new VM | |
xm create /etc/xen/$NAME.cfg -c | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment