vt 4 devices Linux
linux-vt kernel virtual terminal devices

## Description

The kernel provides virtual terminal devices as `/dev/ttyN` where N is from `0` to `63`. These are character devices with major number 4 and minor number from 0 to 63. Each is a fully functional terminal device, with a line discipline. It does not support serial device control.

There are 63 kernel virtual terminals, numbered from 1 to 63. The file numbered 0 acts as an alias for whichever virtual terminal device is currently active. Initially, virtual terminal 1 is active.

The kernel creates the internal data structures for each virtual terminal on the fly, as each `/dev/ttyN` device is first opened. If nothing opens the relevant device file, therefore, the kernel does not allocate any resources for the virtual terminal.

The virtual terminals are managed by a terminal emulator program that (unless configured out) is built into the kernel itself. The emulator program does not run as a distinct process, and uses internal interfaces to the framebuffer and event I/O devices. Applications can take over individual virtual terminals, disconnecting the kernel's built-in terminal emulator from the I/O devices and thereby letting applications handle all I/O with those devices when that virtual terminal is the active one.

In the event of there being more than one framebuffer device available, applications can also control which framebuffer device is associated with which kernel virtual terminal (although only one kernel virtual terminal can be active at any given time). This is done through the framebuffer devices, however, not through the virtual terminal devices.

The type of the terminal emulated does not closely match any other terminal, although there are borrowings from DEC VTs, ECMA-48, and the Xenix console. Only 256 colours are supported, direct colour being emulated by mapping to the nearest indexed colour; and the DEC VT/Xenix control sequence conventions for the ⇱ Home and ⇲ End keys are swapped with the Find and Select keys.

### Hot keys

The user sitting at the keyboard and display can change which is the currently active kernel virtual terminal using hot-key keychords. What the keychords are is programmable by uploading different keyboard maps to the kernel's terminal emulator. By default when no keyboard map has been loaded and conventionally in most keyboard maps, the chord ⎇ Alt+FN requests a switch to virtual terminal N.

Applications that take over a virtual terminal and do their own HID and display handling, such as xorg 8, have their own hot keys that are not necessarily the same and that are not managed by the kernel. Conventionally but not universally in such applications, the chord ⎈ Control+⎇ Alt+FN requests a switch to virtual terminal N. For convenience, these same chords are conventionally mapped to virtual terminal switch requests in the keyboard map of the kernel's virtual terminal emulator, too.

Such applications can also block hot-key virtual terminal switches, which require their coöperation.

The kernel can be configured with a hot-key sequence in the virtual terminal subsystem (the "Magic SysRq" keys, also mis-named "SAK") that issues a `SIGKILL` signal to all processes that have an open file descriptor to the currently active virtual terminal device.

### Console output

The kernel virtual terminal subsystem usually (unless this is configured out) registers a console I/O handler by the internal name `tty`, enabling it to be the target for application and kernel console I/O (see linux-console 4). When `tty` has been made the target for console I/O, the console I/O by default always goes to the currently active kernel virtual terminal. This can be modified from user-mode by applications calling the ioctl 2 function against a kernel virtual terminal device, using `TIOCLINUX` and the undocumented `TIOCL_SETKMSGREDIRECT` subcode. This directs console I/O to a particular kernel virtual terminal, or reinstates the default behaviour (when virtual terminal number 0 is passed).

Whilst technically this ioctl 2 can be issued against any open kernel virtual terminal device, it is wise to issue it against the device that is to be selected. This ensures that the internal data structures for the kernel virtual terminal actually exist, by opening its device file; because if they do not console I/O via the kernal virtual terminal subsystem has no effect.

## See also

console_codes 4

  This describes the input and output control and escape sequences recognized and produced by the kernel's terminal emulator.

console_ioctl 4

  This describes the `ioctl()` controls that are peculiar to kernel virtual terminal devices. As of 2020, many controls are missing.

chvt 1

  a utility that can be used to switch amongst kernel virtual terminals under script control

con2fbmap 1

  a utility that can be used to query and set the mapping between kernel virtual terminals and framebuffers

fgetty 8
agetty 8
mingetty 8
ngetty 8
mgetty 8

  the family of programs (obsoleted by ttymon 8 before Linux was invented, on actual Unices) that are usually responsible for first opening kernel virtual terminal device files

linux-console 4

  the `/dev/console` device, which may or may not map to a virtual terminal

## Files

`/sys/class/tty/tty0/active`

  The contents of this pseudo-file are the currently active virtual terminal name. A file descriptor open to this file can be polled, and will set `POLLPRI` when the active device name changes. `POLLPRI` remains set until the contents of the file are (re-)read.

`/dev/vcsN`
`/dev/vcsaN`

  The contents of these pseudo-files comprise the character display buffers of virtual terminal N, as explained in vcs 4.

## History

A multiple virtual terminal subsystem, with the same hot-key keychords and many of the same control sequences and `ioctl()`s, first appeared in Xenix in 1985. It was named Multiscreen.

Until Linux version 1.1.54, the list of kernel virtual terminals was fixed (with a length given by the `NR_CONSOLES` constant in the source code) and data structures were not allocated on demand.

## Author

Documentation by

Jonathan de Boyne Pollard