Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#266900 - 09/10/2005 15:40 Linux auto login?
WirelessOne
new poster

Registered: 24/01/2001
Posts: 30
Loc: Sugar Land, TX, USA
I love my empeg and it has encouraged me to go with an ARM single board computer running a debian linux port for a data acquisition project. I purchased the SBC and built a custom DAQ board. I have developed the software and it all works great.

Now all I have left to do is get the thing to boot up and run my application automatically. I want it to work just like my empeg. In fact, when my application is running you hit "q" to quit and drop back to a shell (sounds familiar?).

So the simple question is: How does the empeg either login automatically or how does it skip login and go straight to a shell?

Thanks,

--Steve

Top
#266901 - 09/10/2005 15:42 Re: Linux auto login? [Re: WirelessOne]
tman
carpal tunnel

Registered: 24/12/2001
Posts: 5528
It uses a custom init and doesn't actually have login or anything like that

Top
#266902 - 09/10/2005 15:45 Re: Linux auto login? [Re: WirelessOne]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31563
Loc: Seattle, WA
The empeg does this because it has a customized Linux kernel, and a tricky architecture that involves storing the kernel in Flash RAM for a fast boot-up. It's a combination of hardware and software that gets the job done.

Your architecture may be different, and therefore might require a different solution. But the empeg's kernel is fully open-source (available right there at www.empeg.com along with the main player firmware downloads), so you're welcome to look at how they accomplish it in their own source code. I've got no idea where to look, of course, but I'm sure some of the kernel gurus here will answer that for you.
_________________________
Tony Fabris

Top
#266903 - 09/10/2005 15:48 Re: Linux auto login? [Re: tfabris]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31563
Loc: Seattle, WA
Oh yeah. And they have a custom init, like Trevor said.

The reason I bring up the kernel is that you said you wanted it to be just like the empeg. I thought it might be that you wanted your project to boot as quickly as the empeg boots. And if you want that, you're going to need to do some of their tricks.
_________________________
Tony Fabris

Top
#266904 - 09/10/2005 15:54 Re: Linux auto login? [Re: tfabris]
WirelessOne
new poster

Registered: 24/01/2001
Posts: 30
Loc: Sugar Land, TX, USA
Wow! You guys are fast. Two replies in less than 5 minutes!

Customized kernel... I was affraid of that. Of course like all things linux I have been scouring the web for answers. Basically I have found two:

1. don't do it like that, instead make it a daemon
2. make a custom kernel that drops straight to a shell

I'm really frustrated by this. It should not be that hard to just auto-login. I understand the security implications, but this is an embedded system like the empeg and simply does not need security.

Anyway thanks for the input, I'll keep looking and I'll have a look at the empeg kernel source and see if I can figure out anythin there...

--Steve

Top
#266905 - 09/10/2005 16:03 Re: Linux auto login? [Re: WirelessOne]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31563
Loc: Seattle, WA
Maybe it's as simple as making a custom init. I dunno enough about it.

Back in the old days before Hijack, we used to auto-run programs on the empeg by altering the init.
_________________________
Tony Fabris

Top
#266906 - 09/10/2005 16:13 Re: Linux auto login? [Re: WirelessOne]
tman
carpal tunnel

Registered: 24/12/2001
Posts: 5528
Ideally you should do it as a daemon and just leave it as a normal login prompt on the console. If you want to do what the empeg does then you'll have to alter the boot up sequence and you can do that by replacing init or fiddling with the startup scripts. You don't need a custom kernel or anything like that.

Top
#266907 - 09/10/2005 16:39 Re: Linux auto login? [Re: tman]
peter
carpal tunnel

Registered: 13/07/2000
Posts: 4172
Loc: Cambridge, England
Quote:
Ideally you should do it as a daemon and just leave it as a normal login prompt on the console. If you want to do what the empeg does then you'll have to alter the boot up sequence and you can do that by replacing init or fiddling with the startup scripts. You don't need a custom kernel or anything like that.

