Home / Alt manpages / openvt(1)

  • openvt(1)
  • User command
  • linux

Start a Program on a Separate Linux Virtual Terminal with openvt

You will launch a command on a Linux virtual terminal (VT), optionally switch your display to that terminal, and wait for the command to finish. The examples use openvt from kbd 2.6.4, installed here as package version 2.6.4-2ubuntu2. Allow about ten minutes if you already know which command you want to run.

You need a local Linux console with an available VT and permission to write to it. A terminal emulator connected over SSH is not the same thing as a local VT. The command does not create a graphical terminal window: it assigns the program's standard input, output and error to a kernel virtual terminal.

1. Check the installed command

Check the executable and version before relying on option details:

$ command -v openvt
/usr/bin/openvt
$ openvt --version
openvt from kbd 2.6.4

The package version and the program version are related but not identical labels. Keep the installed version in deployment notes when a script depends on this behaviour.

Checkpoint

If openvt --version works, the command is installed. It has not opened a VT or started another program.

2. Start a shell on the first available VT

With no -c option, openvt searches for the first available virtual terminal and runs the command there. Start a shell with:

$ openvt -- bash

The -- marks the end of openvt's options. It is a useful habit because everything after it belongs to the command being started. The shell's input, output and error go to the new VT, so you may not see its prompt in the terminal where you typed the command.

To make the new terminal the one shown on the physical console, add -s:

$ openvt -s -- bash

-s switches to the new VT as the command starts. It does not make the shell a login shell and it does not wait for the shell to exit.

3. Run a short command and wait for it

For a command that should finish before the caller continues, use -w. This example writes a visible marker on the selected VT and then exits:

$ openvt -s -w -- sh -c 'printf "%s\n" "openvt test complete"; sleep 2'
openvt test complete

The marker is shown on the new VT while it runs. When -s and -w are combined, openvt switches back to the controlling terminal after the command completes. Without -w, the launcher does not wait for the child command to finish.

Use a command with an obvious end while testing. A shell, editor or pager can wait for input indefinitely, making a successful launch look like a hung command.

4. Choose a particular VT when needed

Use -c with a VT number instead of letting openvt choose the first available one:

$ openvt -c 3 -s -w -- sh -c 'printf "%s\n" "running on VT 3"; sleep 2'
running on VT 3

The number identifies the VT, not a graphical display and not a shell session name. You must have write access to the supplied VT. If it is in use, the normal safety check can refuse the request. Verify the number and your console permissions before adding other options.

Checkpoint

Use -c only when you have a reason to target that VT. Otherwise omit it and let openvt find an available one.

5. Pass options to the child command

Options intended for the child must come after --. For example, this asks ls for a long listing:

$ openvt -- ls -l /tmp

Without the separator, an option such as -l can be interpreted by openvt as its own login-shell option. The command may then behave differently from what you intended, or the launcher may reject the invocation.

6. Understand login and shell defaults

If you omit the command, the manual says that openvt uses the SHELL environment variable. Make the choice explicit in scripts instead of depending on that environment:

$ openvt -s -w -- /bin/bash

Add -l when the command should be treated as a login shell:

$ openvt -s -w -l -- bash

The option prepends a hyphen to the command name it executes. It changes how the shell identifies itself and which startup files it considers; it does not grant additional privileges.

7. Keep force and service-oriented options out of routine use

-f forces opening a VT without checking whether it is already in use. This can disrupt another user's console session or overwrite what a foreground program is using. Treat it as a deliberate recovery measure, not a default. Before using it, identify the VT and accept that its current process may be interrupted:

$ openvt -c 3 -f -s -- /bin/sh

There is no general undo command for an interrupted session. Exit the new shell with exit, or press Ctrl-D when the shell is reading input. If a program was killed or its screen state was changed, return to another VT and restart that program through its normal recovery procedure.

-e executes the command without forking and is intended for /etc/inittab. It requires openvt to be a session leader, so it is not a drop-in replacement for ordinary launches. The -u option is also intended for init-style use: it finds the owner of the current VT and runs login as that user. Do not combine -u with -c or -l.

8. Diagnose a failed launch

First rerun the smallest command that demonstrates the problem, with -v for more output:

$ openvt -v -w -- sh -c 'printf "%s\n" "VT check"'
VT check

If the command cannot open a VT, check that you are on a local console, that a VT number was not chosen incorrectly, and that your account can write to the relevant console device. Avoid jumping straight to sudo: elevated privileges can hide a permissions problem and may start the child command with an unexpected environment.

If a command appears to have vanished, switch to the selected VT with your system's console key sequence and check whether it is waiting for input. For a controlled test, use -s -w with a short command and a visible message. The -w option affects waiting by the launcher; it does not terminate a child that is blocked in an interactive program.

Done means

  • openvt --version identifies the installed kbd implementation.
  • The command runs on a local VT, with -- separating launcher options from child options.
  • -s is used when the new VT should become visible, and -w when the caller must wait.
  • -c is used only with a known, writable VT number.
  • -f is reserved for an understood, potentially disruptive recovery case.
  • Interactive tests are exited normally, and no session was interrupted accidentally.