From 4d9bbbbfa900d7b9e11e55569fae6b2343dfe4cf Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Tue, 28 May 2024 15:21:55 +0200 Subject: [PATCH] Pass arguments that look like env variables as env to systemd-nspawn The kernel passes unknown parameters as environment variables to pid1. Let's do the same for systemd-nspawn. Of course we don't know what is known and unknown so let's take advantage of the fact that kernel cmdline arguments are (usually) lower case and environment variables are (usually) upper case and use that to determine whether to pass something as an argument or an environment variable. --- mkosi/__init__.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 4bd9b6606..619dd172d 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -3998,11 +3998,22 @@ def run_shell(args: Args, config: Config) -> None: if args.verb == Verb.boot: # Add nspawn options first since systemd-nspawn ignores all options after the first argument. - cmdline += args.cmdline - # kernel cmdline config of the form systemd.xxx= get interpreted by systemd when running in nspawn as - # well. - cmdline += config.kernel_command_line - cmdline += config.kernel_command_line_extra + argv = args.cmdline + + for arg in itertools.chain(config.kernel_command_line, config.kernel_command_line_extra): + name, sep, _ = arg.partition("=") + + if sep and name.isupper(): + # When invoked by the kernel, all unknown arguments are passed as environment variables to pid1. + # Let's mimick the same behavior when we invoked nspawn as a container but only for upper case + # arguments. + cmdline += ["--setenv", arg] + else: + # kernel cmdline config of the form systemd.xxx= get interpreted by systemd when running in nspawn + # as well. + argv += [arg] + + cmdline += argv elif args.cmdline: cmdline += ["--"] cmdline += args.cmdline -- 2.47.2