]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
qemu: Use virtconsole serial console instead of regular serial console
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 30 Mar 2023 11:56:53 +0000 (13:56 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 30 Mar 2023 19:37:14 +0000 (21:37 +0200)
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.

mkosi.md
mkosi/__init__.py

index feef292eb96e75ba1c8c5f1af7369e1251a58ba8..afeb6e8affc6cf78ca0f118f1ef4064af7f3bce5 100644 (file)
--- 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=`
 
index fd32be39065cf12a43bd870a5551a64243c766f2..8877a29de7e648b8f7444587bd47c9e76e987fc4 100644 (file)
@@ -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}"]