1c88ee46cSPhilippe Mathieu-Daudé#!/usr/bin/env python3 25cd2b138SFam Zheng# 35cd2b138SFam Zheng# NetBSD VM image 45cd2b138SFam Zheng# 5af093bc9SGerd Hoffmann# Copyright 2017-2019 Red Hat Inc. 65cd2b138SFam Zheng# 75cd2b138SFam Zheng# Authors: 85cd2b138SFam Zheng# Fam Zheng <famz@redhat.com> 9af093bc9SGerd Hoffmann# Gerd Hoffmann <kraxel@redhat.com> 105cd2b138SFam Zheng# 115cd2b138SFam Zheng# This code is licensed under the GPL version 2 or later. See 125cd2b138SFam Zheng# the COPYING file in the top-level directory. 135cd2b138SFam Zheng# 145cd2b138SFam Zheng 155cd2b138SFam Zhengimport os 165cd2b138SFam Zhengimport sys 17af093bc9SGerd Hoffmannimport time 185cd2b138SFam Zhengimport subprocess 195cd2b138SFam Zhengimport basevm 205cd2b138SFam Zheng 215cd2b138SFam Zhengclass NetBSDVM(basevm.BaseVM): 225cd2b138SFam Zheng name = "netbsd" 2331719c37SPhilippe Mathieu-Daudé arch = "x86_64" 24af093bc9SGerd Hoffmann 25*844d35b9SBrad Smith link = "https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.1/images/NetBSD-9.1-amd64.iso" 26*844d35b9SBrad Smith csum = "65bddc95945991c3b2021f9c8ded7f34c25f0a7611b7aa15a15fe23399e902307e926ae97fcd01dc1662ac67b5f6e4be643c6a2b581692ddcb616d30125066f9" 27af093bc9SGerd Hoffmann size = "20G" 28af093bc9SGerd Hoffmann pkgs = [ 29af093bc9SGerd Hoffmann # tools 30af093bc9SGerd Hoffmann "git-base", 31af093bc9SGerd Hoffmann "pkgconf", 32af093bc9SGerd Hoffmann "xz", 33af093bc9SGerd Hoffmann "python37", 34bfea7012SPaolo Bonzini "py37-setuptools", 35345d7053SPaolo Bonzini "ninja-build", 36af093bc9SGerd Hoffmann 37af093bc9SGerd Hoffmann # gnu tools 38af093bc9SGerd Hoffmann "bash", 39af093bc9SGerd Hoffmann "gmake", 40af093bc9SGerd Hoffmann "gsed", 41*844d35b9SBrad Smith "gettext-tools", 42af093bc9SGerd Hoffmann 43af093bc9SGerd Hoffmann # libs: crypto 44af093bc9SGerd Hoffmann "gnutls", 45af093bc9SGerd Hoffmann 46af093bc9SGerd Hoffmann # libs: images 47af093bc9SGerd Hoffmann "jpeg", 48af093bc9SGerd Hoffmann "png", 49af093bc9SGerd Hoffmann 50af093bc9SGerd Hoffmann # libs: ui 51af093bc9SGerd Hoffmann "SDL2", 52af093bc9SGerd Hoffmann "gtk3+", 53af093bc9SGerd Hoffmann "libxkbcommon", 543a678481SJuan Quintela 553a678481SJuan Quintela # libs: migration 563a678481SJuan Quintela "zstd", 57af093bc9SGerd Hoffmann ] 58af093bc9SGerd Hoffmann 595cd2b138SFam Zheng BUILD_SCRIPT = """ 605cd2b138SFam Zheng set -e; 61af093bc9SGerd Hoffmann rm -rf /home/qemu/qemu-test.* 62af093bc9SGerd Hoffmann cd $(mktemp -d /home/qemu/qemu-test.XXXXXX); 63af093bc9SGerd Hoffmann mkdir src build; cd src; 645cd2b138SFam Zheng tar -xf /dev/rld1a; 65af093bc9SGerd Hoffmann cd ../build 66af093bc9SGerd Hoffmann ../src/configure --python=python3.7 --disable-opengl {configure_opts}; 675c2ec9b6SAlex Bennée gmake --output-sync -j{jobs} {target} {verbose}; 685cd2b138SFam Zheng """ 69af093bc9SGerd Hoffmann poweroff = "/sbin/poweroff" 705cd2b138SFam Zheng 716d46e602SEduardo Habkost # Workaround for NetBSD + IPv6 + slirp issues. 726d46e602SEduardo Habkost # NetBSD seems to ignore the ICMPv6 Destination Unreachable 736d46e602SEduardo Habkost # messages generated by slirp. When the host has no IPv6 746d46e602SEduardo Habkost # connectivity, this causes every connection to ftp.NetBSD.org 756d46e602SEduardo Habkost # take more than a minute to be established. 766d46e602SEduardo Habkost ipv6 = False 776d46e602SEduardo Habkost 785cd2b138SFam Zheng def build_image(self, img): 795b4b4865SAlex Bennée cimg = self._download_with_cache(self.link, sha512sum=self.csum) 805cd2b138SFam Zheng img_tmp = img + ".tmp" 81af093bc9SGerd Hoffmann iso = img + ".install.iso" 82af093bc9SGerd Hoffmann 83af093bc9SGerd Hoffmann self.print_step("Preparing iso and disk image") 84af093bc9SGerd Hoffmann subprocess.check_call(["ln", "-f", cimg, iso]) 851e48931cSWainer dos Santos Moschetta self.exec_qemu_img("create", "-f", "qcow2", img_tmp, self.size) 86af093bc9SGerd Hoffmann 87af093bc9SGerd Hoffmann self.print_step("Booting installer") 88af093bc9SGerd Hoffmann self.boot(img_tmp, extra_args = [ 89af093bc9SGerd Hoffmann "-bios", "pc-bios/bios-256k.bin", 90af093bc9SGerd Hoffmann "-machine", "graphics=off", 91af093bc9SGerd Hoffmann "-cdrom", iso 92af093bc9SGerd Hoffmann ]) 93af093bc9SGerd Hoffmann self.console_init() 942cc3e591SGerd Hoffmann self.console_wait_send("3. Drop to boot prompt", "3") 952cc3e591SGerd Hoffmann self.console_wait_send("> ", "consdev com0\n") 96af093bc9SGerd Hoffmann self.console_wait_send("> ", "boot\n") 97af093bc9SGerd Hoffmann 98af093bc9SGerd Hoffmann self.console_wait_send("Terminal type", "xterm\n") 99af093bc9SGerd Hoffmann self.console_wait_send("a: Installation messages", "a\n") 100af093bc9SGerd Hoffmann self.console_wait_send("a: Install NetBSD", "a\n") 101af093bc9SGerd Hoffmann self.console_wait("Shall we continue?") 102af093bc9SGerd Hoffmann self.console_wait_send("b: Yes", "b\n") 103af093bc9SGerd Hoffmann 104af093bc9SGerd Hoffmann self.console_wait_send("a: ld0", "a\n") 1052cc3e591SGerd Hoffmann self.console_wait_send("a: Guid Partition Table", "a\n") 106af093bc9SGerd Hoffmann self.console_wait_send("a: This is the correct", "a\n") 1072cc3e591SGerd Hoffmann self.console_wait_send("b: Use default part", "b\n") 108af093bc9SGerd Hoffmann self.console_wait_send("x: Partition sizes ok", "x\n") 109af093bc9SGerd Hoffmann self.console_wait("Shall we continue?") 110af093bc9SGerd Hoffmann self.console_wait_send("b: Yes", "b\n") 111af093bc9SGerd Hoffmann 112af093bc9SGerd Hoffmann self.console_wait_send("b: Use serial port com0", "b\n") 113af093bc9SGerd Hoffmann self.console_wait_send("f: Set serial baud rate", "f\n") 114af093bc9SGerd Hoffmann self.console_wait_send("a: 9600", "a\n") 1152cc3e591SGerd Hoffmann self.console_wait_send("x: Continue", "x\n") 116af093bc9SGerd Hoffmann 117af093bc9SGerd Hoffmann self.console_wait_send("a: Full installation", "a\n") 118af093bc9SGerd Hoffmann self.console_wait_send("a: CD-ROM", "a\n") 119af093bc9SGerd Hoffmann 120af093bc9SGerd Hoffmann self.print_step("Installation started now, this will take a while") 121af093bc9SGerd Hoffmann self.console_wait_send("Hit enter to continue", "\n") 122af093bc9SGerd Hoffmann 123af093bc9SGerd Hoffmann self.console_wait_send("d: Change root password", "d\n") 124af093bc9SGerd Hoffmann self.console_wait_send("a: Yes", "a\n") 125af093bc9SGerd Hoffmann self.console_wait("New password:") 126df001680SRobert Foley self.console_send("%s\n" % self._config["root_pass"]) 127af093bc9SGerd Hoffmann self.console_wait("New password:") 128df001680SRobert Foley self.console_send("%s\n" % self._config["root_pass"]) 129af093bc9SGerd Hoffmann self.console_wait("Retype new password:") 130df001680SRobert Foley self.console_send("%s\n" % self._config["root_pass"]) 131af093bc9SGerd Hoffmann 132af093bc9SGerd Hoffmann self.console_wait_send("o: Add a user", "o\n") 133af093bc9SGerd Hoffmann self.console_wait("username") 134df001680SRobert Foley self.console_send("%s\n" % self._config["guest_user"]) 135af093bc9SGerd Hoffmann self.console_wait("to group wheel") 136af093bc9SGerd Hoffmann self.console_wait_send("a: Yes", "a\n") 137af093bc9SGerd Hoffmann self.console_wait_send("a: /bin/sh", "a\n") 138af093bc9SGerd Hoffmann self.console_wait("New password:") 139df001680SRobert Foley self.console_send("%s\n" % self._config["guest_pass"]) 140af093bc9SGerd Hoffmann self.console_wait("New password:") 141df001680SRobert Foley self.console_send("%s\n" % self._config["guest_pass"]) 142af093bc9SGerd Hoffmann self.console_wait("Retype new password:") 143df001680SRobert Foley self.console_send("%s\n" % self._config["guest_pass"]) 144af093bc9SGerd Hoffmann 145af093bc9SGerd Hoffmann self.console_wait_send("a: Configure network", "a\n") 146af093bc9SGerd Hoffmann self.console_wait_send("a: vioif0", "a\n") 147af093bc9SGerd Hoffmann self.console_wait_send("Network media type", "\n") 148af093bc9SGerd Hoffmann self.console_wait("autoconfiguration") 149af093bc9SGerd Hoffmann self.console_wait_send("a: Yes", "a\n") 150af093bc9SGerd Hoffmann self.console_wait_send("DNS domain", "localnet\n") 151af093bc9SGerd Hoffmann self.console_wait("Are they OK?") 152af093bc9SGerd Hoffmann self.console_wait_send("a: Yes", "a\n") 153af093bc9SGerd Hoffmann self.console_wait("installed in /etc") 154af093bc9SGerd Hoffmann self.console_wait_send("a: Yes", "a\n") 155af093bc9SGerd Hoffmann 156af093bc9SGerd Hoffmann self.console_wait_send("e: Enable install", "e\n") 157af093bc9SGerd Hoffmann proxy = os.environ.get("http_proxy") 158af093bc9SGerd Hoffmann if not proxy is None: 159af093bc9SGerd Hoffmann self.console_wait_send("f: Proxy", "f\n") 160af093bc9SGerd Hoffmann self.console_wait("Proxy") 161af093bc9SGerd Hoffmann self.console_send("%s\n" % proxy) 162af093bc9SGerd Hoffmann self.console_wait_send("x: Install pkgin", "x\n") 163af093bc9SGerd Hoffmann self.console_init(1200) 164af093bc9SGerd Hoffmann self.console_wait_send("Hit enter to continue", "\n") 165af093bc9SGerd Hoffmann self.console_init() 166af093bc9SGerd Hoffmann 167af093bc9SGerd Hoffmann self.console_wait_send("g: Enable sshd", "g\n") 168af093bc9SGerd Hoffmann self.console_wait_send("x: Finished conf", "x\n") 169af093bc9SGerd Hoffmann self.console_wait_send("Hit enter to continue", "\n") 170af093bc9SGerd Hoffmann 171af093bc9SGerd Hoffmann self.print_step("Installation finished, rebooting") 172af093bc9SGerd Hoffmann self.console_wait_send("d: Reboot the computer", "d\n") 173af093bc9SGerd Hoffmann 174af093bc9SGerd Hoffmann # setup qemu user 175af093bc9SGerd Hoffmann prompt = "localhost$" 176df001680SRobert Foley self.console_ssh_init(prompt, self._config["guest_user"], 177df001680SRobert Foley self._config["guest_pass"]) 178af093bc9SGerd Hoffmann self.console_wait_send(prompt, "exit\n") 179af093bc9SGerd Hoffmann 180af093bc9SGerd Hoffmann # setup root user 181af093bc9SGerd Hoffmann prompt = "localhost#" 182df001680SRobert Foley self.console_ssh_init(prompt, "root", self._config["root_pass"]) 183af093bc9SGerd Hoffmann self.console_sshd_config(prompt) 184af093bc9SGerd Hoffmann 185af093bc9SGerd Hoffmann # setup virtio-blk #1 (tarfile) 186af093bc9SGerd Hoffmann self.console_wait(prompt) 187af093bc9SGerd Hoffmann self.console_send("echo 'chmod 666 /dev/rld1a' >> /etc/rc.local\n") 188af093bc9SGerd Hoffmann 189af093bc9SGerd Hoffmann # turn off mprotect (conflicts with tcg) 190af093bc9SGerd Hoffmann self.console_wait(prompt) 191af093bc9SGerd Hoffmann self.console_send("echo security.pax.mprotect.enabled=0 >> /etc/sysctl.conf\n") 192af093bc9SGerd Hoffmann 193af093bc9SGerd Hoffmann self.print_step("Configuration finished, rebooting") 194af093bc9SGerd Hoffmann self.console_wait_send(prompt, "reboot\n") 195af093bc9SGerd Hoffmann self.console_wait("login:") 196af093bc9SGerd Hoffmann self.wait_ssh() 197af093bc9SGerd Hoffmann 198af093bc9SGerd Hoffmann self.print_step("Installing packages") 199af093bc9SGerd Hoffmann self.ssh_root_check("pkgin update\n") 200af093bc9SGerd Hoffmann self.ssh_root_check("pkgin -y install %s\n" % " ".join(self.pkgs)) 201af093bc9SGerd Hoffmann 202af093bc9SGerd Hoffmann # shutdown 203af093bc9SGerd Hoffmann self.ssh_root(self.poweroff) 204af093bc9SGerd Hoffmann self.console_wait("entering state S5") 205af093bc9SGerd Hoffmann self.wait() 206af093bc9SGerd Hoffmann 2075cd2b138SFam Zheng os.rename(img_tmp, img) 208af093bc9SGerd Hoffmann os.remove(iso) 209af093bc9SGerd Hoffmann self.print_step("All done") 2105cd2b138SFam Zheng 2115cd2b138SFam Zhengif __name__ == "__main__": 2125cd2b138SFam Zheng sys.exit(basevm.main(NetBSDVM)) 213