LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-15-2008, 02:38 PM   #1
Eilya
Member
 
Registered: Aug 2008
Posts: 52

Rep: Reputation: 15
Question CuSTomIzE Linux


Hi dear friends,

I want to customize my linux and finally having a linux which starts from kernel next init and finally running an application (like w3m) so I want to omit shell and any other application or interfaces, please guide me.

Best regards,
Eilya
 
Old 09-15-2008, 06:48 PM   #2
sci
LQ Newbie
 
Registered: Jul 2007
Location: new zealand
Distribution: slackware
Posts: 13

Rep: Reputation: 0
Hi Eilya. It all depends on how much work you want to put into trimming off the stuff you won't need for your one-application system. It's very easy to get a typical Linux setup to auto-run an application, but if you're wanting to remove all the stuff a normal install would have that your application doesn't require, this could involve a LOT of work...especially if, as you say, you really want to lose even the shell (!) and have the kernel manage your application's resources directly, without even running the init scripts (which require the shell) that normally set up your terminals and mount stuff and launch vital services and so on. You'd have to know your application intimately (i.e. understand every system resource it needed) and in the end you probably really would be customising "Linux", in the sense that you'd have to modify the kernel code, along with perhaps a bunch of other code as well. Seems like a heck of a lot of work (months, even) just to save yourself a few seconds of boot time and a few system resources (RAM etc.).

Why not just take a minimal install of a light, clean system (like Slackware, for example) and comment all the unwanted services out of the boot scripts, and then have them finish up by launching your chosen application? Slackware's startup is very fast--less than ten seconds on a modern system once you've tidied up the boot scripts--and is not at all resource-hungry. Unless you're doing something really weird like installing to an unusual device (or maybe a really ancient computer), I don't see what you'd gain by getting rid of the shell and so on (or at least, I don't see how anything you'd gain from that would be worth the effort of achieving it).
 
Old 09-16-2008, 09:23 AM   #3
Eilya
Member
 
Registered: Aug 2008
Posts: 52

Original Poster
Rep: Reputation: 15
Question

Thanks dear sci, but it is somehow vital for me to omit shell, other things are not so important to me. just I want to omit shell and after that how to configure to have w3m as a running application. It is so important to me
please help me,
Thanks,
Eilya
 
Old 09-17-2008, 03:25 AM   #4
sci
LQ Newbie
 
Registered: Jul 2007
Location: new zealand
Distribution: slackware
Posts: 13

Rep: Reputation: 0
Sorry, the suggestions I made before are all the help I can offer. "Somehow vital" doesn't really explain why it's so important to ditch the shell (is it a security issue or something?), but if you really do want to go this way, I think you may have a long road ahead of you. I wouldn't even know where to start: every Linux system I've ever used has immediately (after booting) used the shell to parse boot scripts, launch processes, set up the environment, etc.

If the kernel and a major console application like w3m can already play together happily with no shell, then perhaps someone (not me, unfortunately) will be able to walk you through the steps to achieve this (i.e. how to get init to launch w3m, how to get your system to shut down when you quit w3m, and so on). On the other hand, if you need to augment the code in the kernel and/or w3m to make it work, then that could be a huge job: you may have to study the code and figure it out for yourself. My advice is still to take the easier path and just have the shell launch w3m when you boot up: I don't see what's so bad about having /bin/bash (or dash or ash or whatever) running in the background. But whatever you decide to do, good luck!
 
Old 09-17-2008, 04:49 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
ditto the comment about how the difficulty of deleting the shell might outweigh the benefit. How much of any given resource does the shell use?

Intellectually, I'm curious: When booting, "init" is the first program called, but--as stated--it is using shell commands in the various scripts that get run. So when does the shell get started? Or does it? Yes---ps -e shows bash running (PID 9976 here), but shows init with a PID of 1. The implication is that there is a whole lot of stuff that goes on before the init scripts can run.

I would start with the source code for the kernel--and for init. (And a VERY large pot of coffee.....)
 
Old 09-17-2008, 03:28 PM   #6
Eilya
Member
 
Registered: Aug 2008
Posts: 52

