Enable serial port linux

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 .

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.

Читайте также:  Razer lachesis 4000 dpi driver windows 10

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.

Источник

Ubuntu Documentation

Content Cleanup Required
This article should be cleaned-up to follow the content standards in the Wiki Guide. More info.

This document presents (almost) the minimum amount of work required to enable a serial console login on an Ubuntu 6.06 and later versions. (Minor changes have been added to improve performance.) Both server and client settings are included.

This procedure was developed using the Remote Serial Console HOWTO (see «External links» below), and adapted to apply specifically to Ubuntu. The reader is referred to this document for any issues arising from using this HOWTO.

Assumptions

You have enabled the serial console in your BIOS. 1

  • The serial connection is being made at 115200 baud 8n1, on first serial port, called /dev/ttyS0 in linux (9600 8n1 is the default fall back if your hardware does not support 115200 baud)
  • You are comfortable editing critical system files such as /etc/inittab, /boot/grub/menu.lst
  • You are using a serial (null modem) cable. It is also possible to use a USB to Serial adaptor, but the tty* must be changed to reflect your hardware.
  • You have an available serial console on ttyS0. If your not getting any output, a real serial port or other device might be using ttyS0. Try using ttyS1, ttyS2, etc.
  • If you want to use a standard Ethernet/RJ-45 cable for serial connection you can buy a couple of Serial to Cat 5 adapters or make one yourself.

    Server Setup

    Configuring the console login process

    This section details how to configure the ‘getty’ process to enable a login via the console port. You need to configure either an Upstart system or the older inittab, depending on Ubuntu version you are using.

    Configuring upstart (Karmic and newer)

    1) Create a file called /etc/init/ttyS0.conf containing the following:

    2) Ask upstart to start the getty

    Configuring upstart (Edgy/Feisty/Jaunty)

    Create a file called /etc/event.d/ttyS0 containing the following:

    Configuring inittab (only Dapper and older !)

    1) Edit /etc/inittab

    2) Change the following line:

    At this point, a new login prompt should appear on the output of the serial console.

    Configuring grub

    This section details how to get grub talking via the serial port.

    This section is optional if the user does not want grub interaction via the serial console port.

    Configuring (Karmic and newer)

    1) Edit /etc/default/grub

    Configuring grub (Edgy/Feisty/Jaunty)

    1) Edit /boot/grub/menu.lst:

    2) Add the following lines to the top of the file:

    3) When you next reboot, the output from grub will go to the normal console unless input is received from the serial port. Whichever receives input first becomes the default console. This gives you the best of both worlds.

    Configuring the kernel boot parameters

    This section details how to configure the kernel boot parameters to get boot information through the console port.

    This section is optional if the user does not want the kernel boot messages to appear on the serial console port.

    The following procedure can be carried out by modifying the ‘kernel’ line in grub prior to committing the changes directly to the /boot/grub/menu.lst file.

    1) Edit /boot/grub/menu.lst:

    2) Modify the kernel line for the image you want to boot using the serial console on. In this case, I’m setting up the default 2.6.10-5.386 kernel to use the serial console line. Change:

    Note two «console=» kernel options. You can specify this option several times. All devices, mentioned in it will receive kernel messages (those, generated by printk() and seen by dmesg). However, stdin/stdout/stderr of /sbin/init process will be set to the last device only, therefore only the last device will show startup messages and act as a console in single-user mode.

    3) Reboot into this kernel. Output from the boot process should be sent via the serial console line.

    Client Setup

    1) Ensure you have a read/write permissions on /dev/ttyS0.

    if the last command didn’t show an output add yourself to dialout group and logout/login:

    Alternatively, you can always run minicom through sudo, but it’s not recommended.

    2) Install minicom

    3) Configure minicom.

    4) Configure client serial port settings: In Serial port setup, set the following options

    4b) Using 7.10 on the server, I needed to set the following on the client:

    My 7.10 client and Windows’ HyperTerminal both defaulted to Yes; until I changed this client -> server communication did not work.

    5) Configure Initialization string: In Modem and dialing clear the init

    6) Save setup as dfl

    7) You might need to press enter several times to get the connection running.

    8) To log on in the future, run

    Читайте также:  Windows 10 как восстановить host

    and press enter several times if it does not come up on start up.

    Alternative serial client: screen

    GNU screen actually makes quite a capable serial terminal.

    (adjust to requirements)

    To end the session, use Ctrl-A,Shift-K.

    This is only needed if you plan to use serial console to enter BIOS configuration utility or observe early startup messages even before GRUB starts. Note, that in some cases it may interfere with GRUB settings described below. If you’re sure you’ve configured GRUB correctly, but the serial menu does not appear, try disabling serial console support in BIOS. (1)

    SerialConsoleHowto (последним исправлял пользователь tj 2018-11-05 10:36:54)

    The material on this wiki is available under a free license, see Copyright / License for details
    You can contribute to this wiki, see Wiki Guide for details

    Источник

    How To Check and Use Serial Ports Under Linux

    Display Detected System’s Serial Support Under Linux

    Simple run the dmesg command:
    $ dmesg | grep tty

    A note about USB based serial ports

    USB to RS232 adapter cable connects from the USB port of a computer to a device. Such serial to USB adapter connects to devices for configuration or programming under Linux. Here is what the dmesg command displays when you enter USB adapter:
    $ dmesg
    ## use grep command/egrep command to filter out USB devices ##
    $ dmesg | grep -i serial
    $ dmesg | grep -i FTDI

    Listing and using USB serial ports on Linux

    Here is how it looks when I attached USB device:
    $ sudo dmesg | more

    Use the setserial command to check and use serial ports

    The setserial is a program designed to set and/or report the configuration information associated with a serial port. This information includes what I/O port and IRQ a particular serial port is using, and whether or not the break key should be interpreted as the Secure Attention Key, and so on.

    Debian/Ubuntu Linux install setserial using the apt-get command/apt command

    $ sudo apt install setserial

    CentOS/RHEL/Oracle Linux install setserial using the yum command

    $ sudo yum install setserial
    Fedora Linux user try the dnf command:
    $ sudo dnf install setserial

    Using setserial to list serial ports and devices

    Now we installed required package. Open the termial and then type the following setserial command:
    $ setserial -g /dev/ttyS[0123]
    If you get an error/warning that reads as “Permission denied,” try running the command as the root user. For example, I am running it using the sudo command/su command:
    $ sudo setserial -g /dev/ttyS[0123]

    The setserial with -g option help to find out what physical serial ports your Linux box has.

    Listing or displaying USB serial ports on Linux

    Try:
    $ sudo setserial -g /dev/ttyUSB[01]

    • 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

    Linux serial console programs

    Once serial ports identified you can configure Linux box and use serial ports using various utilities:

    1. minicom– The best friendly serial communication program for controlling modems and connecting to dump devices
    2. wvidial or other GUI dial up networking program – a PPP dialer with built-in intelligence.
    3. Screen Command: Set Baud Rate [ Terminal Communication ]
    4. getty / agetty – agetty opens a tty port, prompts for a login name and invokes the /bin/login command.
    5. grub / lilo configuration – To configure serial port as the system console

    Cocnlusion

    You learned how to list or check serial ports including USB based adptor on Linux.

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

    Category List of Unix and Linux commands
    Documentation help • mandb • man • pinfo
    Disk space analyzers df • duf • ncdu • pydf
    File Management cat • cp • less • mkdir • more • tree
    Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
    Linux Desktop Apps Skype • Spotify • VLC 3
    Modern utilities bat • exa
    Network Utilities NetHogs • dig • host • ip • nmap
    OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
    Package Manager apk • apt
    Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
    Searching ag • grep • whereis • which
    Shell builtins compgen • echo • printf
    Text processing cut • rev
    User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
    WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

    Comments on this entry are closed.

    I don’t know if this is the place, but I’m looking for information that is similar. I have 2 machines setup through a null modem. I want to read through the com port from one machine to the other. The sending machine is running Windows sending through COM1: and the receiving computer is Linux Red Hat. Any help on this would be appreciated.

    You can use pyserial ,its a python package,can be used to read and write in serial ports

    another simple serial console program not mentioned is gtkterm.

    I want to advise you that probably there is an error in the last sentence “seserial with -g option help to find out what physical serial ports your Linux box has.”; isn’t it setserial?

    I have 4 standard serial ports defined, /dev/ttyS0-4, but I added a PCI-E 16 port serial adapter, and I have not found a way to connect anything to the upper 16 ports.
    How do you create the virtual links? what options do you give setserial to define the new ports?

    it dosn’t work 🙁 I can’t connect to my ASA using debian.

    Daemon is a program called getty used by UNIX/Linux systems. There are many different versions of getty. The first modem detected is /dev/ttys0 or /dev/ttys1. To create a link to the devices file so that you can view modem information. Type ln -s /dev/ttys1 /dev/modem.
    It is essential to set the modem to AUTO ANSWER using getty.

    download minicom from alioth.debian.org/projects/minicom.

    create a modem config file by entering minicom -s from the root command line
    select the options you want to configure using AT commands
    connect to the modem by typing in minicom

    Thanks very useful..save my time 🙂

    Hi,everybody
    I have a serial PCI card with two ports but neither of them is working, on Linux fedora 16. I have tried using “gtkterm” and “minicom” but unfortunately I can’t make a serial connection to my Cisco lab. Here is my output when I issue the command: “setserial -g /dev/ttyS[0123]”.

    /dev/ttyS0, UART: 16550A, Port: 0xec00, IRQ: 16
    /dev/ttyS1, UART: 16550A, Port: 0xe880, IRQ: 16
    /dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
    /dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3

    also I want to mention that when I try to connet throught the terminal it generates a message like so: ” Cannot open /dev/ttyS0: Permission denied”.
    any help please.
    abdel

    Check the permissions on /dev/ttyS0… Likely problem is it’s owned by root, and is part of the uucp group. Add yourself to the uucp group, and all should be better. I’m curious to know if this is enough for you as I am having problems communicating with a serial port on Linux as well. I got past the permissions stuff, but it is still not working.

    Thanks Tom,
    I actually I tried but it’s does not work, still says “permission denied”. I would appreciate if you explain to me step by step the procedure how to do it, I’m knew to Linux.
    Best Regards
    Abdel

    1) ls -la /dev/ttyS0 — This will report the permissions on the port. Typically, this will say crw-rw—- 1 root uucp. The “c” in the string indicates that it’s a “character device” the first “rw” indicates that the owner has read/write permission. The second “rw” means that the group has read/write permissions. The “—” indicates that the rest of the world has no permissions. After the “—-“, “root” indicates that the owner of the device is root, and that the group id is “uucp”. So, you either need to be root, or a member of the uucp group to have read/write access to the port.

    2) To add yourself to the uucp group (to get read/write access), you need to edit the file /etc/group, and add your user name to the line that begins with “uucp:” User names are separated by commas, so add a comma, then your user name to the end of the line. You will need root permissions to edit this file.

    3) log out, and log back in because group associations are made at login time, and are not queried on each request.

    Thanks Tom,
    here is my output from the group file I have added my username to it but does not work.

    I will just give up.Thanks a lot for your help I relay appreciate it.

    Your entry in /etc/group is incorrect. If you read my previous post, I said to add your user id to the line that _begins_ with uucp. You added uucp to the group of users that can access your account. You want an entry in the /etc/group file that looks something like:

    The critical element is that it’s the line that begins with uucp

    It works. I just add my username to ” dialout ” and it worked fine. Iwould like to thank you for you time and support.

    Best Regards
    Abdel

    hi,
    I have connected the SIM300(gsm model) to my pc running ubuntu. I need a code to send a AT command to the GSM module and it should read and display the reply.
    Please let me know steps.
    I tried so many methods and codes, but no use…

    i need C code(program).

    all my ttyS* shows unknown, earlier it was working fine, now it doesnt recognise

    setserial -g /dev/ttyS*
    /dev/ttyS0, UART: unknown, Port: 0x03f8, IRQ: 4
    /dev/ttyS1, UART: unknown, Port: 0x02f8, IRQ: 3
    /dev/ttyS2, UART: unknown, Port: 0x03e8, IRQ: 4
    /dev/ttyS3, UART: unknown, Port: 0x02e8, IRQ: 3

    #cat /etc/redhat-release
    CentOS Linux release 6.0 (Final)

    #dmesg | grep tty
    console [tty0] enabled

    can u pls help me

    tried spending time in google two days, still no success, tried connecting a brand new device too, still no success.

    Sorry, but that second sentence is not necessarily true. I have a PC with two dual com port adapters. Windows sees them as COM1 -> COM4 (there is no built in COM port). Linux sees them as /dev/ttyS4->/dev/ttyS7.

    /dev/ttyS0-/devttyS3 are apparently reserved, exist whether or not a physical port exists, and /dev/ttyS0 for certain is “special” in that it is used by the default terminal window:

    I think minicom still superior to other console utility.

    Hi All tried all of the above and still get permission denied . HELP
    Kevin

    /bpq$ setserial -g /dev/ttyS[012345657

    /bpq$ setserial -g /dev/ttyS[012345657]

    sudo setserial -g /dev/ttyS1

    Hiiiiiiiii
    Please help me
    i am install minicom and use serial modem sim300 v7.03 but there is problem to type AT cmd on minicom console…….

    Edgeports are very easy to use the firmware is on Ubuntu they are from 2 ports to 16+ I bought my last two of them on ebay.
    Jim

    Hi all..
    I got problem to connect with my USB serial port,
    i already create
    ln -s /dev/ttyUS0

    and check dmesg | grep tty
    [ 0.000000] console [tty0] enabled
    [ 7.722004] systemd[1]: Created slice system-getty.slice.
    [ 3659.524452] usb 1-1.1: FTDI USB Serial Device converter now attached to ttyUSB0
    [ 4850.183339] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
    [ 4857.907567] usb 1-1.1: FTDI USB Serial Device converter now attached to ttyUSB0
    when running SDNC program and select com1 will shown “port is already in use”

    hi, have are you\
    i have a problem with machine xnc . old version sistem operating linux,
    pc removed battery cmos . but change battery do it so machine different data serial port linux dont recognized machine.
    how can you slove this problem
    your help wil be welcome

    Источник

    Читайте также:  Windows 10 ltsc трекер
    Оцените статью