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.
23 class FreeBSDVM(basevm.BaseVM):
27 link = "https://download.freebsd.org/ftp/releases/ISO-IMAGES/12.1/FreeBSD-12.1-RELEASE-amd64-disc1.iso.xz"
28 csum = "7394c3f60a1e236e7bd3a05809cf43ae39a3b8e5d42d782004cf2f26b1cfcd88"
66 rm -rf /home/qemu/qemu-test.*
67 cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
68 mkdir src build; cd src;
71 ../src/configure --python=python3.7 {configure_opts};
72 gmake --output-sync -j{jobs} {target} {verbose};
75 def console_boot_serial(self):
76 self.console_wait_send("Autoboot", "3")
77 self.console_wait_send("OK", "set console=comconsole\n")
78 self.console_wait_send("OK", "boot\n")
80 def build_image(self, img):
81 self.print_step("Downloading install iso")
82 cimg = self._download_with_cache(self.link, sha256sum=self.csum)
83 img_tmp = img + ".tmp"
84 iso = img + ".install.iso"
87 self.print_step("Preparing iso and disk image")
88 subprocess.check_call(["cp", "-f", cimg, iso_xz])
89 subprocess.check_call(["xz", "-dvf", iso_xz])
90 self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size)
92 self.print_step("Booting installer")
93 self.boot(img_tmp, extra_args = [
94 "-bios", "pc-bios/bios-256k.bin",
95 "-machine", "graphics=off",
100 self.console_boot_serial()
101 self.console_wait_send("Console type", "xterm\n")
103 # pre-install configuration
104 self.console_wait_send("Welcome", "\n")
105 self.console_wait_send("Keymap Selection", "\n")
106 self.console_wait_send("Set Hostname", "freebsd\n")
107 self.console_wait_send("Distribution Select", "\n")
108 self.console_wait_send("Partitioning", "\n")
109 self.console_wait_send("Partition", "\n")
110 self.console_wait_send("Scheme", "\n")
111 self.console_wait_send("Editor", "f")
112 self.console_wait_send("Confirmation", "c")
114 self.print_step("Installation started now, this will take a while")
116 # post-install configuration
117 self.console_wait("New Password:")
118 self.console_send("%s\n" % self._config["root_pass"])
119 self.console_wait("Retype New Password:")
120 self.console_send("%s\n" % self._config["root_pass"])
122 self.console_wait_send("Network Configuration", "\n")
123 self.console_wait_send("IPv4", "y")
124 self.console_wait_send("DHCP", "y")
125 self.console_wait_send("IPv6", "n")
126 self.console_wait_send("Resolver", "\n")
128 self.console_wait_send("Time Zone Selector", "a\n")
129 self.console_wait_send("Confirmation", "y")
130 self.console_wait_send("Time & Date", "\n")
131 self.console_wait_send("Time & Date", "\n")
133 self.console_wait_send("System Configuration", "\n")
134 self.console_wait_send("System Hardening", "\n")
137 self.console_wait_send("Add User Accounts", "y")
138 self.console_wait("Username")
139 self.console_send("%s\n" % self._config["guest_user"])
140 self.console_wait("Full name")
141 self.console_send("%s\n" % self._config["guest_user"])
142 self.console_wait_send("Uid", "\n")
143 self.console_wait_send("Login group", "\n")
144 self.console_wait_send("Login group", "\n")
145 self.console_wait_send("Login class", "\n")
146 self.console_wait_send("Shell", "\n")
147 self.console_wait_send("Home directory", "\n")
148 self.console_wait_send("Home directory perm", "\n")
149 self.console_wait_send("Use password", "\n")
150 self.console_wait_send("Use an empty password", "\n")
151 self.console_wait_send("Use a random password", "\n")
152 self.console_wait("Enter password:")
153 self.console_send("%s\n" % self._config["guest_pass"])
154 self.console_wait("Enter password again:")
155 self.console_send("%s\n" % self._config["guest_pass"])
156 self.console_wait_send("Lock out", "\n")
157 self.console_wait_send("OK", "yes\n")
158 self.console_wait_send("Add another user", "no\n")
160 self.console_wait_send("Final Configuration", "\n")
161 self.console_wait_send("Manual Configuration", "\n")
162 self.console_wait_send("Complete", "\n")
164 self.print_step("Installation finished, rebooting")
165 self.console_boot_serial()
169 self.console_ssh_init(prompt, self._config["guest_user"], self._config["guest_pass"])
170 self.console_wait_send(prompt, "exit\n")
173 prompt = "root@freebsd:~ #"
174 self.console_ssh_init(prompt, "root", self._config["root_pass"])
175 self.console_sshd_config(prompt)
177 # setup serial console
178 self.console_wait(prompt)
179 self.console_send("echo 'console=comconsole' >> /boot/loader.conf\n")
182 self.console_wait(prompt)
183 self.console_send("echo 'autoboot_delay=1' >> /boot/loader.conf\n")
185 # setup virtio-blk #1 (tarfile)
186 self.console_wait(prompt)
187 self.console_send("echo 'chmod 666 /dev/vtbd1' >> /etc/rc.local\n")
189 self.print_step("Configuration finished, rebooting")
190 self.console_wait_send(prompt, "reboot\n")
191 self.console_wait("login:")
194 self.print_step("Installing packages")
195 self.ssh_root_check("pkg install -y %s\n" % " ".join(self.pkgs))
198 self.ssh_root(self.poweroff)
199 self.console_wait("Uptime:")
202 if os.path.exists(img):
204 os.rename(img_tmp, img)
206 self.print_step("All done")
208 if __name__ == "__main__":
209 sys.exit(basevm.main(FreeBSDVM))