-
Notifications
You must be signed in to change notification settings - Fork 35
/
build-vbox
executable file
·92 lines (82 loc) · 2.22 KB
/
build-vbox
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
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/sh
set -e
. "$(dirname $0)/config.sh"
ISO="$NICKNAME-ubuntu-$VERSION-$DISTRO-$ARCH.iso"
VBOX="$NICKNAME-ubuntu-$VERSION-$DISTRO-$ARCH"
# Create and configure a virtual machine through VirtualBox.
VBoxManage createvm \
--name "$VBOX" \
--basefolder "$PWD" \
--register \
|| true
VBoxManage modifyvm "$VBOX" \
--ostype "Ubuntu$([ "$ARCH" = "i386" ] || echo _64)" \
--memory 360 \
--vram 12 \
--acpi on --ioapic on \
--cpus 1 \
--pae "$([ "$ARCH" = "i386" ] && echo on || echo off)" \
--hwvirtex on \
--hwvirtexexcl off \
--nestedpaging on \
--accelerate3d off \
--nic1 nat \
--natpf1 guestssh,tcp,,"$SSH_PORT",,22 \
--audio none \
--clipboard disabled \
--usb off --usbehci off \
--vrde off \
--teleporter off
# Mount a virtual hard disk.
VBoxManage createhd \
--filename "$PWD/$VBOX/$VBOX.vmdk" \
--size 40000 \
--format VMDK \
|| true
VBoxManage storagectl "$VBOX" \
--name SATA \
--add sata
VBoxManage storageattach "$VBOX" \
--storagectl SATA \
--port 0 --device 0 \
--type hdd --medium "$PWD/$VBOX/$VBOX.vmdk"
# "Insert" install iso into virtual cd drive
VBoxManage storageattach "$VBOX" \
--storagectl SATA \
--port 1 --device 0 \
--type dvddrive --medium "$PWD/$ISO"
# Start the virtual machine and the OS installation. This will take
# a while so this time it gets a GUI. Spin slowly until SSH is usable.
VBoxManage startvm "$VBOX" --type gui
echo "Waiting for installion to finish.."
until eval "$SSH exit"
do
sleep 60
done
# Attach the VBoxGuestAdditions ISO, implicitly detaching the custom
# installation ISO in the process. Install the additions and empty
# the drive.
VBoxManage storageattach "$VBOX" \
--storagectl SATA \
--port 1 --device 0 \
--type dvddrive --medium "$VBOX_GUEST_ADDITIONS"
eval "$SSH \"
set -e
sudo apt-get -y install linux-headers-\\\$(uname -r) build-essential
until sudo mount /dev/cdrom /media/cdrom
do
sleep 1
done
sudo /media/cdrom/VBoxLinuxAdditions.run
sudo umount /media/cdrom
\""
VBoxManage storageattach "$VBOX" \
--storagectl SATA \
--port 1 --device 0 \
--type dvddrive --medium emptydrive
# Shutdown the virtual machine.
eval "$SSH \"sudo shutdown -h now\""
until VBoxManage showvminfo "$VBOX" | grep "^State: *powered off"
do
sleep 1
done