vmspawn: Add headless console support

This commit is contained in:
Daan De Meyer
2026-03-24 21:36:19 +01:00
committed by Daan De Meyer
parent da9df5eb25
commit a8c2aa9e2f
5 changed files with 19 additions and 8 deletions
+7 -5
View File
@@ -658,11 +658,13 @@
<listitem><para>Configures how to set up the console of the VM. Takes one of
<literal>interactive</literal>, <literal>read-only</literal>, <literal>native</literal>,
<literal>gui</literal>. Defaults to <literal>interactive</literal>. <literal>interactive</literal>
provides an interactive terminal interface to the VM. <literal>read-only</literal> is similar, but
is strictly read-only, i.e. does not accept any input from the user. <literal>native</literal> also
provides a TTY-based interface, but uses qemu native implementation (which means the qemu monitor
is available). <literal>gui</literal> shows the qemu graphical UI.</para>
<literal>gui</literal>, <literal>headless</literal>. Defaults to <literal>interactive</literal>.
<literal>interactive</literal> provides an interactive terminal interface to the VM.
<literal>read-only</literal> is similar, but is strictly read-only, i.e. does not accept any input
from the user. <literal>native</literal> also provides a TTY-based interface, but uses qemu native
implementation (which means the qemu monitor is available). <literal>gui</literal> shows the qemu
graphical UI. <literal>headless</literal> runs the VM without any console, which is useful for
automated or scripted usage.</para>
<xi:include href="version-info.xml" xpointer="v256"/></listitem>
</varlistentry>
+1 -1
View File
@@ -56,7 +56,7 @@ _systemd_vmspawn() {
elif __contains_word "$prev" ${OPTS[SSH_KEY]}; then
comps='dsa ecdsa ecdsa-sk ed25519 ed25519-sk rsa'
elif __contains_word "$prev" ${OPTS[CONSOLE]}; then
comps='interactive native gui'
comps='interactive native gui read-only headless'
elif __contains_word "$prev" ${OPTS[IMAGE_FORMAT]}; then
comps='raw qcow2'
elif __contains_word "$prev" ${OPTS[ARG]}; then
+1
View File
@@ -24,6 +24,7 @@ static const char *const console_mode_table[_CONSOLE_MODE_MAX] = {
[CONSOLE_READ_ONLY] = "read-only",
[CONSOLE_NATIVE] = "native",
[CONSOLE_GUI] = "gui",
[CONSOLE_HEADLESS] = "headless",
};
DEFINE_STRING_TABLE_LOOKUP(console_mode, ConsoleMode);
+1
View File
@@ -27,6 +27,7 @@ typedef enum ConsoleMode {
CONSOLE_READ_ONLY, /* ptyfwd, but in read-only mode */
CONSOLE_NATIVE, /* qemu's native TTY handling */
CONSOLE_GUI, /* qemu's graphical UI */
CONSOLE_HEADLESS, /* no console */
_CONSOLE_MODE_MAX,
_CONSOLE_MODE_INVALID = -EINVAL,
} ConsoleMode;
+9 -2
View File
@@ -260,7 +260,7 @@ static int help(void) {
" --pass-ssh-key=BOOL Create an SSH key to access the VM\n"
" --ssh-key-type=TYPE Choose what type of SSH key to pass\n"
"\n%3$sInput/Output:%4$s\n"
" --console=MODE Console mode (interactive, native, gui)\n"
" --console=MODE Console mode (interactive, native, gui, read-only, headless)\n"
" --background=COLOR Set ANSI color for background\n"
"\n%3$sCredentials:%4$s\n"
" --set-credential=ID:VALUE\n"
@@ -2365,6 +2365,13 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
"-mon", "console");
break;
case CONSOLE_HEADLESS:
r = strv_extend_many(
&cmdline,
"-nographic",
"-nodefaults");
break;
default:
assert_not_reached();
}
@@ -2641,7 +2648,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
return log_oom();
}
if (arg_console_mode != CONSOLE_GUI) {
if (!IN_SET(arg_console_mode, CONSOLE_GUI, CONSOLE_HEADLESS)) {
r = strv_prepend(&arg_kernel_cmdline_extra, "console=hvc0");
if (r < 0)
return log_oom();