Mastering Ubuntu Virtual Consoles: Practical chvt Guide

Overview

When an Xorg or Wayland graphical desktop hangs, or when you need a completely isolated out-of-band text interface for recovery, managing Linux virtual terminals (VT/TTY) becomes an essential skill. This guide covers how to switch foreground displays seamlessly using the chvt utility, along with key companion tools to inspect, dispatch, and clean up virtual console sessions in Ubuntu.

Identifying Terminal Sessions and Active Virtual Terminals

The tty utility identifies the specific device file mapped to standard input. An output of not a tty reveals that the current shell runs inside a non-interactive pipeline or background script rather than an interactive virtual console (tty) or pseudo-terminal (pts).

Inspecting TTY status

Running who inspects the host for currently authenticated user accounts and their associated terminal sessions. A completely blank response confirms that no interactive login sessions are active on the host.

Checking active logged-in users with who

Before querying the active foreground terminal, ensure the fgconsole command is present. The compound command below locates the binary and installs the kbd package automatically if it is missing.

Verifying and installing fgconsole via kbd

Invoking fgconsole returns the index of whichever virtual terminal currently controls the physical video output. The returned digit 1 indicates that virtual console 1 (tty1) is presently projected on the screen.

Querying active console index with fgconsole

Switching Virtual Terminals with chvt

Verify that the chvt (change virtual terminal) binary is installed on the system. The shell path /usr/bin/chvt confirms that the utility is ready for administrative execution.

Checking chvt availability

The chvt tool instructs the kernel console driver to switch the active video buffer to a specified terminal number. Issuing sudo chvt 1 transitions the display to console 1 (tty1). Operating under standard Unix conventions, successful execution produces no console text and immediately shifts the visible screen.

Switching to tty1 using sudo chvt 1

Similarly, running sudo chvt 2 redirects the foreground display to console 2 (tty2). In modern Ubuntu installations, display managers frequently host the graphical desktop or greeter on either tty1 or tty2, making this command indispensable for flipping between graphic and text environments. A clean return without error messages confirms that the switch succeeded.

Switching to tty2 using sudo chvt 2

Spawning Tasks on Dedicated Consoles with openvt

The openvt command allocates a new or idle virtual terminal and launches a specified process directly on it. Executing sudo openvt -c 3 -- ls -la /var/log targets console 3 (tty3) and runs a directory listing of /var/log on that dedicated display without interrupting the current session. A silent command prompt confirms that the job was successfully assigned to the background console.

Launching process on tty3 with sudo openvt

To review the output produced by the command inside console 3, elevate permissions and run sudo chvt 3. The display immediately switches over to tty3, presenting the directory listing rendered by ls.

Navigating to tty3 with sudo chvt 3

Releasing Inactive Virtual Consoles with deallocvt

Once an ad-hoc console session finishes, deallocvt reclaims system resources by freeing the kernel memory structures assigned to that virtual terminal. Running sudo deallocvt 3 releases the allocation for console 3 (tty3). The command completes silently upon successful deallocation.

Releasing console memory with sudo deallocvt 3

Re-running fgconsole prints the index of the terminal still occupying the physical monitor. The output 3 confirms that even though the kernel memory structures for tty3 were deallocated, the display adapter remains tuned to this screen until another console switch is triggered.

Verifying foreground console state after deallocation

Gaining proficiency with chvt, openvt, and deallocvt gives Linux administrators reliable, low-level control over system consoles. These utilities are particularly valuable when recovering from frozen desktop environments or isolating troubleshooting workflows on production servers.