Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://jet.sao.ru/hq/sts/linux/doc/pwr2bash/From-PowerUp-To-Bash-Prompt-HOWTO-6.html
Дата изменения: Unknown Дата индексирования: Tue Oct 2 09:35:30 2012 Кодировка: Поисковые слова: eridanus |
I will only talk about the ``System V'' style of init that Linux systems mostly
use. There are alternatives. In fact, you can put any program you like in
/sbin/init
, and the kernel will run it when it has finished loading.
It is init
's job to get everthing running the way it should be.
It checks that
the file systems are ok and mounts them. It starts up ``daemons'' to log system
messages, do networking, serve web pages, listen to your mouse and so on. It
also starts the getty processes that put the login prompts on your virtual
terminals.
There is a whole complicated story about switching ``run-levels'', but I'm going to mostly skip that, and just talk about system start up.
Init reads the file /etc/inittab
, which tells it what to do.
Typically, the first thing it is told to do is to run an initialisation script.
The program that executes (or interprets) this script is bash
,
the same program that gives you a command prompt.
In Debian systems, the initialisation script is /etc/init.d/rcS
, on Red Hat,
/etc/rc.d/rc.sysinit
. This is where the filesystems get checked and
mounted, the clock set, swap space enabled, hostname gets set etc.
Next, another script is called to take us into the default run-level. This just
means a set of subsystems to start up. There is a set of directories
/etc/rc.d/rc0.d
,
/etc/rc.d/rc1.d
, ..., /etc/rc.d/rc6.d
in Red Hat, or
/etc/rc0.d
,
/etc/rc1.d
, ..., /etc/rc6.d
in Debian, which correspond to the
run-levels. If we are going into runlevel 3 on a Debian system, then the script
runs all the scripts in /etc/rc3.d
that start with `S' (for start).
These scripts are really just links to scripts in another directory usually
called init.d
.
So our run-level script was called by init
, and it is looking in a directory for scripts starting with `S'. It might find S10syslog
first. The numbers tell the run-level script which order to run them in. So in this case S10syslog
gets run first, since there were no scripts starting with S00 ... S09. But S10syslog
is really a link to /etc/init.d/syslog
which is a script to start and stop the system logger. Because the link starts with an `S', the run-level script knows to execute the syslog
script with a ``start'' parameter. There are corresponding links starting with `K' (for kill), which specify what to shut down and in what order when leaving the run-level.
To change what subsystems start up by default, you must set up these links in
the rcN.d
directory, where N is the default runlevel set in your
inittab
.
The last important thing that init does is to start some getty
's.
These are ``respawned'' which means that if they stop, init
just
starts them again. Most distributions come with six virtual terminals. You may
want less than this to save memory, or more so you can leave lots of
things running and
quickly flick to them as you need them. You may also want to run a
getty
for a
text terminal or a dial in modem. In this case you will need to edit the
inittab
file.
/etc/inittab
is the top level configuration file for init.
The rcN.d
directories, where N = 0, 1, ..., 6 determine what
subsystems are started.
Somewhere in one of the scripts invoked by init, the mount -a
command
will be issued. This means mount all the file systems that are supposed to be
mounted. The file /etc/fstab
defines what is supposed to be mounted.
If you want to change what gets mounted where when your system starts up, this
is the file you will need to edit. There is a man page for fstab
.
Find the rcN.d
directory for the default run-level of your system and do a ls -l
to see what the files are links to.
Change the number of gettys that run on your system.
Remove any subsystems that you don't need from your default run-level.
See how little you can get away with starting.
Set up a floppy disk with lilo, a kernel and a statically linked "hello world" program called /sbin/init
and watch it boot up and say hello.
Watch carefully as your system starts up, and take notes about what it tells you is happening. Or print a section of your system log /var/log/messages
from start up time. Then starting at inittab
, walk through all the scripts and see what code does what. You can also put extra start up messages in, such as
echo "Hello, I am rc.sysinit"
This is a good exercise in learning Bash shell scripting too, some of the scripts are quite complicated. Have a good Bash reference handy.
inittab
and fstab
files.
Type (eg) man inittab
into a shell to see it.