Monday, October 13, 2008

Linux Startup Research

As expected, Linux boot generally just a whole bunch of scripts. The core script is:

/etc/inittab

Though unless you're feeling extra awesome, you'll never need to touch this file.

This file include a series of scripts found under:

/etc/rc.d/

"inittab" uses the file "rc.S" as the so called "system initialization". I'm pretty sure this is still more low level than I'd ever care to know.

Next, it implements runlevels by executing a script simply called "rc" with a numeric argument. Runlevels are the Linux equivalent of booting in to DOS mode, back from the Windows 95 days. Runlevel 1 is a single user "administrative" mode. There's a few more, but the other important one is Runlevel 5, Multiuser+Networking+GUI mode. In other words, a normal Linux boot.

Inside the "inittab" file, it seems the "rc" script was overloaded (i.e. copied and renamed). "rc.5" is used alternatively to execute argument 5 (i.e. "rc.5 5" instead of "rc 5").

"rc.5" is heavily modified. Many lines are commented out, so it looks as if it's already been well tuned here.

Services scripts live in:

/etc/rc.d/init.d/

There's also a symlink here setup at "/etc/init.d/".

These scripts are just the files that'll be run. What's important is then this.

/etc/rc.d/rc5.d/

A folder full of symlinks to the various scripts found in "init.d", for our preferred runlevel (5).

Every symlink in this folder has a 3 character identity. S or K (for Start or Kill) followed by a numeric priority (01 before 10).

The OS actually calls all Kills first, then all the Starts.

What each actually does is it calls the linked script files with "stop" and "start" as the first argument respectfully. Pretty straight forward. And if I'm reading correctly, system shutdown will be the opposite (previously killed apps get started, and vice versa).

So technically, changing this involves manipulating the symlinks in the folder. Rather that battle with that tediousness, there's an application "/sbin/chkconfig" that can be used to simplify the task.

chkconfig --list

gives you a printout of what I'm guessing is a compare between the contents of "init.d" and the "rc5.d" and related folders. Use:

chkconfig --add ServiceName

to create a symlink for a service, and:

chkconfig --del ServiceName

to remove a symlink for a service.

Next, the application "/sbin/service" can be used to say what current services are running.

service --status-all

gives you a similar list likely a comparison of the contents of "init.d".


Long ass article later (awesome article I must say, I've learned a crap ton), it seems the secret to making Linux boot parallel is none other than GNU MAKE!!! ZOMG!

As I've discovered from a coding standpoint, by creating proper dependaces, I can run gnu make with the -j parameter. -j followed by a number forks that number of threads, and runs the build process concurrently (where dependaces allow). Where there's a prerequisite, it waits.

GNU Make. Mmmmm. As if I wasn't intrigued by Linux before. :D

No comments: