Jump to content

# Linux console

6 languages

- Español
- 日本語
- Português
- Русский
- Türkçe
- 中文（简体）

From ArchWiki

Related articles

- /Keyboard configuration
- Screen capture#Virtual console
- Color output in console
- getty

According to Wikipedia:

  The Linux console is a system console internal to the Linux kernel. The Linux console provides a way for the kernel and other processes to send text output to the user, and to receive text input from the user. The user typically enters text with a computer keyboard and reads the output text on a computer monitor. The Linux kernel supports virtual consoles — consoles that are logically separate, but which access the same physical keyboard and display.

This article describes the basics of the Linux console and how to configure the font display. Keyboard configuration is described in the /Keyboard configuration subpage. For alternative console solutions offering more features (full Unicode fonts, modern graphics adapters etc.), see KMSCON or similar projects.

## Implementation

The console, unlike most services that interact directly with users, is implemented in the kernel. This contrasts with terminal emulation software, such as Xterm, which is implemented in user space as a normal application. The console has always been part of released Linux kernels, but has undergone changes in its history, most notably the transition to using the framebuffer and support for Unicode.

Despite many improvements in the console, its full backward compatibility with legacy hardware means it is limited compared to a graphical terminal emulator. The main difference between the Linux console and graphical terminal emulators is the shells in the Linux console are attached directly to TTY devices (`/dev/tty*`), whereas the shells in a graphical terminal emulator are attached to pseudo-TTYs (`/dev/pty*`).

Also, graphical terminal emulators can have many more features than the Linux console, including a richer set of available fonts, multiple tabs/windows, split views, scrollback buffers/sliders, background colors/images (optionally with transparency), etc. Some of these features can be used in the Linux console with terminal multiplexers, such as Tmux or GNU Screen, or in certain text user interface programs (TUI) typically relying on libraries such as ncurses and the like, e.g. Vim, nano, or Emacs. These can also be used in graphical terminal emulators, if desired.

### Virtual consoles

The console is presented to the user as a series of virtual consoles. These give the impression that several independent terminals are running concurrently; each virtual console can be logged in with different users, run its own shell and have its own font settings. The virtual consoles each use a device `/dev/ttyX`, and you can switch between them by pressing `Alt+Fx` (where `x` is equal to the virtual console number, beginning with 1). The device `/dev/console` is automatically mapped to the active virtual console.

See also chvt(1), openvt(1) and deallocvt(1).

### Text mode

Since Linux originally began as a kernel for PC hardware, the console was developed using standard IBM CGA/EGA/VGA graphics, which all PCs supported at the time. The graphics operated in VGA text mode, which provides a simple 80x25 character display with 16 colours. This legacy mode is similar to the capabilities of dedicated text terminals, such as the DEC VT100 series. It is still possible to boot in text mode (with `vga=0 nomodeset`) if the system hardware supports it, but almost all modern distributions (including Arch Linux) use the framebuffer console instead.

### Framebuffer console

As Linux was ported to other non-PC architectures, a better solution was required, since other architectures do not use VGA-compatible graphics adapters, and may not support text modes at all. The framebuffer console was implemented to provide a standard console across all platforms, and so presents the same VGA-style interface regardless of the underlying graphics hardware. As such, the Linux console is not a terminal emulator, but a terminal in its own right. It uses the terminal type `linux`, and is largely compatible with VT100.

## Keyboard shortcuts

Keyboard Shortcut | Description
--- | ---
`Ctrl+Alt+Del` | Reboots the system (specified by the symlink `/usr/lib/systemd/system/ctrl-alt-del.target`)
`Alt+F1`, `F2`, `F3`, ... | Switch to n-th virtual console (not to be confused with `Ctrl+Alt+Fn` used in Xorg and Wayland)
`Alt+Left` | Switch to previous virtual console
`Alt+Right` | Switch to next virtual console
`Scroll Lock` | When Scroll Lock is activated, input/output is locked
`Ctrl+c` | Kills current task
`Ctrl+d` | Inserts an EOF
`Ctrl+z` | Pauses current Task

See also console_codes(4).

## Fonts

The Linux console uses UTF-8 encoding by default, but because the standard VGA-compatible framebuffer is used, a console font is limited to either a standard 256, or 512 glyphs. If the font has more than 256 glyphs, the number of colours is reduced from 16 to 8. In order to assign correct symbol to be displayed to the given Unicode value, a special translation map, often called unimap, is needed. Nowadays, most of the console fonts have the unimap built-in; historically, it had to be loaded separately.

By default, the virtual console uses the kernel built-in font with a CP437 character set[1], but this can be easily changed. The kernel offers about 15 built in fonts to choose from, from which the officially supported kernels provide two: VGA 8x16 font (`CONFIG_FONT_8x16`) and Terminus 16x32 font (`CONFIG_FONT_TER16x32`). The kernel chooses the one to use based on its evaluation of the screen resolution. Another builtin font can be forced upon by kernel parameters boot parameter setting such as `fbcon=font:TER16x32`.

The kbd package provides tools to override the kernel decision for virtual console font and font mapping. Available fonts are provided in the `/usr/share/kbd/consolefonts/` directory; those ending with .psfu or .psfu.gz have a Unicode translation map built-in.

Keymaps, the connection between the key pressed and the character used by the computer, are found in the subdirectories of `/usr/share/kbd/keymaps/`; see /Keyboard configuration for details.

Note: Replacing the font can cause issues with programs that expect a standard VGA-style font, such as those using line drawing graphics.
Tip: For European based languages written in Latin/Greek letters, you can use the `eurlatgr` font. It includes a broad range of Latin/Greek letter variations as well as special characters [2].

