-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm-creator.sh
executable file
·94 lines (84 loc) · 2.16 KB
/
vm-creator.sh
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
#!/bin/sh
set +e
FILE=roonbox-linuxx64-nuc4-usb-factoryreset.img
VM=ROCK
MEM=4096
CPUS=4
SIZE=65535
BOOT=headless
#Change boot to gui if you need to see the vm screen
echo "Creating VM"
vboxmanage createvm --name "$VM" \
--ostype "Ubuntu (64-bit)" \
--register >/dev/null 2>&1
echo "Preparing installer"
# download and prepare the installer
if [ ! -f install.vdi ]; then
if [ ! -f $FILE ]; then
if [ ! -f $FILE.gz ]; then
echo "Downloading the installer from Roon server"
wget -q https://download.roonlabs.com/builds/$FILE.gz
fi
gunzip $FILE.gz
fi
vboxmanage convertfromraw $FILE install.vdi --format VDI >/dev/null 2>&1
fi
vboxmanage createmedium disk \
--filename "$VM".vmdk \
--size $SIZE >/dev/null 2>&1
vboxmanage storagectl "$VM" \
--name "SATA" \
--add sata \
--controller IntelAHCI \
--bootable on \
--hostiocache on
vboxmanage storageattach "$VM" \
--storagectl "SATA" \
--port 0 \
--type hdd \
--hotpluggable on \
--medium install.vdi
vboxmanage storageattach "$VM" \
--storagectl "SATA" \
--port 1 \
--type hdd \
--nonrotational on \
--discard on \
--medium "$VM".vmdk
vboxmanage modifyvm "$VM" \
--boot1 disk \
--boot2 none \
--boot3 none \
--boot4 none \
--memory "$MEM" \
--cpus "$CPUS" \
--graphicscontroller vboxvga \
--firmware efi64 \
--usbxhci on \
--keyboard usb \
--nic1 nat
echo "Starting installation process"
vboxmanage startvm "$VM" --type=$BOOT >/dev/null 2>&1
sleep 20
# Type through the installation menu
vboxmanage controlvm "$VM" keyboardputscancode 02 82
vboxmanage controlvm "$VM" keyboardputscancode 1c 9c
sleep 2
vboxmanage controlvm "$VM" keyboardputscancode 02 82
vboxmanage controlvm "$VM" keyboardputscancode 1c 9c
sleep 2
vboxmanage controlvm "$VM" keyboardputscancode 15 95
vboxmanage controlvm "$VM" keyboardputscancode 1c 9c
sleep 45
#detach installer from vm
vboxmanage storageattach "$VM" \
--storagectl "SATA" \
--port 0 \
--device 0 \
--type hdd \
--medium none
rm install.vdi
rm $FILE
vboxmanage controlvm "$VM" poweroff >/dev/null 2>&1
echo "Installation complete"
echo "You can now move the $VM.vmdk virtual disk file to the destination server"