1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-11 09:18:07 +03:00

vmspawn: add kernel configuration options

This commit is contained in:
Sam Leonard 2023-11-10 11:56:49 +00:00
parent cf3beb273b
commit 0f25e3e443
No known key found for this signature in database
GPG Key ID: 96850F0978CE78F0
2 changed files with 48 additions and 14 deletions

View File

@ -147,6 +147,16 @@
</listitem>
</varlistentry>
<varlistentry>
<term><option>--linux=</option><replaceable>PATH</replaceable></term>
<listitem>
<para>Set the linux kernel image to use for direct kernel boot.</para>
<para>If no kernel was installed into the image then the image will fail to boot.</para>
<xi:include href="version-info.xml" xpointer="v256"/>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--qemu-gui</option></term>

View File

@ -50,23 +50,25 @@ static int arg_qemu_kvm = -1;
static int arg_qemu_vsock = -1;
static unsigned arg_vsock_cid = VMADDR_CID_ANY;
static int arg_tpm = -1;
static char *arg_linux = NULL;
static bool arg_qemu_gui = false;
static int arg_secure_boot = -1;
static MachineCredentialContext arg_credentials = {};
static SettingsMask arg_settings_mask = 0;
static char **arg_parameters = NULL;
static char *arg_firmware = NULL;
static char *arg_runtime_directory = NULL;
static bool arg_runtime_directory_created = false;
static bool arg_privileged = false;
static char **arg_kernel_cmdline_extra = NULL;
STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
STATIC_DESTRUCTOR_REGISTER(arg_machine, freep);
STATIC_DESTRUCTOR_REGISTER(arg_qemu_smp, freep);
STATIC_DESTRUCTOR_REGISTER(arg_runtime_directory, freep);
STATIC_DESTRUCTOR_REGISTER(arg_parameters, strv_freep);
STATIC_DESTRUCTOR_REGISTER(arg_credentials, machine_credential_context_done);
STATIC_DESTRUCTOR_REGISTER(arg_firmware, freep);
STATIC_DESTRUCTOR_REGISTER(arg_linux, freep);
STATIC_DESTRUCTOR_REGISTER(arg_kernel_cmdline_extra, strv_freep);
static int help(void) {
_cleanup_free_ char *link = NULL;
@ -94,6 +96,7 @@ static int help(void) {
" --qemu-vsock=BOOL Configure whether to use qemu with a vsock or not\n"
" --vsock-cid= Specify the CID to use for the qemu guest's vsock\n"
" --tpm=BOOL Configure whether to use a virtual TPM or not\n"
" --linux=PATH Specify the linux kernel for direct kernel boot\n"
" --qemu-gui Start QEMU in graphical mode\n"
" --secure-boot=BOOL Configure whether to search for firmware which\n"
" supports Secure Boot\n"
@ -128,6 +131,7 @@ static int parse_argv(int argc, char *argv[]) {
ARG_QEMU_VSOCK,
ARG_VSOCK_CID,
ARG_TPM,
ARG_LINUX,
ARG_QEMU_GUI,
ARG_SECURE_BOOT,
ARG_SET_CREDENTIAL,
@ -148,6 +152,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "qemu-vsock", required_argument, NULL, ARG_QEMU_VSOCK },
{ "vsock-cid", required_argument, NULL, ARG_VSOCK_CID },
{ "tpm", required_argument, NULL, ARG_TPM },
{ "linux", required_argument, NULL, ARG_LINUX },
{ "qemu-gui", no_argument, NULL, ARG_QEMU_GUI },
{ "secure-boot", required_argument, NULL, ARG_SECURE_BOOT },
{ "set-credential", required_argument, NULL, ARG_SET_CREDENTIAL },
@ -246,6 +251,12 @@ static int parse_argv(int argc, char *argv[]) {
return log_error_errno(r, "Failed to parse --tpm=%s: %m", optarg);
break;
case ARG_LINUX:
r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_linux);
if (r < 0)
return r;
break;
case ARG_QEMU_GUI:
arg_qemu_gui = true;
break;
@ -306,9 +317,8 @@ static int parse_argv(int argc, char *argv[]) {
}
if (argc > optind) {
strv_free(arg_parameters);
arg_parameters = strv_copy(argv + optind);
if (!arg_parameters)
arg_kernel_cmdline_extra = strv_copy(argv + optind);
if (!arg_kernel_cmdline_extra)
return log_oom();
arg_settings_mask |= SETTING_START_MODE;
@ -660,7 +670,6 @@ static int run_virtual_machine(void) {
if (r < 0)
return log_oom();
log_debug("vhost-vsock-pci,guest-cid=%u,vhostfd=%d", child_cid, child_vsock_fd);
r = strv_extendf(&cmdline, "vhost-vsock-pci,guest-cid=%u,vhostfd=%d", child_cid, child_vsock_fd);
if (r < 0)
return log_oom();
@ -751,6 +760,12 @@ static int run_virtual_machine(void) {
return log_oom();
}
if (arg_linux) {
r = strv_extend_many(&cmdline, "-kernel", arg_linux);
if (r < 0)
return log_oom();
}
r = strv_extend(&cmdline, "-drive");
if (r < 0)
return log_oom();
@ -766,22 +781,31 @@ static int run_virtual_machine(void) {
if (r < 0)
return log_oom();
r = strv_prepend(&arg_parameters, "console=" DEFAULT_SERIAL_TTY);
r = strv_prepend(&arg_kernel_cmdline_extra, "console=" DEFAULT_SERIAL_TTY);
if (r < 0)
return log_oom();
if (ARCHITECTURE_SUPPORTS_SMBIOS) {
_cleanup_free_ char *kcl = strv_join(arg_parameters, " ");
_cleanup_free_ char *kcl = strv_join(arg_kernel_cmdline_extra, " ");
if (!kcl)
return log_oom();
r = strv_extend(&cmdline, "-smbios");
if (r < 0)
return log_oom();
if (arg_linux) {
r = strv_extend_many(&cmdline, "-append", kcl);
if (r < 0)
return log_oom();
} else {
if (ARCHITECTURE_SUPPORTS_SMBIOS) {
r = strv_extend(&cmdline, "-smbios");
if (r < 0)
return log_oom();
r = strv_extendf(&cmdline, "type=11,value=io.systemd.stub.kernel-cmdline-extra=%s", kcl);
if (r < 0)
return log_oom();
r = strv_extendf(&cmdline, "type=11,value=io.systemd.stub.kernel-cmdline-extra=%s", kcl);
if (r < 0)
return log_oom();
} else
log_warning("Cannot append extra args to kernel cmdline, native architecture doesn't support SMBIOS, ignoring");
}
} else
log_warning("Cannot append extra args to kernel cmdline, native architecture doesn't support SMBIOS");