5 # Copyright 2017-2019 Red Hat Inc.
8 # Fam Zheng <famz@redhat.com>
9 # Gerd Hoffmann <kraxel@redhat.com>
11 # This code is licensed under the GPL version 2 or later. See
12 # the COPYING file in the top-level directory.
21 class NetBSDVM(basevm
.BaseVM
):
25 link
= "https://cdn.netbsd.org/pub/NetBSD/NetBSD-8.1/images/NetBSD-8.1-amd64.iso"
26 csum
= "718f275b7e0879599bdac95630c5e3f2184700032fdb6cdebf3bdd63687898c48ff3f08f57b89f4437a86cdd8ea07c01a39d432dbb37e1e4b008f4985f98da3f"
56 rm -rf /home/qemu/qemu-test.*
57 cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
58 mkdir src build; cd src;
61 ../src/configure --python=python3.7 --disable-opengl {configure_opts};
62 gmake --output-sync -j{jobs} {target} {verbose};
64 poweroff
= "/sbin/poweroff"
66 # Workaround for NetBSD + IPv6 + slirp issues.
67 # NetBSD seems to ignore the ICMPv6 Destination Unreachable
68 # messages generated by slirp. When the host has no IPv6
69 # connectivity, this causes every connection to ftp.NetBSD.org
70 # take more than a minute to be established.
73 def build_image(self
, img
):
74 cimg
= self
._download
_with
_cache
(self
.link
, sha512sum
=self
.csum
)
75 img_tmp
= img
+ ".tmp"
76 iso
= img
+ ".install.iso"
78 self
.print_step("Preparing iso and disk image")
79 subprocess
.check_call(["ln", "-f", cimg
, iso
])
80 subprocess
.check_call(["qemu-img", "create", "-f", "qcow2",
83 self
.print_step("Booting installer")
84 self
.boot(img_tmp
, extra_args
= [
85 "-bios", "pc-bios/bios-256k.bin",
86 "-machine", "graphics=off",
90 self
.console_wait("Primary Bootstrap")
92 # serial console boot menu output doesn't work for some
93 # reason, so we have to fly blind ...
94 for char
in list("5consdev com0\n"):
96 self
.console_send(char
)
97 self
.console_consume()
98 self
.console_wait_send("> ", "boot\n")
100 self
.console_wait_send("Terminal type", "xterm\n")
101 self
.console_wait_send("a: Installation messages", "a\n")
102 self
.console_wait_send("b: US-English", "b\n")
103 self
.console_wait_send("a: Install NetBSD", "a\n")
104 self
.console_wait("Shall we continue?")
105 self
.console_wait_send("b: Yes", "b\n")
107 self
.console_wait_send("a: ld0", "a\n")
108 self
.console_wait_send("a: This is the correct", "a\n")
109 self
.console_wait_send("b: Use the entire disk", "b\n")
110 self
.console_wait("NetBSD bootcode")
111 self
.console_wait_send("a: Yes", "a\n")
112 self
.console_wait_send("b: Use existing part", "b\n")
113 self
.console_wait_send("x: Partition sizes ok", "x\n")
114 self
.console_wait_send("for your NetBSD disk", "\n")
115 self
.console_wait("Shall we continue?")
116 self
.console_wait_send("b: Yes", "b\n")
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: Exit", "x\n")
123 self
.console_wait_send("a: Full installation", "a\n")
124 self
.console_wait_send("a: CD-ROM", "a\n")
126 self
.print_step("Installation started now, this will take a while")
127 self
.console_wait_send("Hit enter to continue", "\n")
129 self
.console_wait_send("d: Change root password", "d\n")
130 self
.console_wait_send("a: Yes", "a\n")
131 self
.console_wait("New password:")
132 self
.console_send("%s\n" % self
.ROOT_PASS
)
133 self
.console_wait("New password:")
134 self
.console_send("%s\n" % self
.ROOT_PASS
)
135 self
.console_wait("Retype new password:")
136 self
.console_send("%s\n" % self
.ROOT_PASS
)
138 self
.console_wait_send("o: Add a user", "o\n")
139 self
.console_wait("username")
140 self
.console_send("%s\n" % self
.GUEST_USER
)
141 self
.console_wait("to group wheel")
142 self
.console_wait_send("a: Yes", "a\n")
143 self
.console_wait_send("a: /bin/sh", "a\n")
144 self
.console_wait("New password:")
145 self
.console_send("%s\n" % self
.GUEST_PASS
)
146 self
.console_wait("New password:")
147 self
.console_send("%s\n" % self
.GUEST_PASS
)
148 self
.console_wait("Retype new password:")
149 self
.console_send("%s\n" % self
.GUEST_PASS
)
151 self
.console_wait_send("a: Configure network", "a\n")
152 self
.console_wait_send("a: vioif0", "a\n")
153 self
.console_wait_send("Network media type", "\n")
154 self
.console_wait("autoconfiguration")
155 self
.console_wait_send("a: Yes", "a\n")
156 self
.console_wait_send("DNS domain", "localnet\n")
157 self
.console_wait("Are they OK?")
158 self
.console_wait_send("a: Yes", "a\n")
159 self
.console_wait("installed in /etc")
160 self
.console_wait_send("a: Yes", "a\n")
162 self
.console_wait_send("e: Enable install", "e\n")
163 proxy
= os
.environ
.get("http_proxy")
164 if not proxy
is None:
165 self
.console_wait_send("f: Proxy", "f\n")
166 self
.console_wait("Proxy")
167 self
.console_send("%s\n" % proxy
)
168 self
.console_wait_send("x: Install pkgin", "x\n")
169 self
.console_init(1200)
170 self
.console_wait_send("Hit enter to continue", "\n")
173 self
.console_wait_send("g: Enable sshd", "g\n")
174 self
.console_wait_send("x: Finished conf", "x\n")
175 self
.console_wait_send("Hit enter to continue", "\n")
177 self
.print_step("Installation finished, rebooting")
178 self
.console_wait_send("d: Reboot the computer", "d\n")
181 prompt
= "localhost$"
182 self
.console_ssh_init(prompt
, self
.GUEST_USER
, self
.GUEST_PASS
)
183 self
.console_wait_send(prompt
, "exit\n")
186 prompt
= "localhost#"
187 self
.console_ssh_init(prompt
, "root", self
.ROOT_PASS
)
188 self
.console_sshd_config(prompt
)
190 # setup virtio-blk #1 (tarfile)
191 self
.console_wait(prompt
)
192 self
.console_send("echo 'chmod 666 /dev/rld1a' >> /etc/rc.local\n")
194 # turn off mprotect (conflicts with tcg)
195 self
.console_wait(prompt
)
196 self
.console_send("echo security.pax.mprotect.enabled=0 >> /etc/sysctl.conf\n")
198 self
.print_step("Configuration finished, rebooting")
199 self
.console_wait_send(prompt
, "reboot\n")
200 self
.console_wait("login:")
203 self
.print_step("Installing packages")
204 self
.ssh_root_check("pkgin update\n")
205 self
.ssh_root_check("pkgin -y install %s\n" % " ".join(self
.pkgs
))
208 self
.ssh_root(self
.poweroff
)
209 self
.console_wait("entering state S5")
212 os
.rename(img_tmp
, img
)
214 self
.print_step("All done")
216 if __name__
== "__main__":
217 sys
.exit(basevm
.main(NetBSDVM
))