Linux console (简体中文) - ArchWiki

Jump to content

# Linux console (简体中文)

From ArchWiki

相关文章

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

这篇文章或章节的翻译不反映原文。

原因：Article created 2020-11-13, no updates since, mostly untranslated from english（在 Talk:Linux console (简体中文)# 中讨论）
翻译状态：本文是 Linux console 的翻译。上次翻译日期：2020-11-13。如果英文版本有所更改，则您可以帮助同步翻译。

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.

## Implementation

This article or section needs expansion.

Reason: In what ways is the Linux console limited compared to terminal emulators? (Discuss in Talk:Linux console (简体中文))

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.

### 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

This article or section needs expansion.

Reason: How do you boot in text mode? (Discuss in Talk:Linux console (简体中文))

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 the capabilities of dedicated text terminals, such as the DEC VT100 series. It is still possible to boot in text mode 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
`Alt+ ←` | Switch to previous virtual console
`Alt+ →` | 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).

## 终端字体

注意： 这部分是关于 Linux console。如果您想获取其它的更加丰富的关于终端的解决方案 (完备的 Unicode 字体, 现代的图形化配适器，等等。), 请参照 KMSCON 或者类似的项目.

默认情况下, virtual console 使用内核的内置字体，其包含 CP437 字体集,[1] 但是这个设置可以非常容易改变.

Linux console 默认使用 UTF-8 编码, 但是由于使用的是标准的兼容 VGA 的帧缓存, 终端字体限定为 256 或 512 个字形。如果字体超出了256个字形, 那么颜色的数量就会从 16 减少到 8。为了针对给定的 Unicode z值分配正确的可显示符号，一种特殊的翻译映射，通常叫做 unimap,是必须的。 就目前来看大多数终端字体都具有内置的 unimap, 但是历史上它是需要被单独载入的。

    kbd 包提供了改变虚拟终端字体和字体映射的工具。可以使用的字体存储在 /usr/share/kbd/consolefonts/ 目录下, 那些以 .psfu 或者 .psfu.gz 结尾的具有一个内嵌的 Unicode 翻译映射。

键盘映射 (Keymap) 是按键和计算机使用字符的对应关系表，可以在 `/usr/share/kbd/keymaps/` 的子目录下找到，详情请查看 Keyboard configuration in console 。

注意： Replacing the font can cause issues with programs that expect a standard VGA-style font, such as those using line drawing graphics.

### 预览和测试

提示： 这里有一个整理过的预览影像数据库：Linux 终端字体截图。

showconsolefont 指令会以表格形式显示可用字与字符：

    $ showconsolefont

setfont 工具可以暂时改变字体，让用户可以决定是否要设为永久性设置。只要指定字体名称即可 (这些字体位于 `/usr/share/kbd/consolefonts/`)，比如：

    $ setfont lat2-16

如果对新换的字体不满意，可以用以下指令撤消至默认字体 (就算终端显示乱码，这个指令依然可以执行，将指令「盲打」进去即可)：

    $ setfont

注意： setfont 只作用于当前正在使用的终端。其它终端无论活跃与否都不受影响。

### 持久性配置

`/etc/vconsole.conf` 的 `FONT` 变量可以用来在启动时设置字体, 对于所有的终端都具有持久性作用。详情请查看 vconsole.conf(5) 。

若要显示 Č, ž, đ, š 或 Ł, ę, ą, ś 之类的字符，请使用 `lat2-16.psfu.gz` 这个字体：

    /etc/vconsole.conf

    ...
    FONT=lat2-16

这代表使用 ISO/IEC 8859 字符的第二部分，尺寸设置为 16。您可以使用其它值更改字体尺寸 (如 `lat2-08`)。您可以在Wikipedia的这张表查询 8859 规范定义的本地。

若要为早期的用户空间套用指定字体，请在 `/etc/mkinitcpio.conf` 使用 `consolefont` 勾子。更多信息请参阅 Mkinitcpio (简体中文)#钩子(HOOKS)。

如果开机时字体没有任何变化，或只变化一下就恢复原样，则有可能是因为显卡驱动引导时字体被复位，然后终端被切至帧缓冲 (framebuffer)。提早装入图形驱动可以避免这个问题。若要在套用 `/etc/vconsole.conf` 之前将帧缓冲准备好，请参阅核心模式设置#提早引导 KMS、[2] 或其它方式。

## HiDPI

See HiDPI#Linux console.

## Audible tones

See PC speaker#Beep.

## See also

- The TTY demystified – Linus Åkesson

Category:

- Linux console (简体中文)

Hidden categories:

- Pages or sections flagged with Template:Bad translation (简体中文)
- Pages or sections flagged with Template:Expansion