These classnotes are depreciated. As of 2005, I no longer teach the classes. Notes will remain online for legacy purposes

UNIX01/Switching Between Virtual Consoles

Classnotes | UNIX01 | RecentChanges | Preferences

Let's look back at our standard entries for getty in inittab (mingetty for Red Hat is practically identical):
 1:12345:respawn:/sbin/getty 38400 tty1
 2:2345:respawn:/sbin/getty 38400 tty2
 3:2345:respawn:/sbin/getty 38400 tty3
 4:2345:respawn:/sbin/getty 38400 tty4
 5:2345:respawn:/sbin/getty 38400 tty5
 6:2345:respawn:/sbin/getty 38400 tty6

As you can see, for all of the multi-user modes a getty session begins. This means we have 6 login sessions sitting there waiting for us to connect to. But where are these sessions and how do we access them?

Virtual Consoles

Each of these sessions spawn in what are called "Virtual Consoles". You can switch to each of these virtual consoles and login. As Linux is multi-user, you can be logged in to as many of them as you desire, and be running programs in each. You can additionally switch between them whenever needed.

Additionally, if you are running an X server on your system, there will be an extra seventh virtual console for that. If graphical mode under X is the default means for logging into your computer, then this seventh virtual console will be the default one on your screen. In other words, you will typically have the following virtual console definations on most Linuxes:

 1 : Text console
 2 : Text console
 3 : Text console
 4 : Text console
 5 : Text console
 6 : Text console
 7 : X (GUI) console

You can switch between these virtual consoles by holding down "Ctrl+Alt" and then pressing one of the function keys, F1-F7. So "Ctrl+Alt+F1" will switch to the first virtual console, "Ctrl+Alt+F7" will switch back to your XFree86 console. If you are not running your system with XFree86 (it is headless, or some server which you do not want to waste resources on), then the seventh console may not exist (it may also just be another text console, depending upon how it is set up).

NOTE: This is the default way to switch consoles in most Linuxes and many other UNIXes, though it is by no means universal. On some UNIXes, there are other "META-keys" which perform the same functions as "Ctrl", "Alt", and the function keys do here.

Why would you need something like this? There are many reasons, which will become evident as we proceed through the future courses. But, briefly some reasons are:

  • X has locked up: Although Linux itself is not likely to freeze or lockup, XFree86 running on top of it might. It could be that the graphic card has buggy support, or that some X application has run-away or gone zombie and ground X to a halt. By switching to a text console, you will still be able to log in and kill whatever process is causing the problems.
  • Securely working as root: We have mentionned that running X as the administrator is a dangerous practice (though we'll see why this is in UNIX03). Logging in as root via a text console can be much more secure than logging in as root under X (however, there are dangers even there! Again, we'll examine these in UNIX03).
  • Quick logons: Logging into X can be quite slow (especially if you are using a desktop environment such as Gnome or KDE). If all you are doing is checking something that can be checked from the command-line (as everything under UNIX can be) then it's much quicker to just log into a text console instead of X.
  • Switching runlevels: If you are rebooting, halting, or simply switching runlevels, chances are your X server will have to be killed. By switching runlevels from a text console, you wont be kicked or booted during the init change (meaning any X applications wont be rudely killed during the switch. Big integrated DEs like GNOME or KDE aren't very graceful when they are told to terminate. Killing them may result in a desktop environment that must be reset in order to be used again.)

7 Virtual Terminals not Universal

One final thing we should mention about this is that it is not universally defined that all UNIX or Linux distributions must offer 7 virtual consoles. There are many different UNIXes and Linuxes which define things quite differently.

If in doubt, consult your distribution's documentation and possibly the /etc/inittab file.



Classnotes | UNIX01 | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited August 9, 2003 12:34 am (diff)
Search:
(C) Copyright 2003 Samuel Hart
Creative Commons License
This work is licensed under a Creative Commons License.