It's true, it's all done with a custom init. The Empeg's init is C and not open-source, but in normal use it just forks, runs the player, waits for it to exit, forks again, runs a shell on console, waits for it to exit, and then back to the beginning again in an endless loop. (There's a bit more to it than that, to do with mounting and unmounting filesystems etc., but that's the bit that does the behaviour you're looking for.)

If you want a Linux box to boot to a root shell on console only, you can just link /sbin/init to /bin/sh -- or even delete /sbin/init, as /bin/sh is one of the things the kernel fails over to if /sbin/init doesn't exist, see the end of init/main.c in a kernel distribution.

If you want a Linux box to boot to a root shell as well as all the normal daemons etc., then you need the normal init process to run, and you can configure it in /etc/inittab to run a root shell on console instead of a getty.

Peter

Top
#266908 - 09/10/2005 16:49 Re: Linux auto login? [Re: WirelessOne]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
You should make it a daemon unless it's something that requires interaction on the console. If it is, then I'd suggest you rethink your concept of console. Get a board with two serial interfaces (assuming the console is serial now) and have it access the non-console serial port. Trying to do it any other way is going to be an exercise in frustration.

That said, you don't really need a customized kernel to make it happen. The default behavior of the Linux kernel is to look for a program called /sbin/init and run that. If that fails, it falls back to /sbin/sh and runs that, and if that fails, it panics (or maybe just stops, but you've not got a viable OS at that point). If you want the OS to do one thing only, you can replace /sbin/init with any program you want to write. You just need to make sure that it doesn't exit, because when it does, that's the end of the OS. (Actually, it might try to start it again -- I forget -- but it's bad form anyway. Then again, we're already talking about bad form, so who cares, right?)
_________________________
Bitt Faulk

Top
#266909 - 09/10/2005 16:51 Re: Linux auto login? [Re: WirelessOne]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
Quote:
how does it skip login and go straight to a shell?

Like I said in my other post, you can make it do this by simply not having an init binary. But if you do that, it's going to start a shell and wait for input, not do anything useful, so that's probably not what you want. That fallback exists so you can potentially repair a badly damaged installation.
_________________________
Bitt Faulk

Top
#266910 - 09/10/2005 18:46 Re: Linux auto login? [Re: peter]
WirelessOne
new poster

Registered: 24/01/2001
Posts: 30
Loc: Sugar Land, TX, USA
Peter,

This sounds like the simplest solution I have found so far. It does not have to be a root shell, it can be some other user. I currently log in a a simple user, but "su" to root to compile so the app is owned by root so that it can access "/dev/mem".

So, my current inittab has the follwoing:

T0:23:respawn:/sbin/getty -L ttyAM0 115200 vt100
T1:23:respawn:/sbin/getty -L ttyAM1 115200 vt100

I have tried the -n option, but it did not help, so I'd like to try this shell on console trick. I'd just go ahead and try it, but I'm affraid if I screw it up, I won't be able to log back in and fix it! Of course I looked at the bash man page after reading your post, but it's about a mile long and has a many options. Can you tell me how to invoke this properly?

Thanks,

--Steve

Top
#266911 - 09/10/2005 19:06 Re: Linux auto login? [Re: wfaulk]
WirelessOne
new poster

Registered: 24/01/2001
Posts: 30
Loc: Sugar Land, TX, USA
wfaulk,

Thanks for the input. I have two com ports, and ethernet. But I really want it to work like the empeg: boot up and go to my application. If I quit my app then drop to a normal shell where I can do all of the normal shell stuff. Then allow me to type "appname" and run my app again.

I realize that this is not quite the normal linux way to do things, but my application is strictly an embedded device run from a battery in a small black box out in the middle of a field. It has no particular secrets on it and does not even have access to the serial or ethernet ports from the outside of the box. In fact the main reason I chose the SBC w/linux was to take advantage of the multi-thread kernel, gcc compiler, and built in support for Compact Flash Cards and a real time clock.

I may eventually convert it to a daemon, but then it will require a network to interract with. Where there is little or no interraction required in normal use, it's still nice to be able to just hook up a serial port and work with it. The second serial port sounds like a great plan, but then I need two serial ports or an A/B switch to interract with my app and the linux command line.

--steve

