]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stub: Prefer graphical console over virtio detection heuristic
authorKai Lüke <kai@amutable.com>
Wed, 8 Jul 2026 15:25:11 +0000 (00:25 +0900)
committerLennart Poettering <lennart@poettering.net>
Thu, 9 Jul 2026 08:54:52 +0000 (10:54 +0200)
With vmspawn --console=gui and similar one has the case where the VirtIO
PCI device is present for something else than the console and the logic
in sd-stub added console=hvc0 even though it didn't exist. This caused
tty0 to be empty during boot.
Always prefer the graphical console before a potential virtio console.
The virtio console is still preferred over a serial console and we can
get the same problem there, e.g., qemu-guest-agent is used causing the
PCI device but without a virtio console and instead a serial console is
used. This is not solved here.

src/boot/console.c

index 1115eeaae0a2c6a998d471c2e5029f2780d43285..95f1d112476dc5903f36cd80daf014ad4be61d7e 100644 (file)
@@ -547,14 +547,16 @@ static const char16_t *serial_console_arg(uint32_t index) {
 /* If there's no console= in the command line yet, try to detect the appropriate console device.
  *
  * Detection order:
- * 1. If exactly one VirtIO console PCI device exists -> console=hvc0
- * 2. If there's graphical output (GOP) -> don't add console=, the kernel defaults are fine
+ * 1. If there's graphical output (GOP) -> don't add console=, the kernel defaults are fine
+ * 2. If exactly one VirtIO console PCI device exists -> console=hvc0
  * 3. On x86, if exactly one serial console exists -> console=uart,io,<addr>
  * 4. Otherwise -> don't add console=, let the user handle it
  *
- * VirtIO console takes priority since it's explicitly configured by the VMM. Graphics is
- * checked before serial to avoid accidentally redirecting output away from a graphical
- * console by adding a serial console= argument.
+ * Graphics is checked first to avoid redirecting output away from a graphical console.
+ * The VirtIO console takes priority over serial since it's explicitly configured by the VMM but detection
+ * by PCI ID also triggers for non-console ports, so its presence alone doesn't imply that a hvc0 console
+ * actually exists. For example, for qemu-guest-agent the PCI device is present but only a traditional
+ * serial console is used. In this case we wrongly prefer hvc0 for now.
  *
  * Serial console auto-detection is restricted to x86 where ACPI PNP0501 UIDs map to fixed
  * I/O port addresses for 8250/16550 UARTs. On non-x86 (e.g. ARM), serial device indices are
@@ -571,14 +573,15 @@ void cmdline_append_console(char16_t **cmdline) {
                 return;
         }
 
+        if (has_graphics_output()) {
+                log_debug("Graphical output available, not adding console= to kernel command line.");
+                return;
+        }
+
         const char16_t *console_arg = NULL;
 
         if (has_virtio_console_pci_device())
                 console_arg = u"console=hvc0";
-        else if (has_graphics_output()) {
-                log_debug("Graphical output available, not adding console= to kernel command line.");
-                return;
-        }
 #if defined(__i386__) || defined(__x86_64__)
         else {
                 uint32_t serial_index;