Serial Null Modem Connection
From openSUSE
For debugging purposes it is often useful to have a serial connection to a computer. You have several advantages doing that:
- a real console is available from remote
- it is possible to use Sysreq calls from another computer
- Logs may be just logged instead of typed from the screen
- login to the machine is possible without a local keyboard or a network connection
What you need:
- a primary computer that should be observed, called server
- a null modem cabel
- a second computer that is connected with that cabel, called client
- a terminal emulation program
First, connect both computers with the cable.
Contents |
Server Configurations
Several actions are needed to make use of a serial connection to the server:
Configure the Bootloader GRUB
Disable the graphics in /boot/grub/menu.lst by adding a comment mark in front of the gfxmenu line:
#gfxmenu (hd0,4)/boot/message
To configure the serial port, add the following two lines to the global section of the menu file:
serial --unit=0 --speed=115200 terminal --timeout=5 console serial
This will make the bootloader visible on the serial line and display the prompt "Press any key to continue." for five seconds to determine where the boot menu should be displayed, after which it will be displayed on the first terminal listed.
Tell the Kernel about the new console
add a parameter
console=tty0 console=ttyS0,115200
to the commandline of the kernel. You may also add several devices, seperated by a comma. After the next reboot, the kernel will accept the device /dev/ttyS0 as a console and tty0 as the default console. Be careful if you make /dev/ttyS0 the default console since the kernel may refuse to continue loading if the default console is not available for writing.
Enable sysrq on the Server
Change the variable ENABLE_SYSRQ in /etc/sysconfig/sysctl to "yes". This may also be done with the "/etc/sysconfig Editor" in YaST. This variable is checkd at boottime, and sets the value of /proc/sys/kernel/sysrq accordingly.
Add a login Prompt
In the file /etc/inittab, remove the # at the beginning of the line
S0:12345:respawn:/sbin/agetty -L 115200 ttyS0 vt102
This will enable you to login as a normal user. To be able to login as root, you still need to add this device to /etc/securetty. Add the line
ttyS0
to /etc/securetty to have this possibility. If you don't want to reboot after this, run the command
telinit q
to reload the configuration file.
Redirect system messages
If you alternatively want to view system messages via serial line instead of getting a login prompt, add the following line to your /etc/syslog.conf instead:
*.* /dev/ttyS0
For versions of OpenSUSE using the syslog-ng facility add the following to the /etc/syslog-ng/syslog-ng.conf file:
destination ttyconsole { pipe("/dev/ttyS0" owner("root") group("uucp") perm(0440)); };
log { source(src); filter(f_console); destination(ttyconsole); };
This adds a new destination of the serial port being used as the console. It then tells syslog-ng to send the same logfile information that is currently being sent to the ALT+F10 screen to this console. Similar lines for tty10 are about about half way down the file that can be used as a model.
Note: If you have AppArmor running, the syslog-ng profile needs to be modified. An entry needs to be added to allow the w permission to the file /dev/ttyS0
Client
On the client side, you basically need a terminal emulation program. On Linux, a nifty tool for that is screen, on Windows there is HyperTerminal. If the serial port on the client is /dev/ttyS0 (COM1 on DOS/Windows), start the connection as follows:
screen /dev/ttyS0 115200
If all was done correctly, a login prompt should appear.
screen has many useful options. By default, you access its commands by typing CTRL-a <letter>. A small help is displayed with CTRL-A ? . Often used features are:
- CTRL-A H
start/stop a log on screenlog.0 in the current directory. - CTRL-A B
send a break to the server to issue a sysrequest. Try that for example with CTRL-A B H to get a small help for sysrequests from the kernel. - CTRL-A C
Start a second screen. - CTRL-A A
Toggle the display of the last used screen. - CTRL-A <NR>
Toggle screen with number <NR>.
Shared Client Session
Screen allows you to work simultaneously from multiple terminals; this is called "share session" mode.
To make things easy, I recommend you to use same user-account on all your terminals, (create a new user "sharer", if must) and write down the command on all terminals:
screen -x
This will attach every terminal, where you typed the command above, to the same session, so you can work simultaneously from several terminals.
KDE 4 Konsole Serial Terminal Emulation
The KDE console is named Konsole. To set up a serial terminal under KDE 4.x:
- Open the terminal program konsole from the application menu.
- Select Settings > Manage Profiles
- Create a new profile and call it something like "Serial Terminal"
- For the command, enter
-
/usr/bin/screen /dev/ttyUSB0 9600- For a USB serial connection at 9600 bps or switch out ttyUSB0 for ttyS0 if using a built-in serial port.
NOTE: You will need to be a member of the dialout group to access the serial ports.
- For a USB serial connection at 9600 bps or switch out ttyUSB0 for ttyS0 if using a built-in serial port.
-
- Select other options including input and visual appearance, and click OK twice.
- To open a serial terminal from within Konsole, select File > Serial Terminal (you may need to press Enter to see anything once the window is open)
- To close the serial terminal session, press Ctrl-A Ctrl-\
screen is limited to VT100/ANSI terminal emulation. If you need other types, check into other options such as ckermit.

