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.0/FreeBSD-12.0-RELEASE-amd64-disc1.iso.xz"
28 csum
= "1d40015bea89d05b8bd13e2ed80c40b522a9ec1abd8e7c8b80954fb485fb99db"
61 rm -rf /home/qemu/qemu-test.*
62 cd $(mktemp -d /home/qemu/qemu-test.XXXXXX);
63 mkdir src build; cd src;
66 ../src/configure --python=python3.6 {configure_opts};
67 gmake --output-sync -j{jobs} {target} {verbose};
70 def console_boot_serial(self
):
71 self
.console_wait_send("Autoboot", "3")
72 self
.console_wait_send("OK", "set console=comconsole\n")
73 self
.console_wait_send("OK", "boot\n")
75 def build_image(self
, img
):
76 self
.print_step("Downloading install iso")
77 cimg
= self
._download
_with
_cache
(self
.link
, sha256sum
=self
.csum
)
78 img_tmp
= img
+ ".tmp"
79 iso
= img
+ ".install.iso"
82 self
.print_step("Preparing iso and disk image")
83 subprocess
.check_call(["cp", "-f", cimg
, iso_xz
])
84 subprocess
.check_call(["xz", "-dvf", iso_xz
])
85 self
.exec_qemu_img("create", "-f", "qcow2", img_tmp
, self
.size
)
87 self
.print_step("Booting installer")
88 self
.boot(img_tmp
, extra_args
= [
89 "-bios", "pc-bios/bios-256k.bin",
90 "-machine", "graphics=off",
94 self
.console_boot_serial()
95 self
.console_wait_send("Console type", "xterm\n")
97 # pre-install configuration
98 self
.console_wait_send("Welcome", "\n")
99 self
.console_wait_send("Keymap Selection", "\n")
100 self
.console_wait_send("Set Hostname", "freebsd\n")
101 self
.console_wait_send("Distribution Select", "\n")
102 self
.console_wait_send("Partitioning", "\n")
103 self
.console_wait_send("Partition", "\n")
104 self
.console_wait_send("Scheme", "\n")
105 self
.console_wait_send("Editor", "f")
106 self
.console_wait_send("Confirmation", "c")
108 self
.print_step("Installation started now, this will take a while")
110 # post-install configuration
111 self
.console_wait("New Password:")
112 self
.console_send("%s\n" % self
.ROOT_PASS
)
113 self
.console_wait("Retype New Password:")
114 self
.console_send("%s\n" % self
.ROOT_PASS
)
116 self
.console_wait_send("Network Configuration", "\n")
117 self
.console_wait_send("IPv4", "y")
118 self
.console_wait_send("DHCP", "y")
119 self
.console_wait_send("IPv6", "n")
120 self
.console_wait_send("Resolver", "\n")
122 self
.console_wait_send("Time Zone Selector", "a\n")
123 self
.console_wait_send("Confirmation", "y")
124 self
.console_wait_send("Time & Date", "\n")
125 self
.console_wait_send("Time & Date", "\n")
127 self
.console_wait_send("System Configuration", "\n")
128 self
.console_wait_send("System Hardening", "\n")
131 self
.console_wait_send("Add User Accounts", "y")
132 self
.console_wait("Username")
133 self
.console_send("%s\n" % self
.GUEST_USER
)
134 self
.console_wait("Full name")
135 self
.console_send("%s\n" % self
.GUEST_USER
)
136 self
.console_wait_send("Uid", "\n")
137 self
.console_wait_send("Login group", "\n")
138 self
.console_wait_send("Login group", "\n")
139 self
.console_wait_send("Login class", "\n")
140 self
.console_wait_send("Shell", "\n")
141 self
.console_wait_send("Home directory", "\n")
142 self
.console_wait_send("Home directory perm", "\n")
143 self
.console_wait_send("Use password", "\n")
144 self
.console_wait_send("Use an empty password", "\n")
145 self
.console_wait_send("Use a random password", "\n")
146 self
.console_wait("Enter password:")
147 self
.console_send("%s\n" % self
.GUEST_PASS
)
148 self
.console_wait("Enter password again:")
149 self
.console_send("%s\n" % self
.GUEST_PASS
)
150 self
.console_wait_send("Lock out", "\n")
151 self
.console_wait_send("OK", "yes\n")
152 self
.console_wait_send("Add another user", "no\n")
154 self
.console_wait_send("Final Configuration", "\n")
155 self
.console_wait_send("Manual Configuration", "\n")
156 self
.console_wait_send("Complete", "\n")
158 self
.print_step("Installation finished, rebooting")
159 self
.console_boot_serial()
163 self
.console_ssh_init(prompt
, self
.GUEST_USER
, self
.GUEST_PASS
)
164 self
.console_wait_send(prompt
, "exit\n")
167 prompt
= "root@freebsd:~ #"
168 self
.console_ssh_init(prompt
, "root", self
.ROOT_PASS
)
169 self
.console_sshd_config(prompt
)
171 # setup serial console
172 self
.console_wait(prompt
)
173 self
.console_send("echo 'console=comconsole' >> /boot/loader.conf\n")
176 self
.console_wait(prompt
)
177 self
.console_send("echo 'autoboot_delay=1' >> /boot/loader.conf\n")
179 # setup virtio-blk #1 (tarfile)
180 self
.console_wait(prompt
)
181 self
.console_send("echo 'chmod 666 /dev/vtbd1' >> /etc/rc.local\n")
183 self
.print_step("Configuration finished, rebooting")
184 self
.console_wait_send(prompt
, "reboot\n")
185 self
.console_wait("login:")
188 self
.print_step("Installing packages")
189 self
.ssh_root_check("pkg install -y %s\n" % " ".join(self
.pkgs
))
192 self
.ssh_root(self
.poweroff
)
193 self
.console_wait("Uptime:")
196 if os
.path
.exists(img
):
198 os
.rename(img_tmp
, img
)
200 self
.print_step("All done")
202 if __name__
== "__main__":
203 sys
.exit(basevm
.main(FreeBSDVM
))