-
-
Save lucafavatella/61a9c08cc2ee5a2e81f9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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. | |
| # 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 | |
| # Ubuntu distro settings. Change mirror or version as required. | |
| IMAGEDIR=/var/lib/xen/images/ubuntu-netboot | |
| MIRROR=http://ubuntu.arcticnetwork.ca/ | |
| DISTRO=/ubuntu/dists/precise/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 Xen Config | |
| CONFIG=/etc/xen/$NAME.cfg | |
| if [ -f "$CONFIG" ]; | |
| then | |
| mv $CONFIG $CONFIG.old | |
| fi | |
| 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" | |
| EOL | |
| #Launch the VM and connect to console to complete Ubuntu installation | |
| xm create /etc/xen/$NAME.cfg -c | |
| #Modify Xen Config to use the kernel configured during the installation | |
| sed -i '/kernel/d' $CONFIG | |
| sed -i '/ramdisk/d' $CONFIG | |
| sed -i '/extra/d' $CONFIG | |
| echo "bootloader=\"pygrub\"" >> $CONFIG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment