Chris Baker chris at
Tue Sep 11 07:13:40 PDT 2001

TITLE:		The RedHat-Style Logon Prompt Hint
AUTHOR:		Chris Baker <chris at>

	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
login prompt.  The following hint describes how to achieve a similar effect
with your Linux From Scratch system.


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
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)
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


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
log out, but it won't clear the screen right after the system boots, and
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
initializing modems and other serial devices through which one might connect
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
we need to take advantage of two ANSI escape sequences.  The first,
clears the screen, while the second, "ESC[f", positions the cursor.  Since
ESC key is a special non-printing character, we have to use alternate means
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
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
to differentiate them from decimal numbers.)

Putting it all together, we have the sequence '\033[2J\033[f' which will
the screen and reposition the cursor to the upper-left corner.  All that's
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

Now you should have a fully-functional, clear screen, custom login prompt.
an aside, check the man page for agetty for some nifty backslash codes that
be inserted into /etc/issue to pull values out automatically.  For instance
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