From: Daan De Meyer Date: Thu, 30 Mar 2023 11:56:53 +0000 (+0200) Subject: qemu: Use virtconsole serial console instead of regular serial console X-Git-Tag: v15~270^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b1dfd3869a9f2e2f263138ed2aea291e42f0c70;p=thirdparty%2Fmkosi.git qemu: Use virtconsole serial console instead of regular serial console With --qemu-headless, qemu stops working when latest systemd is not available because smbios provided kernel cmdline arguments are ignored. This includes "console=ttyS0" meaning we don't get any output on the serial console when booting in qemu. As a workaround, let's use qemu's virtconsole instead. This means the serial console will be available in the VM as /dev/hvc0, on which systemd will automatically spawn a serial getty. This means we'll eventually get a login prompt, even if latest systemd is not used. One caveat is that EDK2 doesn't seem to support virtio-serial with virtconsole. To get around this limitation, we keep a regular serial console around as well, which can be used by the bootloader to log its output. --- diff --git a/mkosi.md b/mkosi.md index feef292eb..afeb6e8af 100644 --- a/mkosi.md +++ b/mkosi.md @@ -672,7 +672,7 @@ a boolean argument: either "1", "yes", or "true" to enable, or "0", `Autologin=`, `--autologin` : Enable autologin for the `root` user on `/dev/pts/0` (nspawn), - `/dev/tty1` and `/dev/ttyS0` by patching `/etc/pam.d/login`. + `/dev/tty1` and `/dev/hvc0` by patching `/etc/pam.d/login`. `BuildScript=`, `--build-script=` diff --git a/mkosi/__init__.py b/mkosi/__init__.py index fd32be390..8877a29de 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -480,10 +480,10 @@ def configure_autologin(state: MkosiState) -> None: ttys = [] ttys += ["pts/0"] - add_dropin_config_from_resource(state.root, "serial-getty@ttyS0.service", "autologin", + add_dropin_config_from_resource(state.root, "serial-getty@hvc0.service", "autologin", "mkosi.resources", "serial_getty_autologin.conf") - ttys += ["ttyS0"] + ttys += ["hvc0"] add_dropin_config_from_resource(state.root, "getty@tty1.service", "autologin", "mkosi.resources", "getty_autologin.conf") @@ -2331,10 +2331,10 @@ def load_kernel_command_line_extra(args: argparse.Namespace) -> list[str]: columns, lines = shutil.get_terminal_size() cmdline += [ - f"systemd.tty.term.ttyS0={os.getenv('TERM', 'vt220')}", - f"systemd.tty.columns.ttyS0={columns}", - f"systemd.tty.rows.ttyS0={lines}", - "console=ttyS0", + f"systemd.tty.term.hvc0={os.getenv('TERM', 'vt220')}", + f"systemd.tty.columns.hvc0={columns}", + f"systemd.tty.rows.hvc0={lines}", + "console=hvc0", ] return cmdline @@ -3558,7 +3558,19 @@ def run_qemu(config: MkosiConfig) -> None: else: # -nodefaults removes the default CDROM device which avoids an error message during boot # -serial mon:stdio adds back the serial device removed by -nodefaults. - cmdline += ["-nographic", "-nodefaults", "-serial", "mon:stdio"] + cmdline += [ + "-nographic", + "-nodefaults", + "-chardev", "stdio,mux=on,id=console,signal=off", + # Use virtconsole which appears as /dev/hvc0 in the guest on which a getty is automatically + # by spawned by systemd without needing a console= cmdline argument. + "-device", "virtio-serial", + "-device", "virtconsole,chardev=console", + "-mon", "console", + # EDK2 doesn't support virtio-serial, so add a regular serial console as well to get bootloader + # output. + "-serial", "chardev:console", + ] cmdline += ["-drive", f"if=pflash,format=raw,readonly=on,file={firmware}"]