### Preview and temporary changes

Tip: An organized library of images for previewing is available: Linux console fonts screenshots.

    $ showconsolefont

shows a table of glyphs or letters of a font.

`setfont` temporarily changes the font if passed a font name (in `/usr/share/kbd/consolefonts/`) such as

    $ setfont lat2-16 -m 8859-2

Font names are case-sensitive. With no parameter, `setfont` returns the console to the default font.

So to have a small 8x8 font, with that font installed like seen below, use e.g.:

    $ setfont -h8 /usr/share/kbd/consolefonts/drdos8x8.psfu.gz

To have a bigger font, the Terminus font (terminus-font) is available in many sizes, such as `ter-132b` which is large.

You can also append `-d` for double size. This would be using a 64*64 font:

    $ setfont -d ter-132n

Tip:

- All font changing commands can be typed in "blind".
- The Terminus font names (`ter-*`) are explained in `/usr/share/terminus-font/README`.

Note: setfont only works on the console currently being used. Any other consoles, active or inactive, remain unaffected.

### Persistent configuration

The `FONT` variable in `/etc/vconsole.conf` is used to set the font at boot, persistently for all consoles. See vconsole.conf(5) for details.

For displaying characters such as Č, ž, đ, š or Ł, ę, ą, ś using the font `lat2-16.psfu.gz`:

    /etc/vconsole.conf

    ...
    FONT=lat2-16
    FONT_MAP=8859-2

It means that second part of ISO/IEC 8859 characters are used with size 16. You can change font size using other values (e.g. `lat2-08`). For the regions determined by 8859 specification, look at the Wikipedia:ISO/IEC 8859#The parts of ISO/IEC 8859.

Since mkinitcpio v33, the font specified in `/etc/vconsole.conf` gets automatically loaded during early userspace by default via the `consolefont` hook, which adds the font to the initramfs. See Mkinitcpio#HOOKS for more information.

You may also need to restart `systemd-vconsole-setup.service` after changing `/etc/vconsole.conf`.

If the fonts appear to not change on boot, or change only temporarily, it is most likely that they got reset when graphics driver was initialized and console was switched to framebuffer. By default, all in-tree kernel drivers are loaded early, NVIDIA users should see NVIDIA#Early loading to load their graphics driver before `/etc/vconsole.conf` is applied.

## Cursor appearance

This subject is poorly documented. You should read the following articles:

- Software cursor for VGA
- Cursor Appearance in the Linux Console
- Disable Cursor Blinking on Linux Console

Cursor types
| Hardware | Software
--- | --- | ---
Shape | (0) default applies (2) underscore (1) invisible (2) underscore (3) lower third (4) lower half (5) two thirds (6) full block | (16) full block the shape can't be changed, but the cursor can effectively be invisible in case of background and foreground colors are equal
Blinking | blinks | driver-dependent the highest bit of background color can be interpreted as "bright" or as "blinking"
Color | the same as console text color (usually white/gray) can't be set independently | can be set by a user

The console cursor can be adjusted with Device Attributes (DA) control function. The sequence of parameters must be preceded by a single question mark (despite console_codes(4) says the opposite).

Here is an example for full block non-blinking green cursor with black symbols under it:

    $ printf "\x1b\x5b?16;$((8+4+2+1));$((32+0+8+4+2+1))\x63"

The same can be expressed with the octal and characters instead of hex codes:

    $ printf '\033[?16;15;47c'

Note: The comprehensive guide on control functions (escape sequences) is the standard ECMA-48 — Control Functions for Coded Character Sets.

The same can be applied as permanent configuration with kernel parameter:

    vt.cur_default=0x2f0f10

Note: Escape sequence parameters (16, 15, 47) are written in hex (10, 0f, 2f) in reversed order.

### Cursor size

The first parameter, despite it's name cursor size, with number 16 (the rightmost two hex digits of the kernel parameter are 10) means "use software cursor."

Note: You may have to use 48 (32+16), 80 (64+16) or 112 (64+32+16) instead of 16.

If you want to change hardware cursor shape - use corresponding number (from 0 to 6, see the table above).

Note: Cursor size is the only parameter applicable to hardware cursor.

### Toggle mask

The second parameter, called toggle mask, flips corresponding bits of the color.

Character attribute bits
| Background (cursor block) | Foreground (symbol under the cursor)
--- | --- | ---
| Bright (highlight) or blinking | Red | Green | Blue | Bright (highlight) or blinking | Red | Green | Blue
Decimals | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1
Hex | 80 | 40 | 20 | 10 | 8 | 4 | 2 | 1

In our case the second parameter is 15 (the middle hex digits of the kernel parameter are 0f), so all four foreground (symbol) bits will be flipped. The most important rule is: toggling (the second parameter) is applied after the setting (the third parameter).

Note: If a bit is set by the third parameter and is toggled by the second one - it is effectively cleared.

### Set mask

The third parameter is called set mask. It sets corresponding character attribute bits. We use 47 (the leftmost hex digits of the kernel parameter are 2f) in our example, which means two things:

- (32) use pure green color for cursor block
- (8+4+2+1) set all four foreground (symbol color) bits. These bits will be toggled by the second parameter, so the color of the symbol under the cursor will be black (`0000`).

## HiDPI

See HiDPI#Linux console (tty).

## Audible tones

See PC speaker#Beep.

## See also

- The TTY demystified – Linus Åkesson

Category:

- Linux console