Original Poster
Rep: Reputation: 15
Thanks dear friends, so I should have a look in the source code (of Kernel), if you have any more information please guide me

Regards,
Eilya
 
Old 09-17-2008, 03:40 PM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
I don't think you can do what you want, e.g. "init=/bin/w3m", because doing so, your partitions won't be mounted and your network interface won't work so w3m will be worthless. I think that you could have w3m run in a certain virtual terminal by including it in your /etc/inittab file but you still want the startup services to run. If you include what you need in the initrd file, you could have it operate similar to a live distro, including w3m at the end of the boot script. I don't see how this is would very useful or possibly urgent.
 
Old 09-17-2008, 08:21 PM   #8
Eilya
Member
 
Registered: Aug 2008
Posts: 52

Original Poster
Rep: Reputation: 15
guide me

Dear Jschiwal, as I mentioned in the first post, it is not important which application to run, just I want run an application by this trend: Kernel->init->application and in this trend which is important is just omitting the Shell (or other interfaces like Gnome or ...) so I want to know how I can make this trend by any application which is possible

Waiting for your Answer
Eilya
 
Old 09-17-2008, 09:43 PM   #9
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I think we're back to the comment about studying the source code---for the kernel and for init. My hunch is that this is going to take you a very long time.

If you can explain why you don't want to run the shell, someone might have a better/easier solution.
 
Old 09-17-2008, 10:52 PM   #10
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
As someone said above, if you wanted to explain us what your goal is (at a practical level) maybe someone will be able to give you a better solution.

The only non-insane way to do what you say (if you really mean what you say, which I am not completely sure about) is to substitute your init process by your own init system, which will need to be completely made on C or a similar language (since most init systems really depend on a shell at one or another point). Saying "non-insane" is very euphemistic on my side, by the way. You will need to integrate your own hooks around udev and the basic system and network services, since you are not going to rely on an external shell nor in conventional scripts to do these tasks. You will definitely need massive work to make such a thing work. Even the closest examples that I can think of requires at least a posix compliant shell to run, because, regardless of the init system, the init scripts will use shell calls at any given time during boot, to do many tasks.

Now, if all you want is to allow the user only to use w3m once s/he login, you can just simplify the thing, and assign w3m as the shell for that given user. You can do so with many admin tools, but the simplest way is to just edit the entry for the user in /etc/passwd, and change /bin/bash (or whatever) by /usr/bin/w3m (or whatever). How this will work: I don't know, never did such a thing. I don't know either if w3m allows the execution of external code or launching an external shell, in which case you will need to patch it to cut down some functionalities. If w3m is the shell, exiting it should just get the user back to the login prompt.

Last edited by i92guboj; 09-17-2008 at 10:55 PM.
 
Old 09-17-2008, 11:15 PM   #11
Eilya
Member
 
Registered: Aug 2008
Posts: 52

Original Poster
Rep: Reputation: 15
Dear friends, It is just for knowing more, and I want to do as simple as possible, I want even passing this trend (without shell) and finally write "Hello World"; so I want to know more about this.
Thanks a lot,
Eilya
 
Old 09-18-2008, 04:41 PM   #12
sci
LQ Newbie
 
Registered: Jul 2007
Location: new zealand
Distribution: slackware
Posts: 13

Rep: Reputation: 0
OK Eilya, if "Hello World!" is all you want, I have a solution for you: create the following file (e.g. via "vi test.c"):

#include <stdio.h>
main () {
printf("Hello World!"\n);
}

...and then compile it via "gcc test.c". The resulting program (a.out) is your "Hello World!" application.

I had a quick look at the kernel source code, and see that the first thing it does after booting is launch /sbin/init. You can jump in before init does anything else--including running the boot (shell) scripts--by simply copying over /sbin/init with your application (in this case, a.out). For God's sake make sure you have a rescue CD or something so you can restore the original /sbin/init, otherwise you will be trashing your system!

