Linux boot console serial

Debian Linux: Set a Serial Console

H ow do I set up a serial console on Debian Linux HP server for troubleshooting and login purpose?

To setup a serial console you need to edit the following files under Debian Linux:

  1. /boot/grub/menu.lst or /etc/default/grub (recommended for grub2)
  2. /etc/inittab
  3. /etc/securetty

Our Setup

/dev/ttyS0 (COM1) is detected and working serial console under Linux. For testing purpose, I’m going to set baud rate to 19200 and terminal type to vt100.

Grub Configuration (Grub2)

Edit /etc/default/grub, enter:
# vi /etc/default/grub
Append / modify as follows:

Save and close the file. Next run the following command to generate a grub2 config file /boot/grub/grub.cfg :
# update-grub

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

A Note About Grub Legacy (older version)

If you are not using GRUB2 update /boot/grub/menu.lst (grub legacy) with kernel line as follows with console port, and baud rate:

Save and close the file.

/etc/inittab Configuration

Edit /etc/inittab, enter:
# vi /etc/inittab
You need put a getty on a serial line for a terminal:

Save and close the file.

/etc/securetty Configuration

Edit /etc/securetty, enter:
# vi /etc/securetty
Make sure UART serial ports /dev/ttyS0 is listed:

Save and close the file. Now, you can reboot the server for testing purpose.

How Do I Connect Using a Serial Console?

You need to use the minicom command, which is a communication program that runs under most unices. You can install minicom as follows on your Debian / Ubuntu desktop system:
# apt-get install minicom
For rpm based distro such as RHEL / Fedora / CentOS Linux, enter:
# yum install minicom
Run minicom as follows to create a configuration file:
# minicom -s -c on
Press [down] key and select Serial port setup:

Fig.01: Setting up minicom serial port

  1. Press A to setup serial device name such as /dev/ttyS0
  2. Press E to setup Bps/Par/Bits (baud rate)
  3. Press [ESC] to exit
  4. From menu select “Save setup as DFL”
  5. Exit

Alternatively, you can create minicom config DFL file as follows:
# cat /etc/minicom/minirc.dfl
pu port /dev/ttyS0
pu baudrate 19200
pu bits 8
pu parity N
pu stopbits 1
pu rtscts No

Save and close the file. To connect to a serial console simply type the minicom command as follows:
# minicom
Sample outputs:

Fig.02: Minicom in action

How Do I Connect From MS-Windows XP / 2000 / Vista / 7 Desktop System?

You can use the HyperTerminal or putty client as described here.

How Do I Connect To a Serial Console Over IP Network ?

You need to use the KVM over IP client as described here or use the ipmitool command line tool for serial console redirection over IP (LAN/WAN). It is highly recommend that you access server over a serial console using some sort of VPN to encrypt all traffic.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

Linux Serial ConsoleВ¶

To use a serial port as console you need to compile the support into your kernel — by default it is not compiled in. For PC style serial ports it’s the config option next to menu option:

Character devices ‣ Serial drivers ‣ 8250/16550 and compatible serial support ‣ Console on 8250/16550 and compatible serial port

You must compile serial support into the kernel and not as a module.

It is possible to specify multiple devices for console output. You can define a new kernel command line option to select which device(s) to use for console output.

The format of this option is:

You can specify multiple console= options on the kernel command line. Output will appear on all of them. The last device will be used when you open /dev/console . So, for example:

defines that opening /dev/console will get you the current foreground virtual console, and kernel messages will appear on both the VGA console and the 2nd serial port (ttyS1 or COM2) at 9600 baud.

Читайте также:  Настройки мыши линукс минт

Note that you can only define one console per device type (serial, video).

If no console device is specified, the first device found capable of acting as a system console will be used. At this time, the system first looks for a VGA card and then for a serial port. So if you don’t have a VGA card in your system the first serial port will automatically become the console.

You will need to create a new device to use /dev/console . The official /dev/console is now character device 5,1.

(You can also use a network device as a console. See Documentation/networking/netconsole.rst for information on that.)

Here’s an example that will use /dev/ttyS1 (COM2) as the console. Replace the sample values as needed.

