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.
24 'cpu' : "max,sse4.2=off",
27 class FreeBSDVM(basevm.BaseVM):
31 link = "https://download.freebsd.org/ftp/releases/ISO-IMAGES/12.4/FreeBSD-12.4-RELEASE-amd64-disc1.iso.xz"
32 csum = "1dcf6446e31bf3f81b582e9aba3319a258c29a937a2af6138ee4b181ed719a87"
76 rm -rf /home/qemu/qemu-test.*
77 cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
78 mkdir src build; cd src;
81 ../src/configure --python=python3.7 {configure_opts};
82 gmake --output-sync -j{jobs} {target} {verbose};
85 def console_boot_serial(self):
86 self.console_wait_send("Autoboot", "3")
87 self.console_wait_send("OK", "set console=comconsole\n")
88 self.console_wait_send("OK", "boot\n")
90 def build_image(self, img):
91 self.print_step("Downloading install iso")
92 cimg = self._download_with_cache(self.link, sha256sum=self.csum)
93 img_tmp = img + ".tmp"
94 iso = img + ".install.iso"
97 self.print_step("Preparing iso and disk image")
98 subprocess.check_call(["cp", "-f", cimg, iso_xz])
99 subprocess.check_call(["xz", "-dvf", iso_xz])
100 self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size)
102 self.print_step("Booting installer")
103 self.boot(img_tmp, extra_args = [
104 "-machine", "graphics=off",
109 self.console_boot_serial()
110 self.console_wait_send("Console type", "xterm\n")
112 # pre-install configuration
113 self.console_wait_send("Welcome", "\n")
114 self.console_wait_send("Keymap Selection", "\n")
115 self.console_wait_send("Set Hostname", "freebsd\n")
116 self.console_wait_send("Distribution Select", "\n")
117 self.console_wait_send("Partitioning", "\n")
118 self.console_wait_send("Partition", "\n")
119 self.console_wait_send("Scheme", "\n")
120 self.console_wait_send("Editor", "f")
121 self.console_wait_send("Confirmation", "c")
123 self.print_step("Installation started now, this will take a while")
125 # post-install configuration
126 self.console_wait("New Password:")
127 self.console_send("%s\n" % self._config["root_pass"])
128 self.console_wait("Retype New Password:")
129 self.console_send("%s\n" % self._config["root_pass"])
131 self.console_wait_send("Network Configuration", "\n")
132 self.console_wait_send("IPv4", "y")
133 self.console_wait_send("DHCP", "y")
134 self.console_wait_send("IPv6", "n")
135 self.console_wait_send("Resolver", "\n")
137 self.console_wait_send("Time Zone Selector", "0\n")
138 self.console_wait_send("Confirmation", "y")
139 self.console_wait_send("Time & Date", "\n")
140 self.console_wait_send("Time & Date", "\n")
142 self.console_wait_send("System Configuration", "\n")
143 self.console_wait_send("System Hardening", "\n")
146 self.console_wait_send("Add User Accounts", "y")
147 self.console_wait("Username")
148 self.console_send("%s\n" % self._config["guest_user"])
149 self.console_wait("Full name")
150 self.console_send("%s\n" % self._config["guest_user"])
151 self.console_wait_send("Uid", "\n")
152 self.console_wait_send("Login group", "\n")
153 self.console_wait_send("Login group", "\n")
154 self.console_wait_send("Login class", "\n")
155 self.console_wait_send("Shell", "\n")
156 self.console_wait_send("Home directory", "\n")
157 self.console_wait_send("Home directory perm", "\n")
158 self.console_wait_send("Use password", "\n")
159 self.console_wait_send("Use an empty password", "\n")
160 self.console_wait_send("Use a random password", "\n")
161 self.console_wait("Enter password:")
162 self.console_send("%s\n" % self._config["guest_pass"])
163 self.console_wait("Enter password again:")
164 self.console_send("%s\n" % self._config["guest_pass"])
165 self.console_wait_send("Lock out", "\n")
166 self.console_wait_send("OK", "yes\n")
167 self.console_wait_send("Add another user", "no\n")
169 self.console_wait_send("Final Configuration", "\n")
170 self.console_wait_send("Manual Configuration", "\n")
171 self.console_wait_send("Complete", "\n")
173 self.print_step("Installation finished, rebooting")
174 self.console_boot_serial()
178 self.console_ssh_init(prompt, self._config["guest_user"], self._config["guest_pass"])
179 self.console_wait_send(prompt, "exit\n")
182 prompt = "root@freebsd:~ #"
183 self.console_ssh_init(prompt, "root", self._config["root_pass"])
184 self.console_sshd_config(prompt)
186 # setup serial console
187 self.console_wait(prompt)
188 self.console_send("echo 'console=comconsole' >> /boot/loader.conf\n")
191 self.console_wait(prompt)
192 self.console_send("echo 'autoboot_delay=1' >> /boot/loader.conf\n")
194 # setup virtio-blk #1 (tarfile)
195 self.console_wait(prompt)
196 self.console_send("echo 'chmod 666 /dev/vtbd1' >> /etc/rc.local\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("pkg install -y %s\n" % " ".join(self.pkgs))
207 self.ssh_root(self.poweroff)
208 self.console_wait("Uptime:")
211 if os.path.exists(img):
213 os.rename(img_tmp, img)
215 self.print_step("All done")
217 if __name__ == "__main__":
218 sys.exit(basevm.main(FreeBSDVM, config=FREEBSD_CONFIG))