TTY – Access Higher TTYs and the Role of Getty

gettytty

I have a few dark areas when trying to understands TTYs.

  • On my system, I have /dev/tty[1-63]. Is udev creating these character devices? And how can I access them (like tty2 can be accessed with Ctrl+Alt+F2)? How can I access /dev/tty40 for example?

  • As I understand, when I access /dev/tty1, agetty is called, which then calls login. What really is the role of agetty outside of calling login?

Best Answer

These are virtual consoles, known in Linux as virtual terminals (VT). There is a single hardware console (a single screen and a single keyboard), but Linux pretends that there are multiple ones (as many as 63). At a given point in time, a single VT is active; keyboard input is routed to that console and the screen shows what that console displays.

You can use the command chvt to switch between VT (you need to have direct access to the current virtual console, which you won't have if logged remotely or running under X). You can also use keybindings set with the keymap loaded by loadkeys or by the X server. By default, outside X, Alt+Fn switches to console number n and Alt+Shift+Fn switches to console number n+12; Alt+Left and Alt+Right switch to the previous/next console.

A console needs to be allocated in order to switch to it. You can use openvt to allocate a console (this requires root) and deallocvt to deallocate one.

The program getty is not directly related to virtual consoles, in particular it has nothing to do with VT allocation. The role of getty is to prepare the console (set up serial port parameters, possibly blank the screen, display a welcome message, etc.) and call login, then wait for the login session to terminate and repeat. In a nutshell, the role of getty is to call login in a loop.

You don't have to run getty to use a console. For example, you can start any program on a console with openvt. You can start an X server on a new console with startx.

Related Question