Top
#266912 - 09/10/2005 19:54 Re: Linux auto login? [Re: WirelessOne]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
Quote:
I may eventually convert it to a daemon, but then it will require a network to interract with.

Daemons have nothing whatsoever inherently to do with networking. It's just a program that gets run outside the context of a login session. Many daemons are network daemons, but certainly not all of them.

If it is just interacting with a serial port, you might be able to replace one of those getty lines in your inittab with a call to your program. It's been a long time since I've dealt with this stuff, so I can't tell you exactly what you need to do, but my point is basically that you're trying to do things that Unix in general allows you to do anyway, but you're trying to circumvent things in a way that's just going to make it harder to deal with.
_________________________
Bitt Faulk

Top
#266913 - 09/10/2005 19:58 Re: Linux auto login? [Re: WirelessOne]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
Quote:
I currently log in a a simple user, but "su" to root to compile so the app is owned by root so that it can access "/dev/mem".

The ownership of an application's binary has nothing to do with what files it can access when it's running. That is determined by the permissions of the user that runs the program. Even if it were true (which it actually is if you set the suid bit on the program's permissions, but I seriously doubt you've done that), you needn't compile as root to set the ownership. The chown program can do that for you.
_________________________
Bitt Faulk

Top
#266914 - 09/10/2005 20:21 Re: Linux auto login? [Re: wfaulk]
WirelessOne
new poster

Registered: 24/01/2001
Posts: 30
Loc: Sugar Land, TX, USA
You must have root privs to access "/dev/mem" (on my SBC anyway). For that reason, I have set the suid bit and then I compile as root in order to make root the owner. You can only chown to root if you are root. It's just as easy to su and compile as root as it is to compile as "user" then su then chown.

And the only reason that I say that the daemon must use ethernet is that in the case of a daemon, it is obviously not proper to interract over STDIN and STDOUT. In this case networking makes more sense.

You seen to feel that I am trying to buck everything linux and do some kind of "wierd thing". Really, I just have an enbedded system with a single use in mind. The application runs just fine when I log in as a regular user and uses the console to interract with the user. Currently you login and type "appname" and it runs, dumping some info to the console as it runs. If you press "q" it quits and drops back to the command line. I just dont think it's that big of a stretch to ask if there is some way to get this embedded box to automatically log in as "user" and not force a person to be available to run the app. I know that in the larger world of linux there is so much hatred and flaming, that it is almost impossible to ask such questions, but I was hoping that here on the empeg bbs where we all have a device that does exactly what I want to do, my question would be welcomed with open arms. Really I am not trying to attack the way linux works or any other negative thing. I just want a simple way to make my program run automatically since it already works so nicely when I first login as a user and then run it. I am reluctant to give up my console access to the application and move it to another serial port or a network port. If I can get this auto-login business to work my development is done, otherwise I still have work to do.

--Steve

Top
#266915 - 09/10/2005 20:54 Re: Linux auto login? [Re: WirelessOne]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
Quote:
in the case of a daemon, it is obviously not proper to interract over STDIN and STDOUT.

Of course it can be. You just have to make sure that stdin and stdout point to the right things. In fact, the network superserver, inetd, presents network communications to the service apps as stdin and stdout. The gettys you're trying to use will present the appropriate things as serial ports.

Quote:
I just dont think it's that big of a stretch to ask if there is some way to get this embedded box to automatically log in as "user"

There is no way to automatically log in. You can circumvent the things that allow you to log in in the first place to grab the console and run your program there, but that will prevent you from being able to drop back to a shell unless you add something else that makes that shell happen. And you can do the same thing on your other serial port without disabling normal access to your console.

Quote:
I am reluctant to give up my console access to the application and move it to another serial port

I'm not really sure what you think you'll be giving up. Do you want to avoid having the ability to run the program and have a console at the same time? Do you think that getting it to run on that other serial port is going to be more difficult than getting it working on the console? Do you think you'd have more console access if it was not on a different serial port? Do you think that you wouldn't be able to access a shell if it was on a different serial port? Do you need to see console spam while running the application? Do you need to be able to do absolutely everything over one serial port?

Quote:
there is so much hatred and flaming

