понедельник, 29 марта 2010 г.

LPI exam 102 prep: Boot, initialization, shutdown, and runlevels

Краткие заметки, сделанные при подготовке к сдаче экзамена LPI 117-102 (Junior Level Linux Professional (LPIC-1)).

Boot the system

To summarize the boot process for PCs:
1. When a PC is turned on, the BIOS (Basic Input Output Service) performs
a self test.
2. When the machine passes its self test, the BIOS loads the Master Boot
Record (or MBR, usually from the first 512-byte sector of the boot drive).
This is usually the first hard drive on the system, but may also be a
diskette, CD, or USB key.
3. For a hard drive, the MBR loads a stage 1 boot loader, which is typically
either the LILO or GRUB stage1 boot loader on a Linux system. This is
another 512-byte, single-sector record.
4. The stage 1 boot loader usually loads a sequence of records called the
stage 2 boot loader (or sometimes the stage 1.5 loader).
5. The stage 2 loader loads the operating system. For Linux, this is the
kernel, and possibly an initial RAM disk (initrd).

The LILO configuration file defaults to /etc/lilo.conf.

Remember that whenever you make changes to /etc/lilo.conf, or whenever you
install a new kernel, you must run lilo

In addition to displaying the LILO configuration file, you may use the -q option of the
lilo command to display information about the LILO boot choices. Add -v options
for more verbose output.

The GRUB configuration file defaults to /boot/grub/grub.conf or /boot/grub/menu.lst.
If both are present, one will usually be a symbolic link to the other.

GRUB also does not require a partition to be mounted in order to configure a boot
entry for it. You will notice entries such as root (hd0,6) and
splashimage=(hd0,2)/boot/grub/fig1x.xpm.gz. GRUB refers to your hard
disks as hdn, where n is an integer starting from 0. Similarly, partitions on a disk are
similarly numbered starting from 0.

From the menu, you may press e on an entry to edit it, c to switch to a GRUB command line,
b to boot the system, p to enter a password, and Esc to return to the menu or to the
previous step. There is also a grub command, which creates a simulated shell in
which you may test your GRUB configuration or your GRUB command skills.

You may also view it on your system using the info grub command.

With GRUB, you could type in another set of commands for the kernel and initrd
statements, or, preferably, you could use the edit facility that you just learned about
to edit an existing entry by adding -prep to the end of the existing kernel image
name.

When the kernel finishes loading, it usually starts /sbin/init. This program
remains running until the system is shut down. It is always assigned process ID 1

The init program boots the rest of your system by running a series of scripts.
These scripts typically live in /etc/rc.d/init.d or /etc/init.d, and they perform services
such as setting the system's hostname, checking the filesystem for errors, mounting
additional filesystems, enabling networking, starting print services, and so on. When
the scripts complete, init starts a program calledgetty, which displays the login
prompt on consoles.

It's nice to be able to go back and review the kernel messages. Since standard
output is related to a process, and the kernel does not have a process identifier, it
keeps kernel (and module) output messages in the kernel ring buffer. You may
display the kernel ring buffer using the dmesg command, which displays these
messages on standard output.

Once your system has started to the point of running /sbin/init, the kernel still
logs events in the ring buffer as you just saw, but processes use the syslog daemon
to log messages, usually in /var/log/messages.

Runlevels , shutdown, and reboot

Runlevels define what tasks can be accomplished in the current state (or runlevel) of
a Linux system. Every Linux system supports three basic runlevels, plus one or
more runlevels for normal operation.

0 Shut down (or halt) the system
1 Single-user mode; usually aliased as s or S
6 Reboot the system

2 Multi-user mode without networking
3 Multi-user mode with networking
5 Multi-user mode with networking and the

To make a permanent change, you can edit /etc/inittab and change the default level
You can use the telinit command to tell the init process what runlevel it should switch to.

You can determine the current runlevel using the runlevel command, which
shows the previous runlevel as well as the current one.

f you use the ls command to display a long listing of the telinit command, you
will see that it really is a symbolic link to the init command. The init executable
knows which way it was called and behaves accordingly. Since init normally runs
as PID 1, it is also smart enough to know if you invoke it using init rather than
telinit. If you do, it will assume you want it to behave as if you had called
telinit instead. For example, you may use int 5 instead of telinit 5 to
switch to runlevel 5.

The shutdown command sends a warning message to all logged on users and blocks further logins.
It then signals init to switch runlevels. The init process then sends all running
processes a SIGTERM signal, giving them a chance to save data or otherwise
properly terminate. After 5 seconds, or another delay if specified, init sends a
SIGKILL signal to forcibly end each remaining process.

By default, shutdown switches to runlevel 1 (single-user mode). You may specify
the -h option to halt the system, or the -r option to reboot. A standard message is
issued in addition to any message you specify. The time may be specified as an
absolute time in hh:mm format, or as a relative time, n, where n is the number of
minutes until shutdown. For immediate shutdown, use now, which is equivalent to
+0.

If you have issued a delayed shutdown and the time has not yet expired, you may
cancel the shutdown by pressing Ctrl-c if the command is running in the foreground,
or by issuing shutdown with the -c option to cancel a pending shutdown.

The halt command halts the system.
The poweroff command is a symbolic link to the halt command, which
halts the system and then attempts to power it off.
The reboot command is a another symbolic link to the halt command,
which halts the system and then reboots it.

there are several other fields in /etc/inittab, along with a set
of init scripts in directories such as rc1.d or rc5.d, where the digit identifies the
runlevel to which the scripts in that directory apply

The scripts used by init when starting the system, changing runlevels, or shutting
down are typically stored in the /etc/init.d o r/etc/rc.d.init.d directory. A series of
symbolic links in the rcn.d directories, one directory for each runlevel n, control
whether a script is started when entering a runlevel or stopped when leaving it.
These links start with either a K or an S, followed by a two-digit number and then the
name of the service.

Комментариев нет: