-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-vm.exp
executable file
·174 lines (121 loc) · 3.05 KB
/
create-vm.exp
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/expect -f
set timeout -1
file delete disk.raw
file delete disk.raw.tar.gz
file delete gce-buildkite-alpine.iso
# Create a iso with this repository
spawn mkisofs -rock -output gce-buildkite-alpine.iso .
lassign [wait] pid spawnid os_error_flag value
if {$os_error_flag == -1 || $value != 0} {
send_user "Failed to create fat32 disk"
exit 1
}
close
if {! [file exists gce-buildkite-alpine.iso]} {
send_user "Failed to create fat32 disk"
exit 1
}
# Start the guest VM
spawn qemu-img create -f raw disk.raw 40G
lassign [wait] pid spawnid os_error_flag value
if {$os_error_flag == -1 || $value != 0} {
send_user "Failed to create raw disk"
exit 1
}
close
spawn qemu-system-x86_64 \
-nographic \
-drive file=disk.raw,format=raw \
-serial mon:stdio \
-cdrom alpine-virt-3.8.0-x86_64.iso \
-boot d
# Login process
expect "localhost login:"
#Enter username
send "root\n"
expect "localhost:~#"
send "setup-alpine\n"
expect "Select keyboard layout"
send "none\n"
expect "Enter system hostname"
send "buildkite-agent\n"
expect "Which one do you want to initialize?"
send "\n"
expect "Ip address for"
send "dhcp\n"
expect "Do you want to do any manual network configuration?"
send "no\n"
expect "New password"
send "\n"
expect "Retype password"
send "\n"
expect "Which timezone are you in?"
send "UTC\n"
expect "HTTP/FTP proxy URL?"
send "none\n"
expect "Enter mirror number"
send "1\n"
expect "Which SSH server?"
send "openssh\n"
#expect "Which NTP client to run?"
#send "chrony\n"
expect "Which disk(s) would you like to use?"
send "sda\n"
expect "How would you like to use it?"
send "sys\n"
expect "Erase the above disk(s) and continue?"
send "y\n"
expect "Installation is complete. Please reboot"
send "poweroff\n"
send_user "\nRebooting...\n"
sleep 3
close
sleep 1
spawn qemu-system-x86_64 \
-nographic \
-serial mon:stdio \
-drive file=disk.raw,format=raw \
-cdrom gce-buildkite-alpine.iso \
-boot c
expect "login:"
send "root\n"
expect "Password:"
send "\n"
expect ":~#"
send "echo default_kernel_opts=\\\"rootfstype=ext4 console=ttyS0,115200 cgroup_enable=memory swapaccount=1\\\" >> /etc/update-extlinux.conf\n"
expect ":~#"
send "echo serial_port=0 >> /etc/update-extlinux.conf\n"
expect ":~#"
send "echo serial_baud=115200 >> /etc/update-extlinux.conf\n"
expect ":~#"
send "echo timeout=1 >> /etc/update-extlinux.conf\n"
expect ":~#"
send "update-extlinux\n"
expect ":~#"
send "echo http://dl-cdn.alpinelinux.org/alpine/v3.8/community >> /etc/apk/repositories\n"
expect ":~#"
send "mount -t iso9660 /dev/cdrom /media/cdrom\n"
expect ":~#"
send "/media/cdrom/install.sh\n"
expect {
"Installation succeeded" {
}
"Installation failed" {
exit 1
}
}
expect ":~#"
send "umount /media/cdrom && rm .ash_history && poweroff\n"
expect ":~#"
close
sleep 1
send_user "Packing disk\n"
spawn tar -Sczf disk.raw.tar.gz disk.raw
lassign [wait] pid spawnid os_error_flag value
if {$os_error_flag == -1 || $value != 0} {
send_user "Failed to pack disk"
exit 1
}
close
send_user "Finished!\n"
exit