Linux, Unix, /etc/

$ To set up this Linux system, do I really have to type long, cryptic, frequently inconsistent and undocumented commands with occasional long strings of hex digits?

# Yeah. You got a problem with that?

Sponsored links (requires javascript):

Multi-User Linux: Supporting Terminals on a Linux Box

intro

This article is about supporting multiple users on a Linux box by attaching terminals. While this approach to multi-user computing has been somewhat overshadowed in recent years by the client-sever model, in which each user has their own computer which avails of network services from its peers and/or a central server, the central host / dumb terminal scheme has certain advantages, not least among them being lower cost and easier maintanance. This article examines how to set up such a system using Linux as the central host OS. Terminals are not just of use to companies with large numbers of staff. One of the disadvantages of the home computer is that it really needs a room of its own, or at least a room with a considerable portion of space given over to it and its paraphernalia. This is clearly not an ideal way of using the machine: one would not think of going to a special room to read a magazine, so why do so when you wish to read through articles on a web site? Linux's inherent multi-user capabilities and its support for terminals offers an answer.

Server

Let's start by listing what we need on the server.

hardware

The hardware is simple: we need a least one serial port.

serial ports

The standard PC comes with two serial ports. If all you want is two terminals, then this is fine. For most uses, though, you'll need more. Many multi-port serial cards are supported by Linux. For some, such as the AST Fourport and clones, support comes as an optional compile-time feature to the standard kernel; for others, the manufacturer may provide a driver, perhaps as a kernel module or as a patch to the standard source tree..

software

Configuring the serial ports
The extra serial ports must have corresponding devices created in /dev, and these must be configured using the setserial program. The devices may already exist; if not, creating them is simple. The mknod command is used (look up the man page!) e.g.

mknod -m 666 /dev/ttyS4 c 4 68

