Linux OS Boot Sequence
Linux OS Boot Sequence
Linux OS Boot Sequence
Tip
If upgrading the kernel using the Red Hat Update Agent, the boot
loader configuration file is updated automatically. More information on
Red Hat Network can be found online at the following URL:
https://rhn.redhat.com.
Once the second stage boot loader is in memory, it presents the user with the
Red Hat Linux initial, graphical screen showing the different operating systems or
kernels it has been configured to boot. On this screen a user can use the arrow
keys to choose which operating system or kernel they wish to boot and press
[Enter]. If no key is pressed, the boot loader will load the default selection after a
configurable period of time has passed.
Note
Once the second stage boot loader has determined which kernel to boot, it
locates the corresponding kernel binary in the /boot/ directory. The kernel binary
is named using the following format — /boot/vmlinuz-<kernel-version> file
(where <kernel-version> corresponds to the kernel version specified in the boot
loader's settings).
For instructions on using the boot loader to supply command line arguments to
the kernel, see Chapter 2 Boot Loaders. For information on changing the runlevel
at the GRUB or LILO prompt, see Section 2.10 Changing Runlevels at Boot
Time.
The boot loader then places the appropriate initial RAM disk image, called an
initrd, into memory. The initrd is used by the kernel to load drivers necessary
to boot the system. This is particularly important if SCSI hard drives are present
or if the systems uses the ext3 file system [2].
Warning
Do not remove the /initrd/ directory from the file system for any
reason. Removing this directory will cause the system to fail with a
kernel panic error message at boot time.
Once the kernel and the initrd image are loaded into memory, the boot loader
hands control of the boot process to the kernel.
For a more detailed overview of the GRUB and LILO boot loaders, see Chapter 2
Boot Loaders.
As illustrated in this listing, none of the scripts that actually start and stop the
services are located in the /etc/rc.d/rc5.d/ directory. Rather, all of the files in
/etc/rc.d/rc5.d/ are symbolic links pointing to scripts located in the
/etc/rc.d/init.d/ directory. Symbolic links are used in each of the rc
directories so that the runlevels can be reconfigured by creating, modifying, and
deleting the symbolic links without affecting the actual scripts they reference.
The name of each symbolic link begin with either a K or an S. The K links are
processes that are killed on that runlevel, while those beginning with an S are
started.
The init command first stops all of the K symbolic links in the directory by
issuing the /etc/rc.d/init.d/<command> stop command, where <command> is the
process to be killed. It then starts all of the S symbolic links by issuing
/etc/rc.d/init.d/<command> start.
Tip
Each of the symbolic links are numbered to dictate start order. The order in which
the services are started or stopped can be altered by changing this number. The
lower the number, the earlier it is started. Those symbolic links with the same
number are started alphabetically.
Note
After the init command has progressed through the appropriate rc directory for
the runlevel, the /etc/inittab script forks a /sbin/mingetty process for each
virtual console (login prompts) allocated to the runlevel. Runlevels 2 through 5
get all six virtual consoles, while runlevel 1 (single user mode) gets only one and
runlevels 0 and 6 get none. The /sbin/mingetty process opens communication
pathways to tty devices [5], sets their modes, prints the login prompt, gets the
user name, and initiates the login process for the user.
In runlevel 5, the /etc/inittab runs a script called /etc/X11/prefdm. The prefdm
script executes the preferred X display manager — gdm, kdm, or xdm, depending
on the contents of the /etc/sysconfig/desktop file.
At this point, the system is operating on runlevel 5 and displaying a login screen.
Notes
[1] GRUB reads ext3 file systems as ext2, disregarding the journal file. See
the chapter titled The ext3 File System in the Red Hat Linux
Customization Guide for more information on the ext3 file system.
[2] For details on making an initrd, see the chapter titled The ext3 File
System in the Red Hat Linux Customization Guide.
[3] For more information on SysV init runlevels, see Section 1.4 SysV Init
Runlevels.
[4] The update command is used to flush dirty buffers back to disk.
[5] See Section 5.3.11 /proc/tty/ for more information on tty devices
init.d/
rc0.d/
rc1.d/
rc2.d/
rc3.d/
rc4.d/
rc5.d/
rc6.d/
The init.d/ directory contains the scripts used by the /sbin/init command
when controlling services. Each of the numbered directories represent the six
default runlevels configured by default under Red Hat Linux.
1.4.1. Runlevels
Runlevels are a state, or mode, defined by the services listed in the SysV
/etc/rc.d/rc<x>.d/ directory, where <x> is the number of the runlevel.
The idea behind SysV init runlevels revolves around the fact that different
systems can be used in a different ways. For example, a server runs more
efficiently without the drag on system resources created by the X Window
System. Other times, a system administrator may need to operate the system at
a lower runlevel to perform diagnostic tasks, like fixing disk corruption in runlevel
1, when no other users can possibly be on the system.
The characteristics of a given runlevel determines which services are halted and
started by init. For instance, runlevel 1 (single user mode) halts any network
services, while runlevel 3 starts these services. By assigning specific services to
be halted or started on a given runlevel, init can quickly change the mode of the
machine without the user manually stopping and starting services.
The following runlevels are defined by default for Red Hat Linux:
• 0 — Halt
• 1 — Single-user text mode
• 2 — Not used (user-definable)
• 3 — Full multi-user text mode
• 4 — Not used (user-definable)
• 5— Full multi-user graphical mode (with an X-based login
screen)
• 6 — Reboot
In general, users operate Red Hat Linux at runlevel 3 or runlevel 5 — both full
multi-user modes. Users sometimes customize runlevels 2 and 4 to meet specific
needs. since they are not used.
The default runlevel for the system is listed in /etc/inittab. To find out the
default runlevel for a system, look for the line similar to the one below near the
top of /etc/inittab:
id:5:initdefault:
The default runlevel listed in the example above is five, as the number after the
first colon indicates. To change it, edit /etc/inittab as root.
Warning
/sbin/shutdown -h now
/sbin/shutdown -r now
After shutting everything down, the -h option will halt the machine, and the -r
option will reboot.
Non-root users can use the reboot and halt commands to shut down the system
while in runlevels 1 through 5. However, not all Linux operating systems support
this feature.
If the computer does not power itself down, be careful not turn off the computer
until a message appears indicating that the system is halted.
Failure to wait for this message can mean that not all the hard drive partitions are
unmounted, and can lead to file system corruption.