WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Suggestion to shrink the initrd: eliminate the need for '/sbin/rungetty'  (Read 4811 times)

Offline maro

  • Hero Member
  • *****
  • Posts: 1228
Due to taking a bit closer interest in the use of serial interfaces I had the opportunity to read through BusyBox sources (e.g. related to 'inittab', and 'getty') and some more (e.g. this article).

As a consequence I'd like to suggest to remove '/sbin/rungetty' from the initrd and replace it with a considerably smaller script (e.g. '/sbin/autologin'):
Code: (bash) [Select]
#!/bin/sh
cat /etc/issue
if [ -f /var/log/autologin ] ; then
    exec login
else
    touch /var/log/autologin
    exec login -f root
fi

This would then require a further change in '/etc/inittab' to replace:
    tty1::respawn:/sbin/rungetty tty1 --autologin root
with:
    tty1::respawn:/sbin/getty -nl /sbin/autologin 38400 tty1

I believe this replicates what 'rungetty' does, i.e. to automatically execute an automated login of user 'root' (which itself continues to execute a login of the default user unless the 'noautologin' boot code was used), and  to run a "standard" login process as soon as this initial session is terminated.

One IMHO minor difference is that the hard coded reference of the respective autologin user (i.e. 'root') needed to be moved from the '/etc/inittab' entry into the script (due to limitation of 'getty' to accept more complex arguments for the '-l' option).

I've done some testing (including for the 'ttyS0' case, where both occurrences of 'tty1' in the 'inittab' entry would have to be replaced with 'ttyS0') but obviously I can't promise that this proposal covers absolutely all possible cases, but I'm sure any limitations would become obvious with more exposure.


EDIT: Simplified the script even further by removing the apparently unnecessary assignments of the standard file descriptors.
« Last Edit: August 24, 2011, 01:31:21 AM by maro »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
I haven't tested it, but it looks very good.
The only barriers that can stop you are the ones you create yourself.

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
maro, Thanks for sharing. I will look to implement.
10+ Years Contributing to Linux Open Source Projects.

Offline maro

  • Hero Member
  • *****
  • Posts: 1228
When I wrote in the OP that I've tested the 'ttyS0' case, I should have been more specific insofar that this involved just an emulated serial interface. I've now managed to set up a proper test with "real" hardware (after creating a null-modem cable with the help of two DE-9 to PS/2 (mouse) adapters).

As it turns out the "real" world is a little bit more fickle: One (rather obvious) lesson learned was that it is quite crucial to use the correct speed parameter from the receiving terminal for the '/etc/inittab' parameter (e.g. '38400 ttyS0'), as well as the boot code (e.g. 'console=ttyS0,38400'). In my case I used as terminal a TC system where I ran (after installation of the 'screen.tcz' extension):
    screen -L /dev/ttyS0 38400

The other (more important) finding was that the "real" hardware did not "like" the assignment of the standard file descriptors. As it appears now those are not required, I had it just taken from some code snippets I've come across and accepted the "storyline" which claimed that it would be required.

I've now updated the OP and of course retested the simplified version of the script (via emulation as well as "real" hardware), and I'd like to think that it now "Just Works" for the 'tty1' as well as the 'ttyS0' case.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
With the assignments removed, would that cause the session to be opened on /dev/console instead of tty1?

If it's still on tty1, ctrl-z (shell job control) will work (and tty should say so).

edit: Tested, and it's not on console.
« Last Edit: August 24, 2011, 02:43:39 AM by curaga »
The only barriers that can stop you are the ones you create yourself.

Offline maro

  • Hero Member
  • *****
  • Posts: 1228
As far as I can tell the session is is not opened on '/dev/console'. At least the output of 'tty' is what one would expect (e.g. '/dev/tty1' or '/dev/ttyS0' respectively). Likewise 'Ctrl-Z' seems to work as well as expected.

EDIT: I only now spotted your addition that you knew that already.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Suggestion to shrink the initrd: eliminate the need for '/sbin/rungetty'
« Reply #6 on: September 07, 2011, 03:14:07 AM »
you will want to apt-get remove gdm, kdm, xdm, wdm
and apt-get install rungetty afterwards open /etc/inittab and modify this line 1:2345:respawn:/sbin/getty 38400 tty1 to
1:2345:respawn:/sbin/rungetty tty1 --autologin $user
...

That kicks so much ass it's not even funny.

Which OS are you talking about?
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Suggestion to shrink the initrd: eliminate the need for '/sbin/rungetty'
« Reply #7 on: September 07, 2011, 10:56:55 AM »
I'd guess a spambot, with a post copied off U forums or similar...
The only barriers that can stop you are the ones you create yourself.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11594
Re: Suggestion to shrink the initrd: eliminate the need for '/sbin/rungetty'
« Reply #8 on: September 07, 2011, 02:56:38 PM »
Post looks bogus, removed.