forked from jasherai/ubuntu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-vbox
executable file
·99 lines (90 loc) · 2.57 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
93
94
95
96
97
98
99
#!/bin/sh
set -e
. "$(dirname $0)/config.sh"
for ARCH in $ARCHS
do
ISO="${ISOPREFIX}-ubuntu-$VERSION-$DISTRO-$ARCH.iso"
VBOX="${LABEL}-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,,2222,,22 \
--audio none \
--clipboard disabled \
--usb off --usbehci off \
--vrdp off \
--teleporter off
# Mount the custom installation ISO.
VBoxManage storagectl "$VBOX" \
--name IDE \
--add ide
VBoxManage storageattach "$VBOX" \
--storagectl IDE \
--port 1 --device 0 \
--type dvddrive --medium "$PWD/$ISO"
# 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"
# 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
## Set better perms on the private key to avoid ssh abort
chmod 600 ${PRIVATE_KEY}
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 IDE \
--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 IDE \
--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
VBoxManage snapshot "${VBOX}" take "AUTO_${LABEL}_base_build #000001" --description "Snapshot taken after initial build to be able to restore back when recreating vagrant boxes"
done