Serial Port, Devices

Ubuntu Serial Port setup:

I am using a machine with Serial Port 0x3f8 (COM1) or /dev/ttyS0
create the following file:
 

# anand@megatron:~$ cat /etc/event.d/ttyS0
# tty1 - getty
#
# This service maintains a getty on tty1 from the point the system is
# started until it is shut down again.
start on stopped rc2
start on stopped rc3
start on stopped rc4
start on stopped rc5
stop on runlevel 0
stop on runlevel 1
stop on runlevel 6
respawn
exec getty -L 38400 ttyS0 vt102

Ubuntu does not use /etc/inittab for starting such services, rather, it uses UPSTART.

Following commands can be used to list, start and stop services.

initctl list
initctl start ttyS0
initctl stop ttyS0

root@megatron:~# initctl list
control-alt-delete (stop) waiting
logd (stop) waiting
rc-default (stop) waiting
rc0 (stop) waiting
rc1 (stop) waiting
rc2 (stop) waiting
rc3 (stop) waiting
rc4 (stop) waiting
rc5 (stop) waiting
rcS (stop) waiting
rcS-sulogin (stop) waiting
sulogin (stop) waiting
tty1 (start) running, process 6763
tty2 (start) running, process 5384
tty3 (start) running, process 5386
tty4 (start) running, process 5381
tty5 (start) running, process 5382
tty6 (start) running, process 5388
ttyUSB0 (stop) waiting
root@megatron:~# initctl stop ttyUSB0
initctl: Job not changed: ttyUSB0
root@megatron:~# initctl start ttyUSB0
ttyUSB0 (start) waiting
ttyUSB0 (start) starting
ttyUSB0 (start) pre-start
ttyUSB0 (start) spawned, process 24836
ttyUSB0 (start) post-start, (main) process 24836
ttyUSB0 (start) running, process 24836

Use minicom on another machine to login. Note that Root login will need appending ttyS0 to /etc/securetty. Nonroot user logins via serial should just work
Note: On the client side, the user should belong to dialout group

anand@megatron:~$ id anand
uid=731(anand) gid=731(anand)
groups=731(anand),4(adm),20(dialout),24(cdrom),25(floppy),29(audio),

30(dip),44(video),46(plugdev),107(fuse),109(lpadmin),114(admin),121(kvm)

Also ensure that the device ownership and permissions are correct:
(group dialout should have read/write perms)

anand@megatron:~$ ls -l /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 0 2008-11-04 18:09 /dev/ttyUSB0

Now, the final test:

bumblebee login: root
Password:
Last login: Tue Nov  4 12:53:31 SGT 2008 on ttyS0
Linux bumblebee 2.6.24-16-generic #1 SMP Thu Apr 10 13:23:42 UTC 2008 i686

root@bumblebee:~#

The following may help when a headless system needs to be controlled from just a serial console.

Setup Console Redirection from BIOS to serial port.

Setup GRUB to use serial port as Console:

Add the following at the top of the grub config file (common settings section)

serial --unit=0 --speed=38400 --word=8 --parity=no --stop=1 terminal --timeout=30 serial console

and append the following:

console=ttyS0,38400n8 console=tty0
to your active stanza (kernel line)

 

Linux Serial Communication

Connecting to a serial device such as network switch with a serial cable connected is quite simple:

screen /dev/ttyS0 9600

(source: Pete Savage's blog)

  • on the one machine run:
    /usr/sbin/pppd /dev/ttyS0 115200 noauth passive 10.0.0.1:10.0.0.2
    and on the other run (after you started the first one above)
    /usr/sbin/pppd /dev/ttyS0 115200 noauth
    (assuming the serial port is ttyS0 on both systems.) This should connect the two with ppp giving them addresses 10.0.0.1 and 10.0.0.2
  • Another solution: If you are using null modem cable, then you dont have to have pppd running. Just configure the getty to listen on specified port. For example:
    /sbin/getty -L ttyS0 38400 vt100
    Then you can hook up to it from another machine using cu or minicom. cu is a part of UUCP package and is generally nicer then minicom. For example to hook up to host running getty, I use this command:
    cu -l /dev/ttyS0 -s38400
    While troubleshooting you can use yes program - it will print y till stopped.
    yes > /dev/ttyS0
    and then you can cat /dev/ttS0 on another computer - this will tell you if serial ports are configured correctly.
  • On one end:
    pppd -detach noauth crtscts lock proxyarp 192.168.1.2:192.168.1.1 /dev/ttyS0 115200
    On the other:
    pppd -detach noauth crtscts lock proxyarp 192.168.1.1:192.168.1.2 /dev/ttyS0 115200

    If it complains, you can try to remove the "proxyarp" option, or to use a lower baud rate - try 19200 and then 9600. If all goes well, try pinging. and verify that the ppp interface you are using is indeed ppp0. Then You run into problems if your kernel doesn't have ppp support, but usually standard distribution kernels do. Try a "modprobe ppp" if it fails.

    Using a USB serial device

    If you are using a USB-Serial converter, plugin the USB device to your laptop. Insert appropriate USB modules (usb-ohci etc ) , usbserial, and the driver, for example pl2303. Your USB serial device should be mapped as /dev/ttyUSB0 ( SUSE ) or /dev/tts/USB0 (Gentoo)

    Use this device name to configure minicom.