master
text 219 lines 7.77 KB
Raw
1 #!/usr/bin/env python3
2 #
3 # NetBSD VM image
4 #
5 # Copyright 2017-2019 Red Hat Inc.
6 #
7 # Authors:
8 # Fam Zheng <famz@redhat.com>
9 # Gerd Hoffmann <kraxel@redhat.com>
10 #
11 # This code is licensed under the GPL version 2 or later. See
12 # the COPYING file in the top-level directory.
13 #
14
15 import os
16 import sys
17 import time
18 import subprocess
19 import basevm
20
21 class NetBSDVM(basevm.BaseVM):
22 name = "netbsd"
23 arch = "x86_64"
24
25 link = "https://cdn.netbsd.org/pub/NetBSD/images/10.1/NetBSD-10.1-amd64.iso"
26 csum = "7a5e5071307e1795885ffc6e1b8aac465082c21c8b79f4c9b4103ef44e4f2da45477299d213ae0093f6534dc99dc2bbf78f41e9dd556c72a02516068bf43fe49"
27 size = "20G"
28 pkgs = [
29 # tools
30 "git-base",
31 "pkgconf",
32 "xz",
33 "python313",
34 "py313-wheel",
35 "ninja-build",
36
37 # gnu tools
38 "bash",
39 "gmake",
40 "gsed",
41 "gettext-tools",
42
43 # libs: basic
44 "dtc",
45
46 # libs: crypto
47 "gnutls",
48
49 # libs: images
50 "png",
51
52 # libs: ui
53 "capstone",
54 "SDL2",
55 "gtk3+",
56 "libxkbcommon",
57
58 # libs: migration
59 "zstd",
60
61 # libs: networking
62 "libslirp",
63 ]
64
65 BUILD_SCRIPT = """
66 set -e;
67 rm -rf /home/qemu/qemu-test.*
68 cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
69 mkdir src build; cd src;
70 tar -xf /dev/rld1a;
71 cd ../build
72 ../src/configure --disable-opengl --extra-ldflags=-L/usr/pkg/lib \
73 --extra-cflags=-I/usr/pkg/include {configure_opts};
74 gmake --output-sync -j{jobs} {target} {verbose};
75 """
76 poweroff = "/sbin/poweroff"
77
78 # Workaround for NetBSD + IPv6 + slirp issues.
79 # NetBSD seems to ignore the ICMPv6 Destination Unreachable
80 # messages generated by slirp. When the host has no IPv6
81 # connectivity, this causes every connection to ftp.NetBSD.org
82 # take more than a minute to be established.
83 ipv6 = False
84
85 def build_image(self, img):
86 cimg = self._download_with_cache(self.link, sha512sum=self.csum)
87 img_tmp = img + ".tmp"
88 iso = img + ".install.iso"
89
90 self.print_step("Preparing iso and disk image")
91 subprocess.check_call(["ln", "-f", cimg, iso])
92 self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size)
93
94 self.print_step("Booting installer")
95 self.boot(img_tmp, extra_args = [
96 "-machine", "graphics=off",
97 "-cdrom", iso
98 ])
99 self.console_init()
100 self.console_wait_send("3. Drop to boot prompt", "3")
101 self.console_wait_send("> ", "consdev com0\n")
102 self.console_wait_send("> ", "boot\n")
103
104 self.console_wait_send("Terminal type", "xterm\n")
105 self.console_wait_send("a: Installation messages", "a\n")
106 self.console_wait_send("a: Install NetBSD", "a\n")
107 self.console_wait("Shall we continue?")
108 self.console_wait_send("b: Yes", "b\n")
109
110 self.console_wait_send("a: ld0", "a\n")
111 self.console_wait_send("a: Guid Partition Table", "a\n")
112 self.console_wait_send("a: This is the correct", "a\n")
113 self.console_wait_send("b: Use default part", "b\n")
114 self.console_wait_send("x: Partition sizes ok", "x\n")
115 self.console_wait("Shall we continue?")
116 self.console_wait_send("b: Yes", "b\n")
117
118 self.console_wait_send("b: Use serial port com0", "b\n")
119 self.console_wait_send("f: Set serial baud rate", "f\n")
120 self.console_wait_send("a: 9600", "a\n")
121 self.console_wait_send("x: Continue", "x\n")
122
123 self.console_wait_send("a: Full installation", "a\n")
124 self.console_wait_send("a: CD-ROM", "a\n")
125
126 self.print_step("Installation started now, this will take a while")
127 self.console_wait_send("Hit enter to continue", "\n")
128
129 self.console_wait("New password:")
130 self.console_send("%s\n" % self._config["root_pass"])
131 self.console_wait("New password:")
132 self.console_send("%s\n" % self._config["root_pass"])
133 self.console_wait("Retype new password:")
134 self.console_send("%s\n" % self._config["root_pass"])
135
136 self.console_wait_send("o: Add a user", "o\n")
137 self.console_wait("username")
138 self.console_send("%s\n" % self._config["guest_user"])
139 self.console_wait("to group wheel")
140 self.console_wait_send("a: Yes", "a\n")
141 self.console_wait_send("a: /bin/sh", "a\n")
142 self.console_wait("New password:")
143 self.console_send("%s\n" % self._config["guest_pass"])
144 self.console_wait("New password:")
145 self.console_send("%s\n" % self._config["guest_pass"])
146 self.console_wait("Retype new password:")
147 self.console_send("%s\n" % self._config["guest_pass"])
148
149 self.console_wait_send("a: Configure network", "a\n")
150 self.console_wait_send("a: vioif0", "a\n")
151 self.console_wait_send("Network media type", "\n")
152 self.console_wait("autoconfiguration")
153 self.console_wait_send("a: Yes", "a\n")
154 self.console_wait_send("Finished", "netbsd-guest\n")
155 self.console_wait_send("DNS domain", "localnet\n")
156 self.console_wait("Are they OK?")
157 self.console_wait_send("a: Yes", "a\n")
158 self.console_wait("installed in /etc")
159 self.console_wait_send("a: Yes", "a\n")
160
161 self.console_wait_send("e: Enable install", "e\n")
162 self.console_wait("installed in /etc")
163 self.console_wait_send("a: Yes", "a\n")
164 proxy = os.environ.get("http_proxy")
165 if not proxy is None:
166 self.console_wait_send("f: Proxy", "f\n")
167 self.console_wait("Proxy")
168 self.console_send("%s\n" % proxy)
169 self.console_wait_send("x: Install pkgin", "x\n")
170 self.console_init(1200)
171 self.console_wait_send("Hit enter to continue", "\n")
172 self.console_init()
173
174 self.console_wait_send("g: Enable sshd", "g\n")
175 self.console_wait_send("x: Finished conf", "x\n")
176 self.console_wait_send("Hit enter to continue", "\n")
177
178 self.print_step("Installation finished, rebooting")
179 self.console_wait_send("d: Reboot the computer", "d\n")
180
181 # setup qemu user
182 prompt = "netbsd-guest$"
183 self.console_ssh_init(prompt, self._config["guest_user"],
184 self._config["guest_pass"])
185 self.console_wait_send(prompt, "exit\n")
186
187 # setup root user
188 prompt = "netbsd-guest#"
189 self.console_ssh_init(prompt, "root", self._config["root_pass"])
190 self.console_sshd_config(prompt)
191
192 # setup virtio-blk #1 (tarfile)
193 self.console_wait(prompt)
194 self.console_send("echo 'chmod 666 /dev/rld1a' >> /etc/rc.local\n")
195
196 # turn off mprotect (conflicts with tcg)
197 self.console_wait(prompt)
198 self.console_send("echo security.pax.mprotect.enabled=0 >> /etc/sysctl.conf\n")
199
200 self.print_step("Configuration finished, rebooting")
201 self.console_wait_send(prompt, "reboot\n")
202 self.console_wait("login:")
203 self.wait_ssh()
204
205 self.print_step("Installing packages")
206 self.ssh_root_check("pkgin update\n")
207 self.ssh_root_check("pkgin -y install %s\n" % " ".join(self.pkgs))
208
209 # shutdown
210 self.ssh_root(self.poweroff)
211 self.console_wait("entering state S5")
212 self.wait()
213
214 os.rename(img_tmp, img)
215 os.remove(iso)
216 self.print_step("All done")
217
218 if __name__ == "__main__":
219 sys.exit(basevm.main(NetBSDVM))