-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0.sh
executable file
·138 lines (124 loc) · 3.8 KB
/
0.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
VBM=VBoxManage
ISO=$1
# VirtualBox Setup
# VM config: 1cpu+768MB+256GB (will override first two with vagrant)
# General->Advanced: bidirectional + bidirectional
# System->Processor: PAE
# Display->Video: enough for UHD
# Storage: add xubuntu CD + harddisk type SSD
# Network->Adapter 1->NAT + virtio-net
CPUS=1
DISKSIZEGB=${2:-256}
MEM=768 #512 is too small for desktop
VRAM=$((2+3840*2160*4/1048576)) #UHD + 2
if [ ! -f "$1" ]; then
cat <<EOM
Usage:
yourself@host\$ ./0.sh iso-path [disk-size-in-GB (default $DISKSIZEGB)]
EOM
else
# register VM
read -ep 'VM name (try "XU64Base"): ' \
$([ $BASH_VERSINFO -ge 4 ] && echo '-i XU64Base') \
VMNAME
VMUUID=$($VBM createvm --name "$VMNAME" --ostype Ubuntu_64 --register |
gawk '/^UUID:/{print $2}')
echo 'VM registered.'
# configure VM
$VBM modifyvm $VMUUID \
--accelerate2dvideo off \
--accelerate3d off `#https://www.virtualbox.org/ticket/10250` \
--audio coreaudio \
--audiocontroller ac97 \
--clipboard bidirectional \
--cpus $CPUS \
--draganddrop bidirectional \
--memory $MEM \
--mouse usbtablet \
--nic1 nat \
--nictype1 virtio \
--pae on \
--rtcuseutc on \
--usb on \
--usbehci on \
--vram $VRAM \
`#end`
# configure IDE and attach Xubuntu iso
$VBM storagectl $VMUUID \
--add ide \
--bootable on \
--controller PIIX4 \
--hostiocache on \
--name IDE \
--portcount 2 \
`#end`
$VBM storageattach $VMUUID \
--device 0 \
--medium "$ISO" \
--port 1 \
--storagectl IDE \
--type dvddrive \
`#end`
# attach Guest Additions iso
# https://www.virtualbox.org/ticket/13040
$VBM storageattach $VMUUID \
--device 1 \
--medium emptydrive \
--port 1 \
--storagectl IDE \
--type dvddrive \
`#end`
$VBM storageattach $VMUUID \
--device 1 \
--medium additions \
--port 1 \
--storagectl IDE \
--type dvddrive \
`#end`
# configure SATA and attach new hdd
VMPREFIX=$($VBM showvminfo $VMUUID --machinereadable |
gawk -F = '/^CfgFile=/{print $2}' |
xargs dirname)
DISKNAME=$VMPREFIX/$VMNAME.vdi
$VBM createhd --filename "$DISKNAME" \
--format VMDK \
--sizebyte $(($DISKSIZEGB * 1024 * 1024 * 1024)) \
--variant Split2G \
`#end` > /dev/null
$VBM storagectl $VMUUID \
--add sata \
--bootable on \
--controller IntelAHCI \
--hostiocache off \
--name SATA \
--portcount 1 \
`#end`
$VBM storageattach $VMUUID \
--device 0 \
--medium "$DISKNAME" \
--nonrotational on \
--port 0 \
--storagectl SATA \
--type hdd \
`#end`
echo 'Disk image created.'
# instructions to continue
cat <<EOM
VM created.
Start the VM to run the Xubuntu installer. Notes:
1. No need to "Download updates while installing" (we will dist-upgrade later).
2. Enable "Install this third-party software" (if you want a nice desktop env).
3. Use LVM, always.
4. name = vagrant
computer name = XU64 (no base!)
username = vagrant (don't worry, we will create your account later)
password = vagrant
5. At "Installation Complete", click "Restart Now".
6. A minute later you will see gibberish. Use VirtualBox to shutdown the VM.
(The message "Please remove installation media and close the tray (if any)
then press ENTER:" mixed inside other shutdown messages.)
7. Take a snapshot of the VM.
Enjoy!
EOM
fi