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 OpenBSDVM(basevm.BaseVM):
25 link = "https://cdn.openbsd.org/pub/OpenBSD/7.5/amd64/install75.iso"
26 csum = "034435c6e27405d5a7fafb058162943c194eb793dafdc412c08d49bb56b3892a"
67 rm -rf /home/qemu/qemu-test.*
68 cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
69 mkdir src build; cd src;
72 ../src/configure --cc=cc --extra-cflags=-I/usr/local/include \
73 --extra-ldflags=-L/usr/local/lib {configure_opts};
74 gmake --output-sync -j{jobs} {target} {verbose};
78 def build_image(self, img):
79 self.print_step("Downloading install iso")
80 cimg = self._download_with_cache(self.link, sha256sum=self.csum)
81 img_tmp = img + ".tmp"
82 iso = img + ".install.iso"
84 self.print_step("Preparing iso and disk image")
85 subprocess.check_call(["cp", "-f", cimg, iso])
86 self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size)
88 self.print_step("Booting installer")
89 self.boot(img_tmp, extra_args = [
90 "-machine", "graphics=off",
95 self.console_wait_send("boot>", "set tty com0\n")
96 self.console_wait_send("boot>", "\n")
98 # pre-install configuration
99 self.console_wait_send("(I)nstall", "i\n")
100 self.console_wait_send("Terminal type", "xterm\n")
101 self.console_wait_send("System hostname", "openbsd\n")
102 self.console_wait_send("Network interface to configure", "vio0\n")
103 self.console_wait_send("IPv4 address", "autoconf\n")
104 self.console_wait_send("IPv6 address", "none\n")
105 self.console_wait_send("Network interface to configure", "done\n")
106 self.console_wait("Password for root account")
107 self.console_send("%s\n" % self._config["root_pass"])
108 self.console_wait("Password for root account")
109 self.console_send("%s\n" % self._config["root_pass"])
110 self.console_wait_send("Start sshd(8)", "yes\n")
111 self.console_wait_send("X Window System", "no\n")
112 self.console_wait_send("console to com0", "\n")
113 self.console_wait_send("Which speed", "\n")
115 self.console_wait("Setup a user")
116 self.console_send("%s\n" % self._config["guest_user"])
117 self.console_wait("Full name")
118 self.console_send("%s\n" % self._config["guest_user"])
119 self.console_wait("Password")
120 self.console_send("%s\n" % self._config["guest_pass"])
121 self.console_wait("Password")
122 self.console_send("%s\n" % self._config["guest_pass"])
124 self.console_wait_send("Allow root ssh login", "yes\n")
125 self.console_wait_send("timezone", "UTC\n")
126 self.console_wait_send("root disk", "\n")
127 self.console_wait_send("Encrypt the root disk with a (p)assphrase", "no\n")
128 self.console_wait_send("(W)hole disk", "\n")
129 self.console_wait_send("(A)uto layout", "c\n")
131 # 4000 MB / as /dev/sd0a, at start of disk
132 self.console_wait_send("sd0>", "a a\n")
133 self.console_wait_send("offset:", "\n")
134 self.console_wait_send("size:", "4000M\n")
135 self.console_wait_send("FS type", "4.2BSD\n")
136 self.console_wait_send("mount point:", "/\n")
138 # 256 MB swap as /dev/sd0b
139 self.console_wait_send("sd0*>", "a b\n")
140 self.console_wait_send("offset:", "\n")
141 self.console_wait_send("size:", "256M\n")
142 self.console_wait_send("FS type", "swap\n")
144 # All remaining space for /home as /dev/sd0d
145 # NB, 'c' isn't allowed to be used.
146 self.console_wait_send("sd0*>", "a d\n")
147 self.console_wait_send("offset:", "\n")
148 self.console_wait_send("size:", "\n")
149 self.console_wait_send("FS type", "4.2BSD\n")
150 self.console_wait_send("mount point:", "/home\n")
152 self.console_wait_send("sd0*>", "q\n")
153 self.console_wait_send("Write new label?:", "y\n")
155 self.console_wait_send("Location of sets", "cd0\n")
156 self.console_wait_send("Pathname to the sets", "\n")
157 self.console_wait_send("Set name(s)", "\n")
158 self.console_wait_send("without verification", "yes\n")
160 self.print_step("Installation started now, this will take a while")
161 self.console_wait_send("Location of sets", "done\n")
163 self.console_wait("successfully completed")
164 self.print_step("Installation finished, rebooting")
165 self.console_wait_send("(R)eboot", "reboot\n")
169 self.console_ssh_init(prompt, self._config["guest_user"],
170 self._config["guest_pass"])
171 self.console_wait_send(prompt, "exit\n")
175 self.console_ssh_init(prompt, "root", self._config["root_pass"])
176 self.console_sshd_config(prompt)
178 # setup virtio-blk #1 (tarfile)
179 self.console_wait(prompt)
180 self.console_send("echo 'chmod 666 /dev/rsd1c' >> /etc/rc.local\n")
182 # enable w+x for /home
183 self.console_wait(prompt)
184 self.console_send("sed -i -e '/home/s/rw,/rw,wxallowed,/' /etc/fstab\n")
186 # tweak datasize limit
187 self.console_wait(prompt)
188 self.console_send("sed -i -e 's/\\(datasize[^=]*\\)=[^:]*/\\1=infinity/' /etc/login.conf\n")
190 # use http (be proxy cache friendly)
191 self.console_wait(prompt)
192 self.console_send("sed -i -e 's/https/http/' /etc/installurl\n")
194 self.print_step("Configuration finished, rebooting")
195 self.console_wait_send(prompt, "reboot\n")
196 self.console_wait("login:")
199 self.print_step("Installing packages")
200 self.ssh_root_check("pkg_add %s\n" % " ".join(self.pkgs))
203 self.ssh_root(self.poweroff)
206 if os.path.exists(img):
208 os.rename(img_tmp, img)
210 self.print_step("All done")
212 if __name__ == "__main__":
213 sys.exit(basevm.main(OpenBSDVM))