I don't hate you and I'm not flaming you. I'm trying to prevent you from doing something that I think is going to require more work and be more difficult to maintain while also lessening your access to the computer than doing it the "correct" way to begin with.

What I'm getting at is that the difference between the steps to make what you want happen and running it as a daemon on the other serial port are virtually identical with the addition in doing it your way of needing to disable the default console.

Actually, I suppose that's not true. As stated, you can replace the init binary with one you create yourself that will do nothing but run your program and run a shell in a loop. Again, that would disable normal console access completely and you'd have to write additional stuff to make sure that you are the correct user at the correct time. My suggestion means that you'd have to figure out how to configure your second serial port's getty properly to run your program instead of a shell. (Or, as Peter suggested, not use getty at all, but replace it with a call to your program, but, again, that means you wouldn't have any shell access on that serial port without modifying your program to be able to start one itself.)
_________________________
Bitt Faulk

Top
#266916 - 09/10/2005 21:21 Re: Linux auto login? [Re: wfaulk]
WirelessOne
new poster

Registered: 24/01/2001
Posts: 30
Loc: Sugar Land, TX, USA
Quote:
Of course it can be. You just have to make sure that stdin and stdout point to the right things. In fact, the network superserver, inetd, presents network communications to the service apps as stdin and stdout. The gettys you're trying to use will present the appropriate things as serial ports.


Agreed.

Quote:
There is no way to automatically log in. You can circumvent the things that allow you to log in in the first place to grab the console and run your program there, but that will prevent you from being able to drop back to a shell unless you add something else that makes that shell happen. And you can do the same thing on your other serial port without disabling normal access to your console.

I do not want to give up access to the shell and I do not want to have to use one serial port to interract with the shell and another to interract with my application. Further, my application already works and is "complete." So, it is "harder" to switch to another port (even if only trivial effort) than to stay with what I have.
Quote:
Do you want to avoid having the ability to run the program and have a console at the same time?

Not particularly avoid, but I have no need to run the application and have the shell at the same time. My app dumps some status info to the console while running. So the shell needs to be on another port or unavailable to the console while the app is running. Again I refer to the example of the empeg. It is exactly what I want.
Quote:
Do you think that getting it to run on that other serial port is going to be more difficult than getting it working on the console?

No, I just don't want to have to keep swapping my serial cable back and forth.
Quote:
Do you think you'd have more console access if it was not on a different serial port?

no. see above.
Quote:
Do you think that you wouldn't be able to access a shell if it was on a different serial port?

no. see above.
Quote:
Do you need to see console spam while running the application?

Console spam? What's that?
Quote:
I don't hate you and I'm not flaming you. I'm trying to prevent you from doing something that I think is going to require more work and be more difficult to maintain while also lessening your access to the computer than doing it the "correct" way to begin with.

I don't claim that you hate or flame, I state that the linux forums are full of hate and flame and that it is difficult to ask some questions there.

Again, I don't want to do anything strange that is going to require more work. It seems to me that if my system could behave like my empeg it would be great. It seems that this is difficult, so I am exploring other options.

If I understand you correctly, you assert that the correct way to do this is to make my application into a daemon that starts from an /etc/rc#.d script and uses the other serial port for interraction while leaving the "primary" serial port for normal console logins. Is this correct?

--steve

Top
#266917 - 09/10/2005 23:01 Re: Linux auto login? [Re: WirelessOne]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
Quote:
If I understand you correctly, you assert that the correct way to do this is to make my application into a daemon that starts from an /etc/rc#.d script and uses the other serial port for interraction while leaving the "primary" serial port for normal console logins.

Yes, and while I am something of a pedant for "correct"ness, it's your computer and you can do what you want with it. My point is less that it's correct and more that it's actually probably less effort to do it this way and still maintain the ability to administer the computer. What I mean by that is if something goes wrong with your program, the ability to be able to log in elsewhere is probably going to be nice.

Quote:
Console spam?

By that I mean all the stuff that gets spewed to the console, from syslog stuff to the kernel and drivers printing out information. That actually brings up another point. You say you want it to run when there are not users there. That might imply that there's going to be another computer listening to that serial port. If so, all the bootup info might confuse it. Certainly avoiding it would be easier. Then again, you might just want people to be able to see output when they check it.

Quote:
My app dumps some status info to the console while running.

The console is a separate entity from the primary serial device. They happen to share the same hardware in this case, but that doesn't mean that they are inherently related. What I'm getting at is are you redirecting that info to /dev/console or are you just printing it out on stdout? If it's the latter, then I don't think that this is anything to worry about.

It occurs to me that I'm busy telling you what you can't and shouldn't do and less what will work. Again, you can replace init with a program that loops and does what you want, but that means that you lose an actual console. This is the way the empeg works. You can, IIRC, tell getty to use a different program than login, so you could either tell it to use your program and have your program be able to fork a shell in the foreground or you could use a script that calls your program, then the shell (init will restart the getty when it exits, assuming you give it the respawn parameter, so it need not loop itself). You could also do the same thing without getty, but getty does some nice stuff for you, like dealing with the serial port so that your program can just use stdin and stdout. Those are the ways that occur to me immediately. I'd go with the getty option myself. Note that there are a number of versions of getty for Linux. Make sure that you read the correct documentation. (I've lost a few hours wondering why those documented options didn't work before I realized I was using a different getty than the one I was reading documentation for.)

And since the steps for configuring getty are the same regardless of whether you use the console port or the other port, I'd personally go with the other port. In fact, if I were to go with the console port, I'd make sure to configure the other port so that it can accept logins.


Edited by wfaulk (09/10/2005 23:07)
_________________________
Bitt Faulk

Top
#266918 - 10/10/2005 11:21 Re: Linux auto login? [Re: wfaulk]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3582
Loc: Columbus, OH
Out of curiosity, how does KDE or Gnome handle automatic login? I know you can do it.
_________________________
~ John

Top
#266919 - 10/10/2005 11:57 Re: Linux auto login? [Re: JBjorgen]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5680
Loc: London, UK
Quote:
Out of curiosity, how does KDE or Gnome handle automatic login? I know you can do it.


It's called Kiosk mode. In GDM, edit /etc/X11/gdm/gdm.conf and look for the AutomaticLoginEnable and AutomaticLogin settings.
_________________________
-- roger

Top
#266920 - 10/10/2005 12:04 Re: Linux auto login? [Re: JBjorgen]
peter
carpal tunnel

Registered: 13/07/2000
Posts: 4172
Loc: Cambridge, England
Quote:
Out of curiosity, how does KDE or Gnome handle automatic login? I know you can do it.

They use programs run -- as root -- from the inittab: kdm in the case of KDE, and I guess the Gnome one is probably called gdm. This is the program that puts up the graphical "please log in" screen (as opposed to login, which is the program which does the text-mode log-in). As kdm, like init, is running as root, it can skip the password entry if it chooses to and run startkde, or gnome-session or whatever, as any user of its choice, directly.

So I guess Bitt's position is that technically it's not "automatic login", but automatic starting of processes as a particular user without going via a log-in prompt. But that's a mighty fine line IMO: it sure looks like automatic login and quacks like automatic login.

Peter

Top
#266921 - 10/10/2005 13:09 Re: Linux auto login? [Re: peter]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
Well, an X session is a whole different ball of wax from a text login.

The reason I say you can't do it from a text session is that "automatic login" implies that you can log back out and then log in as someone else, and no login program that I'm aware of allows that. No reason you couldn't write one yourself, I suppose, but it seems kinda pointless.
_________________________
Bitt Faulk

Top
#266922 - 10/10/2005 17:37 Re: Linux auto login? [Re: wfaulk]
SonicSnoop
addict

Registered: 29/06/2002
Posts: 531
Loc: Triangle, VA
Doesnt Knoppix also have you auto logged in in X and Console when it boots?
_________________________
-D Modifying and Tweaking is a journey, not a destination................................ MKIIa : 60gig - 040103286 - Blue - v2 + PCATS tuner MKIIa : 20gig - 040103260 - Blue - v3a8 + Mark Lord Special Edition Cherry Dock

Top