redhat-style_logon.txt

Chris Baker chris at aoe.vt.edu
Tue Sep 11 07:13:40 PDT 2001


TITLE:		The RedHat-Style Logon Prompt Hint
LFS VERSION:	All
AUTHOR:		Chris Baker <chris at aoe.vt.edu>

SYNOPSIS:
	RedHat Linux presents the user with a customized login prompt immediately
after booting and whenever you logout.  This prompt neatly clears the screen
and displays the version of RedHat and the Linux kernel in use just above
the
login prompt.  The following hint describes how to achieve a similar effect
with your Linux From Scratch system.

HINT:


Background
------------------------------
Anyone familiar with RedHat Linux has seen its attractive login prompt:

	RedHat Linux 7.1 (Seawolf)
	Kernel 2.4.8 on an i686

	localhost login:

After you terminate your session, the screen clears, and the prompt is again
displayed.  You'll notice that your new LFS system will instead leave you
dangling after you logout:

	[root at localhost:~]# logout

	localhost login:

Functional, yes, but polished, no.

What's Really Happening?
------------------------------
The local login process is really a two-step affair.  By default, LFS calls
the
program /sbin/agetty, which opens a tty port, prompts for a login name, and
invokes the /bin/login command.  The login executable verifies your password
and completes the housekeeping necessary to drop you off in a shell.

(By contrast, RedHat uses mingetty, and both agetty and mingetty are
descendents of the original getty.  I believe it's the differences between
mingetty and agetty that allows for the screen to be cleared without a
complicated workaround in RedHat Linux, but I'm getting ahead of myself.)

In reality, agetty is actually called from within the /etc/inittab file by a
series of six lines similar to

	1:2345:respawn:/sbin/agetty tty1 9600
	...
	6:2345:respawn:/sbin/agetty tty6 9600

which basically define six "virtual consoles" (on devices tty1 through tty6)
to
be invoked during runlevels 2-5 (basically everything but halt, single-user,
and reboot modes), and set to "respawn" continuously.  In other words, while
the system is in multi-user mode, whenever a virtual console session
terminates, another login is immediately displayed courtesy of agetty.

Customizing the Logon Message
------------------------------
The first step, integrating a customized message to display before the login
prompt, is extremely straightforward.  Simply create the file /etc/issue:

	cat > /etc/issue << "EOF"
	Linux From Scratch 3.0-rc2
	Kernel 2.4.8 on an i686

	EOF

Now, after you login and logout again, you'll see the following:

	Linux From Scratch 3.0-rc2
	Kernel 2.4.8 on an i686

	localhost login:

We're halfway there, but we still haven't got the screen clearing before our
message is displayed, which means that whatever leftovers are there from our
previous session are still visible above the prompt.

Clearing the Screen
------------------------------
One way to solve this problem is to create a .bash_logout file in your home
directory containing the command "clear".  This will clear the screen after
you
log out, but it won't clear the screen right after the system boots, and
you'll
have to set one up for each individual user.  That's not very elegant.

Instead, we'll take advantage of a feature built into agetty for the purpose
of
initializing modems and other serial devices through which one might connect
in
addition to the more common tty interface.  By adding the "-I <initstring>"
option to agetty in the /etc/inittab file, we can pass raw characters to the
tty interface.

In order to clear the screen and position the cursor at the upper-left
corner,
we need to take advantage of two ANSI escape sequences.  The first,
"ESC[2J",
clears the screen, while the second, "ESC[f", positions the cursor.  Since
the
ESC key is a special non-printing character, we have to use alternate means
to
inject it into the data stream.

ESC has an ASCII value of 27, which corresponds to an octal value of 033.
According to the man page for agetty, we can pass non-printing characters
via
the -I option by prepending them with a backslash followed by their octal
value, so in this case ESC = \033.  (Octal numbers always have a leading
zero
to differentiate them from decimal numbers.)

Putting it all together, we have the sequence '\033[2J\033[f' which will
clear
the screen and reposition the cursor to the upper-left corner.  All that's
left
to do is to modify /etc/inittab so that the above-mentioned agetty lines now
read like so:

	1:2345:respawn:/sbin/agetty -I '\033[2J\033[f' tty1 9600
	...
	6:2345:respawn:/sbin/agetty -I '\033[2J\033[f' tty6 9600

There's probably some way to make it effective without rebooting, but a
reboot's the simplest method I know of to bring the new /etc/inittab file
into
play.

Conclusion
------------------------------
Now you should have a fully-functional, clear screen, custom login prompt.
As
an aside, check the man page for agetty for some nifty backslash codes that
can
be inserted into /etc/issue to pull values out automatically.  For instance
\r
will spit out the current kernel revision, and \d inserts the date.

I've modified mine to read

	Linux From Scratch 3.0-rc2
	Kernel \r on an \m (\l)

which expands to

	Linux From Scratch 3.0-rc2
	Kernel 2.4.8 on an i686 (tty1)

	localhost login:

Good luck!




More information about the hints mailing list