Serial Login

From YobiWiki
Jump to navigation Jump to search

Inspired by but the Debian way.

Support in BIOS

I use 57600 as this is the speed set in my BIOS (yes, even BIOS management via serial!)

Support in Grub

Add to /boot/grub/menu.lst

# Setup serial (COM1) here with baudrate 57600
# use --unit=1 (for COM2) and so on
serial --unit=0 --speed=57600
# Now setup terminal as both Serial Line(/dev/ttyS0) and
# Monitor Console(/dev/tty0) depending upon where you press key
# with in timeout (15 sec) period. Otherwise first entry
# (console(Monitor)=>tty0) is selected here.
terminal --timeout=15  console serial



Support in Kernel

To get messages on both consoles, use "console=ttyS0,57600" and "console=tty0", modify these lines (but let them commented!) in /boot/grub/menu.lst to change kernel options

# defoptions=console=ttyS0,57600 console=tty0
# altoptions=(recovery mode) console=ttyS0,57600 console=tty0 single
# altoptions=(recovery mode via serial) console=tty0 console=ttyS0,57600 single



Support in console

Uncomment in /etc/inittab and change speed

T0:23:respawn:/sbin/getty -L ttyS0 57600 vt100

check if ttyS0 is well present in /etc/securetty to be able to login directly as root


You can use

  • minicom
  • socat (man pages of stty and termios can help understanding the tweaks of terminals
socat -,icanon=0,echo=0 /dev/ttyUSB2,raw,echo=0,b9600

With that socat command:

  • echo is ok, colors are supported, arrows also, ctrl-d
  • ctrl-c is local -> exit socat
  • To get ctrl-c working remotely instead of locally
    But then socat must be killed externally to quit:
socat -,icanon=0,echo=0,isig=0 /dev/ttyUSB2,raw,echo=0,b9600
  • If F1..F10 don't work in mc or other problems, this is probably because of a mismatch of terminfo.
    • You can use instead esc-1..esc-9, esc-0 (for F10) in mc
    • You can also simply fix the TERM variable according to your local terminal, which means sth like:
    • export TERM=xterm # if you are in an xterm
    • export TERM=linux # if you are in a text console

Here is a simple bash script to launch serial consoles in an easy and explicit way:


# Usage:
#  -c to get ctrl-c working remotely instead of locally
#     this means you'll have to kill socat by other means!

if [ "$SPEED" == "$DATA" ]; then
    echo "Error, this script must be called by a symlink with a proper name" >&2
    echo "Example: machine1%USB0@9600" >&2
    echo "to connect to machine1 via local port /dev/ttyUSB0 at 9600bps" >&2
    exit 1

echo "============================================================================"
if [ "$1" == "-c" ]; then
    echo "CTRL-C will be active remotely but not locally!"
    echo "CTRL-C will be active locally but not remotely!"
    echo "Use \"$0 -c\" if you want the other way"  
echo "Once you are logged, you'd better fix the terminfo to your current settings:"
echo "        >>>>>>>>>>>>>>>>>>>> export TERM=$TERM <<<<<<<<<<<<<<<<<<<<"
echo "   You have to do it manually as i've no idea in which state the port is"
echo "       And, of course, don't forget to logout! CTRL-D works remotely" 
echo " Press enter to get a login or CTRL-L if there is already a running session"
echo "============================================================================"
socat -,icanon=0,echo=0${ISIG} ${PORT},raw,echo=0,b${SPEED}