Create /dev/console (real console) and /dev/tty0 (master virtual console):

LILO can also take input from a serial device. This is a very useful option. To tell LILO to use the serial port: In lilo.conf (global section):

Adjust to kernel flags for the new kernel, again in lilo.conf (kernel section):

Make sure a getty runs on the serial port so that you can login to it once the system is done booting. This is done by adding a line like this to /etc/inittab (exact syntax depends on your getty):

Init and /etc/ioctl.save

Sysvinit remembers its stty settings in a file in /etc , called /etc/ioctl.save . REMOVE THIS FILE before using the serial console for the first time, because otherwise init will probably set the baudrate to 38400 (baudrate of the virtual console).

/dev/console and X Programs that want to do something with the virtual console usually open /dev/console . If you have created the new /dev/console device, and your console is NOT the virtual console some programs will fail. Those are programs that want to access the VT interface, and use /dev/console instead of /dev/tty0 . Some of those programs are:

It should be fixed in modern versions of these programs though.

Note that if you boot without a console= option (or with console=/dev/tty0 ), /dev/console is the same as /dev/tty0 . In that case everything will still work.

Thanks to Geert Uytterhoeven @ linux-m68k . org> for porting the patches from 2.1.4x to 2.1.6x for taking care of the integration of these patches into m68k, ppc and alpha.

© Copyright The kernel development community.

Источник

Enable Linux Serial Console login

Dec 21, 2019 · 5 min read

Why this article.

While working as a Linux System Admin I had many cases where I needed to work on a Server but the Server did not had internet access and I needed one.
to make things more difficult the ILO is dedicated to the Out Of band connection and can not disconnected…

The only option I had left available is to configure one of the COM ports of the Server as a Serial listening port and those connect through it.

Why did I write this document?

Although there are lot s of documents available on the Internet that are dealing with Linux serial ports, most of them seemed to be either out of date, or missing good examples on how to use it.
I wanted consistent documentation on how to setup simple terminal access (with a few tweaks) via RS232C serial ports for RHEL 7.

Step 1: Check your system’s serial support

First, let’s make sure that your operating system recognizes serial ports in your hardware. You should make a visual inspection and make sure that you have one or more serial ports on your motherboard or add-in PCI card. Most motherboards have two built-in ports, which are called COM1: and COM2: in the DOS/Windows world. You may need to enable them in BIOS before the OS can recognize them. After your system boots, you can check for serial ports with the following commands:

IMPORTANT NOTE :
If your server does not have a serial port , you can always but a USB to SERIAL connect in a reasonable small price.

Now we need to set the serial post we found with a listening getty service:

What is a getty?

A getty is is a program that opens a tty port, prompts for a login name, and runs the /bin/login command. It is normally invoked by init.

agetty options explained:

  • -L force line to be local line with no need for carrier detect (when you have no modem).
  • -f alternative /etc/issue file. This is what a user sees at the login prompt.
  • -i do not display any messages at the login prompt.
  • 9600 serial line rate in bps. Set this to your dumb terminal or terminal emulator line rate.
  • ttyS0 this is the serial port identifier.
  • vt100 is the terminal emulation. You can use others, but VT100 is the most common or “standard”. Another widely used terminal type is VT102.

Possible serial line rates (sometimes called baud rates) for the 16550A UART:

  • 110 bps
  • 300 bps
  • 1200 bps
  • 2400 bps
  • 4800 bps
  • 9600 bps
  • 19,200 bps
  • 38,400 bps
  • 57,600 bps
  • 115,200 bps
Читайте также:  Windows 10 профессиональная 64 bit с драйверами

I have tried all of these line rates. 9600 bps is generally O.K., and is a very common setting for networking hardware. 38,400 bps is the speed of the standard Linux console, so it is my second choice. If your dumb terminal or terminal emulator cannot handle 38,400 bps, then try 19,200 bps: it is reasonably speedy and you will not be annoyed.

Solaris Hardware Systems

if you are (for some reason) using a Solaris hardware then you do not need to run through this configuration , it should be priconfigured.

Step 2: Enable Serial port at boot.

Add to end of GRUB_CMD_LINELINUX, “console=ttyS0” Replace ttyS0 with your serial port.

