Linux console (简体中文)
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
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
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).
终端字体
默认情况下, 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 。
预览和测试
showconsolefont 指令会以表格形式显示可用字与字符:
$ showconsolefont
setfont 工具可以暂时改变字体,让用户可以决定是否要设为永久性设置。只要指定字体名称即可 (这些字体位于 /usr/share/kbd/consolefonts/
),比如:
$ setfont lat2-16
如果对新换的字体不满意,可以用以下指令撤消至默认字体 (就算终端显示乱码,这个指令依然可以执行,将指令「盲打」进去即可):
$ 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.