Where c says it is a character special device (the alternative is b for block, e.g. a disk), and the two numbers following the device file name are the major and minor numbers respectively. For serial input, the major number is 4; for serial output, 5. The minor number is the port number plus 64 (you ask why? I don't know!) The -m option, as you've probably guessed from the look of it, sets ther permissions on the file. The following devices exist on my system. Note the major and minor numbers. /dev/ttyS4-7 and /dev/cua4-7 are the control devices for my additional serial lines.
Input

crw—w--w-   1 root     root       4,  64 Sep 24 19:44 /dev/ttyS0
crw—w--w-   1 root     root       4,  65 Sep 20 19:42 /dev/ttyS1
crw-rw-rw-   1 root     root       4,  66 Jan 23  1980 /dev/ttyS2
crw-rw-rw-   1 root     root       4,  67 Sep 24 19:36 /dev/ttyS3
crw-rw-rw-   1 root     other      4,  68 Nov 17 16:53 /dev/ttyS4
crw-rw-rw-   1 root     other      4,  69 Nov 17 16:56 /dev/ttyS5
crw-rw-rw-   1 root     other      4,  70 Nov 17 16:56 /dev/ttyS6
crw-rw-rw-   1 root     other      4,  71 Nov 17 16:56 /dev/ttyS7

Output

crw-rw-rw-   1 root     tty        5,  64 Apr  1  1993 /dev/cua0
crw-rw-rw-   2 uucp     staff      5,  65 Oct  7 21:42 /dev/cua1
crw-rw-rw-   1 root     tty        5,  66 Apr 11  1993 /dev/cua2
crw-rw-rw-   1 paul     staff      5,  67 Nov 21 09:16 /dev/cua3
crw-rw-rw-   1 root     tty        5,  68 Sep 20 13:11 /dev/cua4
crw-r—r--   1 root     root       5,  69 Sep 20 13:12 /dev/cua5
crw-r—r--   1 root     root       5,  70 Sep 20 13:12 /dev/cua6
crw-r—r--   1 root     root       5,  71 Sep 20 13:12 /dev/cua7

Setserial
The setserial program is essential to configure the additional serial ports. The README file that comes with the source says it all, really: "[setserial] allows you to look at and change various attributes of a serial device, including its port, its IRQ, and other serial port options." It comes with an rc.serial script which with a little tuning will do everything you need. In /etc/rc.local, I have the following lines:

if [ -f /etc/rc.serial ]; then
		/etc/rc.serial
	fi

init config

/etc/inittab

# Serial lines
s4:2345:respawn:/sbin/uugetty ttyS4 9600
s2:45:respawn:/sbin/agetty 19200 ttyS1 vt100

# Dialup lines
d1:45:respawn:/sbin/agetty -mt60 38400,19200,9600,2400,1200 ttyS0 vt100
d2:45:respawn:/sbin/agetty -mt60 38400,19200,9600,2400,1200 ttyS1 vt100

How Linux talks to terminals: getty
A standalone Linux box already supports multiple terminals, due to the virtual console support built into the kernel. Each of the screens accessible on the console monitor through an Alt-Fkey combination is treated as a separate terminal. This can be illustrated by a ps listing, which should show some lines like this:

5831 p 5 S     0:00 /sbin/agetty 38400 tty5

Support for real terminals starts along similar lines. First, it is necessary to tell the system to run a getty process on each port to which a terminal will be attached. The ports would normally be serial lines. A normal PC has only two of these, but there are cheap multi-port serial cards available, which provide 4, 8, 16 or even more additional serial lines, while taking up only one interrupt (and an expansion slot on the motherboard, of course). I use a cheap clone of the AST Fourport card, which as the name implies gives me four extra serial ports.
Why agetty?
You will notice that I am referring to agetty(8), rather than the standard getty(8). Both are available in a standard Linux install, and agetty has several features and is simpler to configure. Just like the standard getty, agetty opens a tty port, prompts for a login name and invokes the /bin/login command. In addition, agetty has several useful non-standard features. These include: Adapting the tty settings to parity bits and to erase, kill, end-of-line and uppercase characters when it reads a login name. Agetty can handle 7-bit characters with even, odd, none or space par­ ity, and 8-bit characters with no parity. The fol­ lowing special characters are recognized: @ and Control-U (kill); #, DEL and back space (erase); carriage return and line feed (end of line). Optionally deduces the baud rate from the CONNECT messages produced by Hayes(tm)-compatible modems. Optionally does not hang up when it is given an already opened line (useful for call-back applica­ tions). Optionally turns on hard-ware flow control Optionally forces the line to be local with no need for carrier detect. Note that agetty does <EM>not</EM> use the /etc/gettydefs or /etc/gettytab files. agetty is usually called by init(8). Here are some sample command entries for the /etc/inittab file. 1) For a hard-wired line or a console tty: /sbin/agetty 9600 ttyS1 2) For a directly connected terminal without proper carriage detect wiring: (try this if your terminal just sleeps instead of giving you a password: prompt.) /sbin/agetty -L 9600 ttyS1 vt100 One handy feature of agetty is its support for escape codes in the /etc/issue file. These are: For example, my /etc/issue reads

Running \s \r	It is now \t	\U logged on

which displays

Running Linux 2.0.36	It is now 15:23:13	1 user logged on

Depending on how the program was configured, all diagnos­ tics are written to the console device or reported via the syslog(3) facility. Error messages are produced if the port argument does not specify a terminal device; if there is no utmp entry for the current process (System V only); and so on.

Terminal

Most standard serial terminals will work under Linux. If in doubt, consult the manufacturer.

The Connection

The cabling needed for a basic serial connection to a terminal is very simple. Just three wires must be connected, as follows:

RxD   Receive Data          2 - 3       TxD   Transmit Data
	TxD   Transmit Data         3 - 2       RxD   Receive Data
	GND   Signal Ground         7 - 7       GND   Signal Ground

This will work, but allows for no hardware handshaking. I once had a small set of old Wyse 30s hocked up to my machine, and this basic cabling worked fine with them. Your terminals may also supported advanced features through additional lines on the serial cable. A full null-modem configuration is as follows:

DCD   Carrier Detect        1 - 20      DTR   Data Terminal Ready
	RxD   Receive Data          2 - 2       TxD   Transmit Data
	TxD   Transmit Data         3 - 3       RxD   Receive Data
	DTR   Data Terminal Ready   4 - 6       DSR   Data Set Ready
	DTR   Data Terminal Ready   4 - 8       DCD   Carrier Detect
	GND   Signal Ground         5 - 7       GND   Signal Ground
	DSR   Data Set Ready        6 - 20      DTR   Data Terminal Ready
	RTS   Request To Send       7 - 5       CTS   Clear To Send
	CTS   Clear To Send         8 - 4       RTS   Request To Send

If you want to have hardware handshaking signals, you must have a full null modem cable:

PC male DB25                            Terminal DB25
          TxD   Transmit Data         2 —> 3     RxD   Receive Data
          RxD   Receive Data          3 <— 2     TxD   Transmit Data
          RTS   Request To Send       4 —> 5     CTS   Clear To Send
          CTS   Clear To Send         5 <— 4     RTS   Request To Send
          DSR   Data Set Ready        6
                                      |
          DCD   Carrier Detect        8 <— 20    DTR   Data Terminal Ready
          SG    Signal Ground         7 -— 7     SG    Signal Ground
                                            6     DSR   Data Set Ready
                                            |
          DTR   Data Terminal Ready  20 —> 8     DCD   Carrier Detect

If you have a DB9 connector on your serial port, try the following:

PC DB9                                  Terminal DB25
          RxD   Receive Data          2 <— 2     TxD   Transmit Data
          TxD   Transmit Data         3 —> 3     RxD   Receive Data
          SG    Signal Ground         5 -— 7     SG    Signal Ground

Alternatively, a full DB9-DB25 null modem cable:

PC DB9                                  Terminal DB25
          RxD   Receive Data          2 <— 2     TxD   Transmit Data
          TxD   Transmit Data         3 —> 3     RxD   Receive Data
                                            6     DSR   Data Set Ready
                                            |
          DTR   Data Terminal Ready   4 —> 8     DCD   Carrier Detect
          GND   Signal Ground         5 -— 7     GND   Signal Ground
          DCD   Carrier Detect        1
                                      |
          DSR   Data Set Ready        6 <— 20    DTR   Data Terminal Ready
          RTS   Request To Send       7 —> 5     CTS   Clear To Send
          CTS   Clear To Send         8 <— 4     RTS   Request To Send
          (RI   Ring Indicator        9 not needed)

(Yes, the pins 2 and 3 really do have the opposite meanings in DB9 connectors than in DB25 connectors!) As my terminals could be configured to use no handshaking, as I was fixing up my own cables with their appropriate connectors, and as I hate soldering, I took the former route! It works just fine.

Configuring agetty

Edit your /etc/inittab file to run agetty on the serial port (substituting in the correct information for your environment - port, speed, and default terminal type):

s2:45:respawn:/sbin/agetty 19200 ttyS1 vt100

Restart your system. That's it!

Conclusion

So, at the end of it all, we have a cheap and simple way to set up a multi-user system. I think that any REAL operating system has to offer this capability (multi-user support just "slots in" on top of multi-tasking, after all). Certainly, it has made my use of my Linux box much more productive, by allowing me access to it from several different locations in my house.

Paul Dunne 2000


main | scripts | contact | links

Sponsored links (requires javascript):