-
Notifications
You must be signed in to change notification settings - Fork 3
/
installqemu.expect
146 lines (100 loc) · 2.64 KB
/
installqemu.expect
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
###############################################
#
# install alpine with docker in qemu x86_64
#
# Wait enough (forever) until a long-time boot
set timeout -1
# Root Password
set Password "Secret123"
set ISO "alpine-virt-3.12.3-x86_64.iso"
set URL "http://dl-cdn.alpinelinux.org/alpine/v3.12/releases/x86_64"
spawn curl -v -L -o $ISO -C - $URL/$ISO
expect "left intact"
spawn rm -f ./qemukey ./qemukey.pub
sleep 5
spawn ssh-keygen -b 2048 -t rsa -N "" -f ./qemukey
expect "\[SHA256\]"
set qemukey [exec cat ./qemukey.pub]
#
# install the system
#
spawn rm -f alpine.img
spawn qemu-img create -f qcow2 alpine.img 4G
sleep 5
spawn qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 \
-drive if=pflash,format=raw,read-only,file=$env(PREFIX)/share/qemu/edk2-x86_64-code.fd \
-netdev user,id=n1,hostfwd=tcp::8070-:8070,hostfwd=tcp::8080-:8080,hostfwd=tcp::2222-:22 -device virtio-net,netdev=n1 \
-cdrom $ISO \
-nographic alpine.img
set qemuID $spawn_id
expect "login:"
send "root\r"
#expect "Password:"
#send "\n"
expect "localhost:~#"
send "setup-interfaces\r"
expect "\[eth0\]"
send "\r"
expect "\[dhcp\]"
send "\r"
expect "\[no\]"
send "\r"
expect "localhost:~#"
send "ifup eth0\r"
expect "localhost:~#"
send "sed -i -E 's/(local kernel_opts)=.*/\\1=\"console=ttyS0\"/' /sbin/setup-disk\r"
expect "localhost:~#"
send "wget -q -O answerfile https://raw.githubusercontent.com/egandro/docker-qemu-arm/main/answerfile\r"
expect "localhost:~#"
send "setup-alpine -f answerfile\r"
expect "password:"
send "$Password\n"
expect "password:"
send "$Password\n"
expect "\[n\]"
send "y\r"
expect "Please reboot"
send "halt\r"
expect "System halted"
# Ctrl-a + x (qemu machine monitor halt)
send "\x01"
send "x"
close -i $qemuID
#
# setup the system
#
sleep 5
spawn qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 \
-drive if=pflash,format=raw,read-only,file=$env(PREFIX)/share/qemu/edk2-x86_64-code.fd \
-netdev user,id=n1,hostfwd=tcp::2222-:22 -device virtio-net,netdev=n1 \
-nographic alpine.img
set qemuID $spawn_id
expect "login:"
send "root\r"
expect "Password:"
send "$Password\r"
expect "#"
send "apk update && apk add docker ip6tables\r"
expect "#"
send "service docker start\r"
expect "#"
send "rc-update add docker\r"
expect "#"
send "apk add zram-init\r"
expect "#"
send "service zram-init start\r"
expect "#"
send "rc-update add zram-init\r"
expect "#"
send "mkdir -p /root/.ssh\r"
expect "#"
send "chmod 700 /root/.ssh\r"
expect "#"
send "echo $qemukey >> /root/.ssh/authorized_keys\r"
expect "#"
send "halt\r"
expect "System halted"
# Ctrl-a + x (qemu machine monitor halt)
send "\x01"
send "x"
close -i $qemuID