Simple Summary
1 Startup process
The init process uses/etc/inittab to determine the sequence of startup and workflow Init executes the script under the/ETC/INIT.D directory that all the symbolic links in the/etc/runlevels/boot directory point to, when/etc/runlevels/ After the scripts referenced by the boot directory have been executed, the script that the symbolic link in the/etc/runlevels/default directory points to will continue to run
Related Instructions
There is a definition of run level in Inittab
L1:S1:WAIT:/SBIN/RC Single
L2:2:WAIT:/SBIN/RC Nonetwork
L3:3:WAIT:/SBIN/RC Default
L4:4:WAIT:/SBIN/RC Default
L5:5:WAIT:/SBIN/RC Default
L6:6:WAIT:/SBIN/RC reboot
The following definition
SI::SYSINIT:/SBIN/RC Sysinit
This is the INIT process will initialize to RC by/SBIN/RC Sysinit to initialize the system,/SBIN/RC script is responsible for system initialization
In the RC::BOOTWAIT:/SBIN/RC boot
The parameters of the RC script (boot) are the same as the subdirectories of the/etc/runlevels you want to use.
After the RC has finished executing, INIT will decide which virtual terminals to activate and what commands each terminal needs to run:
The following definitions are available in the Inittab
C1:12345:respawn:/sbin/agetty 38400 tty1 Linux
C2:12345:respawn:/sbin/agetty 38400 Tty2 Linux
C3:12345:respawn:/sbin/agetty 38400 Tty3 Linux
C4:12345:respawn:/sbin/agetty 38400 Tty4 Linux
C5:12345:respawn:/sbin/agetty 38400 Tty5 Linux
C6:12345:respawn:/sbin/agetty 38400 Tty6 Linux
This code defines which virtual terminals need to be activated when running at a certain level of operation and what commands each terminal needs to run
2 starting services and tuning
/etc/init.d/xxxx Status View service running status
/etc/init.d/xxxx Zap Manually set the information to stop
/etc/init.d/xxxx ineed View Dependent services
/ETC/INIT.D/XXXX needsme which services require this service (NEEDSME) or which services can use this service (USESME)
Rc-update Add xxx Default adds service to default level
Rc-update del xxx default removal service
The RC-UPDATE-V Show command will display all existing initialization scripts and list which run level they run in
Additional independent configuration added the advantage of this is that you will not overwrite your configuration after you reload a software
The Gentoo configuration is in the/ETC/CONF.D
reference to the official document of Gentoo
Www.gentoo.org/doc/zh_cn/handbook/handbook-x86.xml
First, your bootstrapper loads the kernel image you defined in the bootstrapper profile into memory, and then it tells the CPU to run the kernel. When the kernel is loaded and running, the kernel initializes all of the kernel-specific constructs and tasks and opens the Init process.
The process then ensures that all file systems (defined in/etc/fstab) are mounted and ready to use. The process then executes some of the scripts that are located under/ETC/INIT.D, which will start some of the services you need so that you can get a system that starts successfully.
Eventually, when all the scripts have been executed, Init activates the terminal (most often just the virtual terminal is activated, can be accessed using ALT-F1, ALT-F2, etc.), and a special process called agetty is attached to it. This process will ensure that you can log in to your system from these terminals by running login.
Gentoo does not randomly execute scripts under/ETC/INIT.D. Even it won't run/etc/init.d under all the scripts and will only go to execute/etc/runlevels under the
Init runs scripts in the/ETC/INIT.D directory that are pointed to by the symbolic links in all/etc/runlevels/boot directories. Typically, it executes these scripts alphabetically, but some scripts contain dependencies, meaning that the system will not run this script until another script is executed.
When the scripts referenced by the/etc/runlevels/boot directory are executed, Init continues to run the script that the symbolic links under the/etc/runlevels/default directory point to. They also execute these scripts alphabetically, unless a script has dependencies, so that the existing order is changed to make the startup order more reasonable.
Of course, Init doesn't decide all the startup sequences. It requires a configuration file to specify its workflow. This configuration file is/etc/inittab.
If you remember the boot sequence we just described, you'll remember that Init first did is mount all the file systems. This feature is actually defined in the/etc/inittab configuration file. As follows:
SI::SYSINIT:/SBIN/RC Sysinit
This line tells Init that the/SBIN/RC Sysinit must be run to initialize the system. The/SBIN/RC script is responsible for system initialization, so you might say that Init itself didn't do much of it-it just gave the initialization system task to another process.
Next, Init executes all scripts that have symbolic links in the/etc/runlevels/boot directory. This is defined by the following line:
RC::BOOTWAIT:/SBIN/RC Boot
What is run level
You've seen Init use a digital way to determine the run level that needs to be activated. The run level represents the state of your system running, and it contains a set of scripts (run level scripts or initialization scripts) that you need to perform when you enter or exit a run level.
There are seven running levels defined in Gentoo: Three internal run levels and four user custom run levels. These internal run levels are called Sysinit, shutdown, and reboot, and they do things like their name: Initializing the system, shutting down the system, and rebooting the system.
User-defined run levels have subdirectories with the same name under the/etc/runlevels directory: boot, default, Nonetwork, and single. Run level boot starts the system services that all other run levels must use. The other three running levels differ mainly in the services they are going to start: default is used for daily work, Nonetwork is used without network, and single is used when users repair the system.
using initialization Scripts
In fact, the scripts called by the RC process are called initialization scripts. Each script under/ETC/INIT.D can be executed with the following parameters: Start, stop, restart, pause, zap, status, Ineed, Iuse, Needsme, usesme, or broken.
To start, stop, or restart a service (and all services that depend on it), you should use the parameter
Start
、
Stop
And
Restart
。
The Gentoo initialization system uses the dependency tree (dependency-tree) to determine what services will be started first. Because it's a tedious job and we don't want our users to do it manually, we create a management tool (Rc-update) that simplifies the run level and initializes the scripts.
With Rc-update you can add or remove initialization scripts from one run level. The Rc-update tool automatically invokes the/sbin/depscan.sh script to re-create the dependency tree.
Adding and removing services
You have added the initialization script to the "default" run level during the Gentoo installation process. You may not be sure what "default" is, but you should know it now. The Rc-update script requires a second parameter to determine its behavior: Add, Del, or show.
To add or remove an initialization script, just give the rc-update add or del parameter and follow up with the initialization script and run level. As follows:
Code 2.1: Remove the Postfix service from the default level |
# rc-update del postfix default
|
The RC-UPDATE-V Show command will display all existing initialization scripts and list which run level they run in:
Code 2.2: Getting initialization script information |
# rc-update-v Show
|
You can also run Rc-update show (without the-v argument) to view only the initialization scripts that have been enabled and their level of operation.
*************************************************************************
Mount device file System at startup
*************************************************************************
/etc/fstab
An example illustrates
/dev/sda1/boot ext3 Defaults 1 2
/dev/sda2 None swap SW 0 0
/DEV/SDA3/EXT3 Defaults 0 1
NONE/PROC proc Defaults 0 0
NONE/DEV/SHM TMPFS Defaults 0 0
1. Equipment or file systems that need to be mounted
the field, (Fs_spec), describes the block special device or remote FIL Esystem to be mounted.
for ordinary mounts it'll hold (a link to) a Block special device node (as Created by Mknod (8)) for the device to be mounted, like '/dev/cdrom ' or '/dev/sdb7 '. & nbsp For NFS mounts one would have
2. There's nothing to say. mount point Note Swap etc
the second field, (Fs_file), describes the Mount Poin T for the filesystem. to swap partitions, this field should is specified as ' none '. If the name of the mount point contains spaces this can be escaped as '/040 '.
3. File System format
The third field, (Fs_vfstype), describes the type of the filesystem. Linux supports lots of filesystem types, such as ADFS, Affs, autofs, coda, , Coher-ent, Cramfs, devpts, EFS, ext 2, Ext3, HFS, HPFS, iso9660, JFS, Minix, Msdos, NCPFS, NFS, NTFS, proc, qnx4, ReiserFS, Romfs, Smbfs, SysV, Tmpfs, UDF, UF S,umsdos, VFAT, Xenix, XFS, and possibly others. For more details, and the Mount (8) . for the filesystems currently supported by the Running kernel, see/proc/filesystems. an entry swap denotes a file or partition to IS Used for swapping, cf. swapon (8) . A entry ignore causes the line to be ignored. This is useful to show disk partitions which are currently unused.
4. Post-mount Access status
the Fourth field, (Fs_mntops), describes the mount Options associated with the filesystem.
It is formatted as a comma separated list of options. it contains at l East the type of Mount plus any additional options appropriate to the filesystem type. for D Ocumentation on the available options for Non-nfs file systems, and the Mount (8) . for documentation to all nfs-specific Options have a look at NFS (5) . Common to all types of the file system are the options ' noauto ' (does not mount Mo Unt-a "is given, e.g., in boot time", ' user ' (allow a user to mount), and ' O Wner ' (Allow device owner to mount), and ' comment ' (e.g., for use by fstab-maintaining programs) . the ' owner ' a nd ' com-ment ' options are linux-specific. for more details, the mount (8).
5. Provides the dump function, in the system dump when need backup flag bit, the value is 0.
The Fifth field, (Fs_freq), is used for this filesystems by the dump (8) com Mand to determine which filesystems need to being dumped. If the fifth field is not present, a value of zero is Returne D and Dump would assume the filesystem does not need to be dumped.
6. Set this filesystem whether to do check on the boot, in addition to the root of the filesystem its necessary check to 1, all other visual needs to set, the default value is 0
the sixth field, (fs_passno), is used by the fsck (8) program to determine the order in which filesystem checks the do at are time. The root filesystem should is specified with a fs_passno of 1, and other filesystems should a have O F 2. filesystems within a drive will be checked sequentially, but filesystems on Diffe Rent drives'll be checked on the same time to utilize parallelism the the available If the hardware. Sp Is isn't present or zero, a value of zero is returned and fsck would assume that filesystem does not need to be checked.< /p>