Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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).
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
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!
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.....)
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.
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
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.
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.
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
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.
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?!
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.