I've tested it, and sure enough, "Hello World!" is the very first thing you get...right after the Tux logo...and right before the kernel panic and catastrophic death of your system. Heh. But, it shows how easy it is to shove something into the start of the boot process. If you examined the source code for /sbin/init, you could presumably modify things more tidily, although I imagine it would still involve a huge amount of work if you actually wanted anything useful as a result. It still seems much, much easier just to allow the normal boot process to complete and then launch an application as per usual.
 
Old 09-18-2008, 05:12 PM   #13
sci
LQ Newbie
 
Registered: Jul 2007
Location: new zealand
Distribution: slackware
Posts: 13

Rep: Reputation: 0
Whoops...I just remembered that my Tux logo is not the one that ships with the kernel...it's an image I stuck there via the bootsplash patch (and splash=quiet, to suppress the normal boot messages). So in fact you're more likely to see a bunch of kernel messages whizzing up your screen as usual (rather than just the serene Tux): it's at the point where you'd normally see init kick in with its own messages (presumably announcing its own launch, to start with) that you'll see "Hello World!" instead.

This is still what I'd call the "start" of the boot process in terms of where you can (if you're insane) shove in your own application. I suppose you could go through the earlier kernel code (i.e. the stuff that initialises hardware) and try to find an even earlier point at which your application could run (bearing in mind that we're talking about launching a program here, not just inserting the "Hello World!" code into the kernel code, which is obviously possible with this simplistic example) but, again...WHY?!

 
Old 09-18-2008, 05:21 PM   #14
Eilya
Member
 
Registered: Aug 2008
Posts: 52

Original Poster
Rep: Reputation: 15
Lightbulb chkconfig????????????

Thanks a lot Sci, I have just one more question,
As I know after Kernel and in the init process, system continues in /etc/inittab and it defines how to initialize the system(the inittab configuration file defines several entries with a common format: id:runlevels:actionrocess), after that its initdefault turn to specify the runlevel, after that we should have a look at (for example: ) /etc/rc2.d for the processes which are running in this runlevel (runlevel 2). by the way we know chkconfig ($chkconfig --list) let us to see the runlevel of services and change their runlevel.
In conclusion, I want to know can we use inittab for initialize the processes and after that by chkconfig change the services runlevel, and finally by initdefault changing the runlevel of system, and in this stage we can include our application (for example: a.out) in the list of running applications in runlevel 2????????????
please correct me if I made false?? and if not, please show me the practical way

waiting for your guides,
Eilya

Last edited by Eilya; 09-18-2008 at 06:50 PM.
 
Old 09-18-2008, 06:36 PM   #15
launcelot
LQ Newbie
 
Registered: Sep 2008
Posts: 4

Rep: Reputation: 0
IIRC, getty launches the login program which displays a login prompt and answers to a correct login/password sequence by executing the shell mentioned as the user's default shell in /etc/passwd. So, the sequence here is kernel->init->getty->login->user's shell.

This is not however the context in which the various runlevel scripts are run at startup. As far as I can say, the latter happens not on a virtual terminal but on the real one, even before getty initializes the login sequences. So, the above does not answer your question completely. There has got to be at least one more earlier shell launched by init, because the rc scripts are executed before the ttys invade the terminal.

I'm pretty sure the very first shell is not started as part of the scripts linked by the rc directories. They themselves are shell scripts, so there would be a chicken and egg problem. Possibly, init executes them in a non-interactive shell that starts running on the non-virtual terminal before the gettys themselves. I guess this (hypothetical) non-interctive shell continues running until the start of the shutdown or reboot sequence (I myself get a mysql shutdown message when my system enters either of these runlevels; most probably, this means that the X and getty1-6 processes have been killed at this stage, but that the shell which started mysqld_safe is still active).

Presumably, you would see the evry first shell being launched in the source code of the init program. This is however nothing but personal speculation.

Edit: you erased your questions while i was writing the above answer.

Last edited by launcelot; 09-18-2008 at 06:38 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Customize linux boot sequence Pavan Goyal Linux - Embedded & Single-board computer 6 07-15-2008 05:46 AM
customize linux johnynixon LinuxQuestions.org Member Intro 1 01-10-2008 02:18 PM
Who Customize Linux for an Embedded System usage? Rajaee Linux - Software 0 08-18-2003 03:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration