Skip to content

Commit

Permalink
Use qemu's virtconsole for the serial console
Browse files Browse the repository at this point in the history
edk2 now has a virtio serial driver so let's switch to virtconsole
for the serial console as it's significantly faster compared to the
old ISA serial console.
  • Loading branch information
DaanDeMeyer committed Jul 4, 2024
1 parent 5279498 commit a4c06e1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 25 deletions.
8 changes: 2 additions & 6 deletions mkosi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,10 @@ def configure_autologin(context: Context) -> None:
"--noclear --keep-baud console 115200,38400,9600")
configure_autologin_service(context, "[email protected]",
"--noclear -")
configure_autologin_service(context, "[email protected]",
configure_autologin_service(context,
f"[email protected]",
"--keep-baud 115200,57600,38400,9600 -")

if context.config.architecture.default_serial_tty() != "ttyS0":
configure_autologin_service(context,
f"serial-getty@{context.config.architecture.default_serial_tty()}.service",
"--keep-baud 115200,57600,38400,9600 -")


@contextlib.contextmanager
def mount_cache_overlay(context: Context, cached: bool) -> Iterator[None]:
Expand Down
20 changes: 4 additions & 16 deletions mkosi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,17 +420,6 @@ def to_oci(self) -> str:

return a

def default_serial_tty(self) -> str:
return {
Architecture.arm : "ttyAMA0",
Architecture.arm64 : "ttyAMA0",
Architecture.s390 : "ttysclp0",
Architecture.s390x : "ttysclp0",
Architecture.ppc : "hvc0",
Architecture.ppc64 : "hvc0",
Architecture.ppc64_le : "hvc0",
}.get(self, "ttyS0")

def supports_smbios(self, firmware: QemuFirmware) -> bool:
if self.is_x86_variant():
return True
Expand Down Expand Up @@ -3749,7 +3738,6 @@ def finalize_term() -> str:


def load_kernel_command_line_extra(args: argparse.Namespace) -> list[str]:
tty = args.architecture.default_serial_tty()
columns, lines = shutil.get_terminal_size()
term = finalize_term()

Expand All @@ -3759,9 +3747,9 @@ def load_kernel_command_line_extra(args: argparse.Namespace) -> list[str]:
"systemd.wants=network.target",
# Make sure we don't load vmw_vmci which messes with virtio vsock.
"module_blacklist=vmw_vmci",
f"systemd.tty.term.{tty}={term}",
f"systemd.tty.columns.{tty}={columns}",
f"systemd.tty.rows.{tty}={lines}",
f"systemd.tty.term.hvc0={term}",
f"systemd.tty.columns.hvc0={columns}",
f"systemd.tty.rows.hvc0={lines}",
]

if not any(s.startswith("ip=") for s in args.kernel_command_line_extra):
Expand All @@ -3785,7 +3773,7 @@ def load_kernel_command_line_extra(args: argparse.Namespace) -> list[str]:
f"systemd.tty.term.console={term}",
f"systemd.tty.columns.console={columns}",
f"systemd.tty.rows.console={lines}",
f"console={tty}",
f"console=hvc0",
f"TERM={term}",
]

Expand Down
3 changes: 2 additions & 1 deletion mkosi/qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,8 @@ def run_qemu(args: Args, config: Config) -> None:
"-nographic",
"-nodefaults",
"-chardev", "stdio,mux=on,id=console,signal=off",
"-serial", "chardev:console",
"-device", "virtio-serial-pci,id=mkosi-virtio-serial-pci",
"-device", "virtconsole,chardev=console",
"-mon", "console",
]

Expand Down
2 changes: 1 addition & 1 deletion mkosi/resources/mkosi.md
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,

`Autologin=`, `--autologin`
: Enable autologin for the `root` user on `/dev/pts/0` (nspawn),
`/dev/tty1` and `/dev/ttyS0`.
`/dev/tty1` and `/dev/hvc0`.

`MakeInitrd=`, `--make-initrd`
: Add `/etc/initrd-release` and `/init` to the image so that it can be
Expand Down
1 change: 0 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def mkosi(
check: bool = True,
) -> CompletedProcess:
kcl = [
f"console={Architecture.native().default_serial_tty()}",
f"TERM={finalize_term()}",
"loglevel=6",
"systemd.crash_shell",
Expand Down

0 comments on commit a4c06e1

Please sign in to comment.