1 TITLE: The RedHat-Style Logon Prompt Hint
3 AUTHOR: Chris Baker <chris@aoe.vt.edu>
6 RedHat Linux presents the user with a customized login prompt immediately
7 after booting and whenever you logout. This prompt neatly clears the screen
8 and displays the version of RedHat and the Linux kernel in use just above the
9 login prompt. The following hint describes how to achieve a similar effect
10 with your Linux From Scratch system.
16 ------------------------------
17 Anyone familiar with RedHat Linux has seen its attractive login prompt:
19 RedHat Linux 7.1 (Seawolf)
20 Kernel 2.4.8 on an i686
24 After you terminate your session, the screen clears, and the prompt is again
25 displayed. You'll notice that your new LFS system will instead leave you
26 dangling after you logout:
28 [root@localhost:~]# logout
32 Functional, yes, but polished, no.
34 What's Really Happening?
35 ------------------------------
36 The local login process is really a two-step affair. By default, LFS calls the
37 program /sbin/agetty, which opens a tty port, prompts for a login name, and
38 invokes the /bin/login command. The login executable verifies your password
39 and completes the housekeeping necessary to drop you off in a shell.
41 (By contrast, RedHat uses mingetty, and both agetty and mingetty are
42 descendents of the original getty. I believe it's the differences between
43 mingetty and agetty that allows for the screen to be cleared without a
44 complicated workaround in RedHat Linux, but I'm getting ahead of myself.)
46 In reality, agetty is actually configured from within the /etc/inittab file by
47 a series of six lines similar to
49 1:2345:respawn:/sbin/agetty tty1 9600
51 6:2345:respawn:/sbin/agetty tty6 9600
53 which basically define six "virtual consoles" (on devices tty1 through tty6) to
54 be invoked during runlevels 2-5 (basically everything but halt, single-user,
55 and reboot modes), and set to "respawn" continuously. In other words, while
56 the system is in multi-user mode, whenever a virtual console session
57 terminates, another login is immediately displayed courtesy of agetty.
59 Customizing the Logon Message
60 ------------------------------
61 The first step, integrating a customized message to display before the login
62 prompt, is extremely straightforward. Simply create the file /etc/issue:
64 cat > /etc/issue << "EOF"
65 Linux From Scratch 3.0-rc2
66 Kernel 2.4.8 on an i686
70 Now, after you login and logout again, you'll see the following:
72 Linux From Scratch 3.0-rc2
73 Kernel 2.4.8 on an i686
77 We're halfway there, but we still haven't got the screen clearing before our
78 message is displayed, which means that whatever leftovers are there from our
79 previous session are still visible above the prompt.
82 ------------------------------
83 One way to solve this problem is to create a .bash_logout file in your home
84 directory containing the command "clear". This will clear the screen after you
85 log out, but it won't clear the screen right after the system boots, and you'll
86 have to set one up for each individual user. That's not very elegant.
88 Instead, we'll take advantage of a feature built into agetty for the purpose of
89 initializing modems and other serial devices through which one might connect in
90 addition to the more common tty interface. By adding the "-I <initstring>"
91 option to agetty in the /etc/inittab file, we can pass raw characters to the
94 In order to clear the screen and position the cursor at the upper-left corner,
95 we need to take advantage of two ANSI escape sequences. The first, "ESC[2J",
96 clears the screen, while the second, "ESC[f", positions the cursor. Since the
97 ESC key is a special non-printing character, we have to use alternate means to
98 inject it into the data stream.
100 ESC has an ASCII value of 27, which corresponds to an octal value of 033.
101 According to the man page for agetty, we can pass non-printing characters via
102 the -I option by prepending them with a backslash followed by their octal
103 value, so in this case ESC = \033. (Octal numbers always have a leading zero
104 to differentiate them from decimal numbers.)
106 Putting it all together, we have the sequence '\033[2J\033[f' which will clear
107 the screen and reposition the cursor to the upper-left corner. All that's left
108 to do is to modify /etc/inittab so that the above-mentioned agetty lines now
111 1:2345:respawn:/sbin/agetty -I '\033[2J\033[f' tty1 9600
113 6:2345:respawn:/sbin/agetty -I '\033[2J\033[f' tty6 9600
115 Now all that remains is to bring the new /etc/inittab file into play. To do
116 so, simply issue the command:
120 (Thanks to Randy Hron for pointing this out to me, and to Edward Ellis for
121 suggesting the equivalent command "init q". Luis Miguel Lourenco also wrote
122 to me mentioning "kill -HUP 1" as another way to restart the init process
126 ------------------------------
127 Now you should have a fully-functional, clear screen, custom login prompt. As
128 an aside, check the man page for agetty for some nifty backslash codes that can
129 be inserted into /etc/issue to pull values out automatically. For instance \r
130 will spit out the current kernel revision, and \d inserts the date.
132 I've modified mine to read
134 Linux From Scratch 3.0-rc2
135 Kernel \r on an \m (\l)
139 Linux From Scratch 3.0-rc2
140 Kernel 2.4.8 on an i686 (tty1)
147 ------------------------------
149 Shaun O'Neil has figured out a way to implement the screen clearing codes in the
150 manner I had originally intended--by including them in /etc/issue, instead of
151 passing them via agetty as configured in /etc/inittab. I had originally tried
152 putting the sequence "\033[2J\033[f" at the beginning of /etc/issue, however, I
153 quickly learned that it was just printed verbatim.
155 Instead, Shaun used vim to insert the escape character thusly: while editing the
156 /etc/issue file in vim, use the sequence CTRL-V CTRL-ESC to insert a literal
157 escape character. Follow this with [2J and repeat for the second code. (Note
158 that the escape character will print as "^[" on the screen, and you must put in
159 the left bracket again after it. In other words, the final sequence will
164 on the screen in vim. Put this sequence before your logon message, and you're
167 Once you've modified /etc/issue in this manner, there is no need to pass codes
168 to the terminal through agetty, so there is no need to edit /etc/inittab at all
169 as detailed in this hint. Shaun's proves to be a much cleaner and easier method!