summaryrefslogtreecommitdiff
path: root/create-vm
blob: 3ee03919203d276e2a3f87e87f325124bbd1b889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/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
	else
		echo "I do not know how to install VirtualBox on this system. Please install manually"
		false
	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 -dc "$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