Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use qemu's virtconsole for the serial console #2834

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# mkosi Changelog

## v24

- The default kernel command line of `console=ttyS0` (or equivalent for
other architectures) has been removed. The required `console=`
argument to have the kernel output to the serial console has to be
added manually from `v24` onwards.

## v23.1

- Respin due to git tag mismatch
Expand Down
2 changes: 1 addition & 1 deletion mkosi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RemoveFiles=
/usr/lib/kernel/install.d/50-dracut.install

# Make sure that SELinux doesn't run in enforcing mode even if it's pulled in as a dependency.
KernelCommandLine=console=ttyS0 enforcing=0
KernelCommandLine=enforcing=0

[Host]
@QemuMem=4G
1 change: 0 additions & 1 deletion mkosi.conf.d/20-fedora/mkosi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ Packages=
pacman
qemu-user-static
systemd-networkd
systemd-ukify
zypper
1 change: 1 addition & 0 deletions mkosi.conf.d/20-fedora/mkosi.conf.d/20-uefi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Architecture=|arm64
[Content]
Packages=
sbsigntools
systemd-ukify
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,
"[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
26 changes: 4 additions & 22 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 @@ -741,10 +730,6 @@ def config_default_proxy_url(namespace: argparse.Namespace) -> Optional[str]:
return None


def config_default_kernel_command_line(namespace: argparse.Namespace) -> list[str]:
return [f"console={namespace.architecture.default_serial_tty()}"]


def make_enum_parser(type: type[StrEnum]) -> Callable[[str], StrEnum]:
def parse_enum(value: str) -> StrEnum:
try:
Expand Down Expand Up @@ -2449,8 +2434,6 @@ def parse_ini(path: Path, only_sections: Collection[str] = ()) -> Iterator[tuple
metavar="OPTIONS",
section="Content",
parse=config_make_list_parser(delimiter=" "),
default_factory_depends=("architecture",),
default_factory=config_default_kernel_command_line,
help="Set the kernel command line (only bootable images)",
),
ConfigSetting(
Expand Down Expand Up @@ -3755,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 @@ -3765,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 @@ -3791,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}",
"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
4 changes: 1 addition & 3 deletions mkosi/resources/mkosi.md
Original file line number Diff line number Diff line change
Expand Up @@ -1065,8 +1065,6 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,

`KernelCommandLine=`, `--kernel-command-line=`
: Use the specified kernel command line when building images.
Defaults to `console=ttyS0`. For `arm`, `s390` and `ppc`, `ttyS0` is replaced
with `ttyAMA0`, `ttysclp0` or `hvc0`, respectively.

`KernelModulesInclude=`, `--kernel-modules-include=`
: Takes a list of regex patterns that specify kernel modules to include in the image. Patterns should be
Expand Down Expand Up @@ -1121,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
3 changes: 1 addition & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import pytest

from mkosi.config import Architecture, finalize_term
from mkosi.config import finalize_term
from mkosi.distributions import Distribution
from mkosi.run import run
from mkosi.types import _FILE, CompletedProcess, PathString
Expand Down 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
Loading