Mine looks like this:

Run the following commands as root: Again replace ttyS0 with your serial port

Recreate the grub.conf configuration file :

And now make sure that getty is enabled for ttyS0 (for our example):

Console issued prompt :

Here was my custom issue file, /etc/issueserial. It uses escape sequences defined in the agetty manpage to add some useful information, such as the serial port number, line speed, and how many users are currently logged on:

Now, let’s make sure that the agetty process is listening on the serial ports:

Step 3: tune the login.

-I have tested this setup with a WYSE dumb terminal, a Linux laptop running Minicom, and Windows 2000/XP laptops running HyperTerminal. They all worked just fine.

Terminal settings: should be 9600, N, 8, 1. Terminal emulation should be set to VT100 or VT102. Turn flow control off. If you want to use the 38,400 bps serial port on ttyS1, then your settings should be adjusted to 38400, N, 8, 1.

Cable: To connect a laptop to the serial port on the Linux host, you need to have a null-modem cable. The purpose of a null-modem cable is to permit two RS-232 DTE devices to communicate with each other without modems between them. While you can construct this yourself, a good, sturdy manufactured null-modem cable is inexpensive and will last longer.

If you insist on making the cable yourself, then check out Nullmodem.Com for the wiring and pinout diagram.

Connectors: Motherboard serial ports are typically male DB-9 connectors, but some serial ports use DB-25 connectors. You may need some DB-9 to DB-25 converters or gender-changers in order to connect to your terminal. For a typical laptop to server connection, a DB-9 null-modem cable should be sufficient.

Here is what you should see on the dumb terminal or terminal emulator:

Note: If you want to be able to login via serial console as the root user, you will need to edit the /etc/securetty config file. The entries to add are highlighted in italic:

Step 4: Test serial port login.

There are several ways to login to a serial connection from the client side.

Some of the known clients are putty,minicom and cu (part of the “uuid” package).

The one that we are going to use now is screen,

I prefer screen for several reasons but mostly because it comfortable to use like the following example :

screen is able to connect to a serial port. It will connect at 9600 baud by default:

A different baud rate (e.g. 115200) may be specified on the command line.

To end the session, press Ctrl+a followed by k.

Источник

Working with the serial console

An Arch Linux machine can be configured for connections via the serial console port, which enables administration of a machine even if it has no keyboard, mouse, monitor, or network attached to it.

Installation of Arch Linux is possible via the serial console as well.

A basic environment for this scenario is two machines connected using a serial cable (9-pin connector cable). The administering machine can be any Unix/Linux or Windows machine with a terminal emulator program (PuTTY or Minicom, for example).

The configuration instructions below will enable boot loader menu selection, boot messages, and terminal forwarding to the serial console.

Contents

Configure console access on the target machine

Boot loader

When using GRUB with a generated grub.cfg , edit /etc/default/grub and enable serial input and output support:

Next add the GRUB_SERIAL_COMMAND variable and set the options for the serial connection. For COM1 ( /dev/ttyS0 ) with baud rate of 115200 bit/s:

Read GRUB’s manual on Using GRUB via a serial line and the serial command for detailed explanation of the available options.

GRUB Legacy

Edit the GRUB Legacy configuration file /boot/grub/menu.lst and add these lines to the general area of the configuration:

rEFInd

rEFInd supports serial console only in text mode. Edit refind.conf and uncomment textonly .

Syslinux

To enable serial console in Syslinux, edit syslinux.cfg and add SERIAL as the first directive in the configuration file.

For COM1 ( /dev/ttyS0 ) with baud rate of 115200 bit/s:

The serial parameters are hardcoded to 8 bits, no parity and 1 stop bit.[1]. Read Syslinux Wiki:Config#SERIAL for the directive’s options.

Kernel

Kernel’s output can be sent to serial console by setting the console= kernel parameter. The last specified console= will be set as /dev/console .

Читайте также:  Bluetooth адаптер buro bu bt40a драйвера linux

getty

At boot, systemd-getty-generator(8) will start a getty instance for each console specified in the kernel command line.

If you have not configured console= in kernel command line start serial-getty@device.service . For /dev/ttyS0 (COM1) that would be serial-getty@ttyS0.service . Enable the service to start it at boot.

