summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Maw <jonathan.maw@codethink.co.uk>2012-12-03 17:17:17 +0000
committerJonathan Maw <jonathan.maw@codethink.co.uk>2012-12-03 17:17:17 +0000
commitd3f04b9de015d04fffd70387314b0367502c8d5c (patch)
treed82c26c6ca37692c302adfb49cb494770127b670
parentac89056ad3c596eb5ea7bd18ad8b2a4dccc180ca (diff)
downloadgenivi-initial-setup-d3f04b9de015d04fffd70387314b0367502c8d5c.tar.gz
Add script to set create and set up a virtualbox vm
-rwxr-xr-xbaserock-install-vm76
1 files changed, 76 insertions, 0 deletions
diff --git a/baserock-install-vm b/baserock-install-vm
new file mode 100755
index 0000000..74f7966
--- /dev/null
+++ b/baserock-install-vm
@@ -0,0 +1,76 @@
+#!/bin/sh
+set -e
+
+DEVEL_IMAGE_NAME="water-bomb-devel-x86_64"
+
+# Usage: baserock-install-vm $VM_NAME $INSTALL_DIRECTORY
+VM_NAME="$1"
+INSTALL_DIRECTORY="$2"
+
+VM_VBOX_NAME=$(echo "$VM_NAME" | sed 's|\s|\.|g')
+
+if [ -z "$VM_NAME" ]; then
+ echo "A name must be specified for this virtual machine"
+ echo "Usage: $0 VM_NAME INSTALL_DIRECTORY"
+ false
+fi
+
+if [ -z "$INSTALL_DIRECTORY" ]; then
+ echo "An install directory must be specified for this virtual machine"
+ echo "Usage: $0 VM_NAME INSTALL_DIRECTORY"
+ false
+fi
+
+# Check that we don't already have a VM of this name
+if [ -e "$VM_NAME.vdi" ]; then
+ echo "A VM by this name already exists"
+ false
+fi
+
+# Ensuring VirtualBox is installed
+if which VBoxManage >/dev/null; then
+ echo "VirtualBox is installed"
+else
+ echo "VirtualBox is not installed"
+ if which yum >/dev/null; then
+ echo "Attempting to install VirtualBox using yum"
+ sudo yum install VirtualBox
+ elif which apt-get >/dev/null; then
+ echo "Attempting to install VirtualBox using apt-get"
+ sudo apt-get install virtualbox-ose
+ fi
+fi
+
+cd "$INSTALL_DIRECTORY"
+
+# Download and extract the water-bomb .img file
+wget --no-clobber "http://download.baserock.org/baserock/$DEVEL_IMAGE_NAME.img.gz"
+
+if [ -e $DEVEL_IMAGE_NAME.img ]; then
+ echo "Development image has already been decompressed"
+else
+ echo "Decompressing development image"
+ gzip -c "$DEVEL_IMAGE_NAME.img.gz" >"$DEVEL_IMAGE_NAME.img"
+fi
+
+# Convert the .img file into a VirtualBox .vdi and create the virtual machine
+VBoxManage convertdd "$DEVEL_IMAGE_NAME.img" "$VM_NAME.vdi"
+VBoxManage createvm --name "$VM_VBOX_NAME" --ostype Linux26_64 --register
+
+
+# Configure the virtual machine
+VBoxManage modifyvm "$VM_VBOX_NAME" --ioapic off --memory 1024 --nic1 nat
+
+
+# Configure the virtual machine's first hard disk
+VBoxManage storagectl "$VM_VBOX_NAME" --name "SATA Controller" --add sata --bootable on --sataportcount 2
+
+VBoxManage storageattach "$VM_VBOX_NAME" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "$VM_NAME.vdi"
+
+
+# Configure the /src partition
+VBoxManage createhd --filename "$VM_NAME-src.vdi" --size $((30*1024))
+
+VBoxManage storageattach "$VM_VBOX_NAME" --storagectl "SATA Controller" --port 1 --device 0 --type hdd --medium "$VM_NAME-src.vdi"
+
+cd - >/dev/null