Previous Section  < Day Day Up >  Next Section

Recipe 15.2. Using Both X Windows and Consoles

15.2.1 Problem

You want both console sessions and X sessions.

15.2.2 Solution

Yes, Linux user, you can have it all. To switch from an X session to one of the consoles, simply hit Ctrl-Alt-Fn, where Fn is F1-F6. To switch between consoles, hit Alt-Fn. To switch back to X, hit Alt-F7. The first X session is always :0. To open a second X session, do this from a console:

$ startx — :1

Make sure there is a space on either side of the double hyphen. The X session you've just created belongs to the F8 key. Don't log into two X sessions as the same user, as strange and bad conflicts will occur. You can create as many X sessions as you have available consoles and system resources for.

When you start X from a console, all of the debugging messages and background mutterings can be seen on the console. KDE is especially talkative, like it's on a coffee jag. Most of it is not significant, but sometimes it's useful for troubleshooting.

15.2.3 Discussion

Most Linuxes install with seven virtual consoles. Take a look in /etc/inittab:

# Note that on most Debian systems tty7 is used by the X Window System,

# so if you want to add more gettys go ahead, but skip tty7 if you run X.


1:2345:respawn:/sbin/getty 38400 tty1

2:23:respawn:/sbin/getty 38400 tty2

3:23:respawn:/sbin/getty 38400 tty3

4:23:respawn:/sbin/getty 38400 tty4

5:23:respawn:/sbin/getty 38400 tty5

6:23:respawn:/sbin/getty 38400 tty6

The majority of Linux systems bind the default X session to tty7. A notable exception is Knoppix, which uses only five virtual terminals.

What can you do with all of these? Express all of your personalities. Log in as several different users. Log in as yourself many times. Switch to another console to get out of trouble. Gloat about how flexible and versatile Linux is. gettys and ttys

These words, like so much of Linux's terminology, are Unix history lessons. getty means get tty. tty is teletype. That's right, Linux sees your expensive new full-color, high-definition monitor, with built-in sound and FireWire ports, as a teletype—just some old thing to stream output to.

getty manages logins over serial connections. It opens a serial device, such as a text terminal, virtual terminal, or modem, and waits for a connection. It displays the login prompt; then, when you enter your username, hands off to the login program. There are many gettys: mgetty, mingetty, ugetty, agetty, getty-ps, fbgetty, and doubtless more. mingetty is a minimal getty designed only for virtual consoles. It won't talk to modems. mgetty is probably the best modem getty. How do you know which getty your system uses?

$ ps ax | grep getty

  456 tty2     S      0:00 /sbin/getty 38400 tty2

  457 tty3     S      0:00 /sbin/getty 38400 tty3

  458 tty4     S      0:00 /sbin/getty 38400 tty4

  459 tty5     S      0:00 /sbin/getty 38400 tty5

  460 tty6     S      0:00 /sbin/getty 38400 tty6

Why doesn't this show tty1? Because that's the terminal you're logged in on. getty only sticks around waiting for logins; it retires quietly once a login is completed.

This tells us we're running getty itself, and not a link to some other getty:

$ ls -go /sbin/getty

-rwxr-xr-x    1    14264 Sep 19 21:25 /sbin/getty

tty is a program. Go ahead, try it out in a console:

$ tty


Now try it in an X terminal:

$ tty


tty tells you what virtual terminal you are in ("virtual" because in the olden days, they had real terminals that had no processing power of their own—they were merely interfaces to a great and mighty mainframe somewheres).

ttyS* is a serial port. The serial ports are numbered ttyS0 through ttyS04. While we think of a serial port as the physical DB-9 connector, it's also a logical port with an IRQ and I/O address.

tty* names the virtual consoles: tty1, tty2, etc. While most Linux systems ship with 7, theoretically you could have up to 63 virtual consoles.

pts means pseudoterminal. These are X terminals, like xterm, gnome-terminal, wterm, powershell, and Konsole.

Because these are serial interfaces, horrid things like flow control, data flow paths, buffers, and other things that used to be of concern to users are involved. Thankfully, in these modern times, Linux handles all this for us (though these are still completely configurable, for those who wish to do so).

15.2.4 See Also

    Previous Section  < Day Day Up >  Next Section