setlogcons
Set kernel console logging destination
SYNOPSIS
setlogcons console_number
PARAMETERS
console_number
The numeric identifier of the virtual console (e.g., 1, 2, 3) to which kernel messages and /dev/console output should be redirected. This number corresponds to the ttyN device (e.g., 1 for tty1).
DESCRIPTION
The setlogcons command is a utility used to redirect kernel messages and the output of the /dev/console device to a specific virtual console. By default, these critical system messages are typically directed to the first active virtual console (often tty1). This command empowers system administrators to change this default destination, allowing them to designate any virtual console, specified by its number, as the primary recipient for kernel logs.
This redirection is particularly useful for debugging, separating system log output from user interactive sessions on other consoles, or establishing a dedicated console solely for monitoring kernel events. It directly interacts with the kernel's virtual console subsystem to modify the target for these messages.
CAVEATS
Requires superuser (root) privileges to execute successfully.
The command affects where the kernel sends messages. While it can be run from any console, it's often recommended to first switch to the target virtual console (e.g., using chvt) and then execute setlogcons with that console's number for intuitive operation.
This command controls kernel console output; it does not directly manage or affect user-space logging daemons like syslogd or journald, although these daemons might read from /dev/console if configured to do so.
KERNEL INTERACTION
setlogcons operates by making a direct system call (specifically, an ioctl on the console device, usually KDSETLOGCONS) to the Linux kernel. This informs the kernel about which virtual console should receive all subsequent kernel printk messages and other output destined for the console. This direct interaction distinguishes it from user-space logging solutions.
USE CASES
Commonly employed in headless server environments, during system boot debugging, or when a system administrator needs a clean, dedicated console for real-time kernel output without interference from other login sessions or applications. It allows for a clear separation of system-level messages from interactive user activities.
HISTORY
setlogcons is an integral part of the kbd (keyboard and console utilities) package for Linux, reflecting its long-standing role in managing the Linux virtual console system. Its functionality dates back to the early development of the Linux kernel, serving as a fundamental tool for console management before the widespread adoption of graphical desktop environments. While its primary function remains relevant for low-level system administration and debugging, its direct usage might be less frequent in modern, primarily graphical desktop environments compared to its utility in server or embedded systems.