Skip to content

Commit

Permalink
Fix tty resize with vmspawn as virtual machine manager
Browse files Browse the repository at this point in the history
A default console is configured  on the kernel commandline by
systemd-vmspawn, and the value depends on the booted architecture. The
rows/columns configuration by mkosi must match that console device to
have an effect.
  • Loading branch information
hundeboll committed Feb 13, 2025
1 parent e30c37b commit e5012a6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
24 changes: 24 additions & 0 deletions mkosi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,30 @@ def default_qemu_nic_model(self) -> str:
Architecture.s390x: "virtio",
}.get(self, "virtio-net-pci") # fmt: skip


def default_vmm_tty(self, vmm: Vmm) -> str:
if vmm == Vmm.qemu:
return "hvc0"

# return default console device for systemd-vmspawn; see src/vmspawn/vmspawn-util.h
if self in (
Architecture.arm,
Architecture.arm64,
):
return "ttyAMA0"

if self == Architecture.s390x:
return "ttysclp0"

if self in (
Architecture.ppc,
Architecture.ppc64,
Architecture.ppc64_le,
):
return "hvc0"

return "ttyS0"

def is_native(self) -> bool:
return self == self.native()

Expand Down
18 changes: 7 additions & 11 deletions mkosi/qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
Firmware,
Network,
OutputFormat,
Vmm,
VsockCID,
finalize_term,
format_bytes,
Expand Down Expand Up @@ -851,6 +852,7 @@ def finalize_state(config: Config, cid: int) -> Iterator[None]:

def finalize_kernel_command_line_extra(config: Config) -> list[str]:
columns, lines = shutil.get_terminal_size()
tty = config.architecture.default_vmm_tty(config.vmm)
term = finalize_term()

cmdline = [
Expand All @@ -859,9 +861,9 @@ def finalize_kernel_command_line_extra(config: Config) -> 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.hvc0={term}",
f"systemd.tty.columns.hvc0={columns}",
f"systemd.tty.rows.hvc0={lines}",
f"systemd.tty.term.{tty}={term}",
f"systemd.tty.columns.{tty}={columns}",
f"systemd.tty.rows.{tty}={lines}",
]

if not any(s.startswith("ip=") for s in config.kernel_command_line_extra):
Expand All @@ -883,14 +885,8 @@ def finalize_kernel_command_line_extra(config: Config) -> list[str]:
# CD-ROMs are read-only so tell systemd to boot in volatile mode.
cmdline += ["systemd.volatile=yes"]

if config.console != ConsoleMode.gui:
cmdline += [
f"systemd.tty.term.console={term}",
f"systemd.tty.columns.console={columns}",
f"systemd.tty.rows.console={lines}",
"console=hvc0",
f"TERM={term}",
]
if config.console != ConsoleMode.gui and config.vmm == Vmm.qemu:
cmdline += [f"console={tty}"]
elif config.architecture.is_arm_variant():
cmdline += ["console=tty0"]

Expand Down

0 comments on commit e5012a6

Please # to comment.