console 4 devices Linux
linux-console system console device

## Description

The `/dev/console` device provides access to the Linux console. What the console actually is can vary, and is configurable via the `console=` parameter on the kernel command line, supplied to it by the bootstrap kernel loader. The kernel maintains a list of console devices. The `/dev/console` device maps to the last device in the list. (Thus application output via `/dev/console` differs from kernel console message output, which goes to all devices listed.)

The `console=` parameter lists one or more serial port devices (see ttyS 4), parallel port devices (see lp 4), or kernel virtual terminal devices (see linux-vt 4). The default list in the absence of a parameter is usually `tty0`, the currently active kernel virtual terminal; although if the kernel virtual terminal subsystem is configured out it will be something else, with the kernel picking the console device.

These names are not devices in the filesystem. Contrary to the erroneous kernel documentation, `tty2` does not denote the second kernel virtual terminal, nor `lp0` the first parallel port. The names decompose into an alphabetic registration name and a numeric index.

- The registration names are internal names used by device drivers when they register that they can do console I/O, and are not required to bear any relation to what is visible in the filesystem. The kernel virtual terminal subsystem registers the console name `tty`, the parallel port driver registers the console name `lp`, the z/VM hypervisor registers the console name `hvc`, and so forth.

- The index only has meaning for device drivers that register more than one console I/O handler by the same name, allowing a particular handler instance to be selected from the `console=` parameter.

  This is not in fact the case for the KVT subsystem, the parallel port driver, nor indeed many of the drivers in the system; which register just a single console I/O handler each, no matter how many character devices they supply in the filesystem, using -1 as the index (which matches any index in the `console=` command-line argument). It is thus often ignored, making (say) `tty0` functionally equivalent to `tty2`. See linux-vt 4 for how to direct console output to different kernel virtual terminals, when `tty` or `ttyNN` is specified as the console.

`/dev/console` is a fully functional terminal device, with a line discipline. Its input and output are routed via the underlying device by the kernel. It does not support serial device control. For that, one must open the actual device underpinning the console. Nor does it support `ioctl()`s peculiar to kernel virtual terminal devices.

Process 1 commences execution with its standard input, output, and error file descriptors open to the console device, which the kernel expects to be available by the name `/dev/console` at that point. The initial root filesystem (initramfs, initrd, or physical on-disc filesystem) should thus have an explicit `/dev/console` character device file with the correct major and minor numbers, as no `/dev` filesystem is mounted by default at this point (although this is modifiable via a kernel configuration option).

The system console is a character device with major number 5 and minor number 1. (Compare minor number 2 for ptmx 4 and minor number 0 for tty 4.) Thus a `devtmpfs` filesystem automatically gains a node named `console` that denotes this device.

### In containers

The `/dev/console` device file available within a container may differ. What it is is determined by the applications software that created the container and populated its `/dev` directory. Some container systems have the convention of it being a bind-mounted pseudo-terminal front-end device, for example. Specifics are beyond the scope of this manual page, which only addresses the kernel-provided device file. See your container software's documentation.

## Files

`/sys/class/tty/console/active`

  The list of devices specified for the console. This is in the reverse order to the order used on the kernel command line, and thus the first item on the list is the one that the `/dev/console` device maps to.

## Standards conformance

The `/dev/console` device filename for the system console is required in order to conform with the Single Unix Specification (per "Directory Structure and Devices"). This explicitly permits it to be a link to another device. Linux does not implement it as a link, however.

## See also

syslog 3

  Opening `/dev/console` and writing messages there is an optional functionality of the syslog library.

## History

The `/dev/console` device has always been in Linux.

Until Linux version 2.1.71, it was a symbolic link to another device file that was managed outwith the kernel, rather than a fully-fledged character device in its own right.

## Author

Documentation by

Jonathan de Boyne Pollard