Unless specified otherwise in the kernel command line, getty will be expecting 38400 bit/s baud rate, 8 data bits, no parity and one stop bit-times.

Making Connections

Connect using a terminal emulator program

Perform these steps on the machine used to connect the remote console.

Command line

dterm

dterm AUR is a tiny serial communication program. If you invoke it without parameters, it will connect to /dev/ttyS0 at 9600 baud by default. The following example connect to /dev/ttyS0 at 115200 baud, with 8 data bits, no parity bit and 1 stop bit-times:

See its homepage[2] for more examples.

Minicom

minicom can be obtained from the official repositories. Start Minicom in setup mode:

Using the textual navigation menu, change the serial port settings to the following:

Press Enter to exit the menus (pressing Esc will not save changes). Remove the modem Init and Reset strings, as we are not connecting to a modem. To do this, under the Modem and Dialing menu, delete the Init and Reset strings. Optionally save the configuration by choosing save setup as dfl from the main menu. Restart minicom with the serial cable connected to the target machine. To end the session, press Ctrl+A followed by Ctrl+X .

picocom

picocom is a tiny dumb-terminal emulation program that is very like minicom, but instead of mini, it is pico. The following example connect to ttyS0 at 9600 bps:

See its manual for detailed usage.

Screen

GNU Screen is able to connect to a serial port. It will connect at 9600 baud by default:

A different baud rate (e.g. 115200) may be specified on the command line.

To end the session, press Ctrl+a followed by K . Alternatively, press Ctrl+a , type :quit and confirm it by pressing Enter .

Serialclient

Serialclient[3] is a CLI client for serial connection written in ruby. Install ruby package, then install it with the following:

Then, you can use like this:

And, for Windows

On Windows machines, connect to the serial port using programs like PuTTY[4] or Terminalbpp[5].

Graphical front-ends

cutecom AUR is another gui enabled serial monitor.

putty is also available for Linux.

moserial is a gtk-based serial terminal, primarily intended for technical users and hardware hackers who need to communicate with embedded systems, test equipment, and serial consoles.

Installing Arch Linux using the serial console

  1. Connect to the target machine using the method described above.
  2. Boot the target machine using the Arch Linux installation CD.
  3. When the bootloader appears, select Boot Arch Linux () and press Tab to edit
  4. Append console=ttyS0,115200 and press Enter .
  5. Now systemd should detect ttyS0 and spawn a serial getty on it. Login as root and start the installation as usual.

Debugging an unresponsive machine using a serial console

Even though [7] has only raw and terse instructions, it presents the full scene. It is important to note that here, the machine under test got unresponsive in a reproducible manner. And that it happened during normal operation. So it could be accessed normally before it needed debugging. However, in general, the serial console is also useful for debugging boot issues. Perhaps by configuring the boot loader by hand at machine startup time. Also note the mentioned netconsole within the P.S paragraph of the external link from this section.

Troubleshooting

Ctrl+c and Minicom

If you are having trouble sending a Ctrl+c command through minicom you need to switch off hardware flow control in the device settings ( minicom -s ), which then enables the break.

Resizing a terminal

Unlike ssh, serial connections do not have a mechanism to transfer something like SIGWINCH when a terminal is resized. This can cause weird problems with some full-screen programs (e.g. less ) when you resize your terminal emulator’s window.

Resizing the terminal via stty is a workaround:

However, this requires you to manually input the proper geometry. The following methods should be simpler.

1. There is a lesser-known utility called resize , shipped with xterm , that can solve this problem. Invoke it without parameters after you resize the terminal emulator’s window:

2. If you do not want to install xterm, it is possible to do the same work via a shell function. Put the following function into your zshrc and invoke it without parameters after resizing the terminal emulator’s window:

Missing ports on multi-port expansion cards

This article or section needs expansion.

The number of serial ports using the generic 8250 driver on the default kernel configuration is set to 4 at runtime with a maximum of 32. This will prevent the creation of /dev/ttyS4 and above. Counting the typical built in serial port on the motherboard this prevents the use of the 4th serial port on a 4 port expansion card.

Источник

Оцените статью