Simple process for Linux system startup

Source: Internet
Author: User
Tags network function

1. Power-on self-test

First power on, then the CPU automatically loads the code on the motherboard on the ROM chip CMOS bios,cpu Why would you do that? Because this is how the CPU is designed. The BIOS will complete the peripheral hardware detection, and in order to find the boot device, the first device with a boot program is the device used to boot the system. This is related to the boot order in the BIOS, and if there is no boot program on the first device, the BIOS will look for the next one. If it is found but the boot fails, the BIOS will not look for the next one because the device is already started.

2. bootloader

The so-called boot program is the disk 0 track 0 sector MBR in the bootloader. When the BIOS found bootloader, it will give control to Bootloader, himself hidden behind the scenes, waiting for the next boot. The bootloader function is to load the kernel of the selected operating system into RAM and unzip it to a fixed location. Multi-system coexistence scenario, a selection menu is also provided. After the kernel boot succeeds, it starts to run, and the bootloader retire. The first thing to do when the kernel starts is to start its own initialization: to probe all recognized hardware and to load drivers for the hardware device from the disk. But then there is a problem, how does the drive kernel access the disk? It's impossible to get all the disk drivers into the kernel, so how big is the kernel?

2.1. Types of Bootloader

    • The bootloader on the Ntloader:windows

    • Lilo:linux Loader, which belongs to the ancient bootloader, because Lilo can only boot the kernel stored on a disk less than 1024 cylinders, so it is rarely seen today. But it is not eliminated, because of its small size, the use of small resources, in the Android phone or some other places are widely used.

    • Grub:grand Unified Bootloader, instead of Lilo, became the most widely used Bootloader on Linux. The Grub feature is very powerful: first it has no limits on the size of the disk, it can boot Linux,windows,unix and other operating systems, the ability to select the loaded kernel and provide the menu interface and other functions. Grub currently has two major versions:

      • Grub 0.X: Also known as Grub Legacy, enables use on CENTOS5 and 6

      • Grub 1.X: Also known as GRUB2, has changed dramatically over the Grub Legacy,grub 2. Because Grub 2 is almost re-rewritten for CENTOS7

3. RAMDisk

In fact, bootloader loads the image device called RAMDisk into memory while loading the kernel. This memory space becomes a block device that can be used as a hard disk. The nature of the storage inside is the drive of the disk. However, can the driver stored in the RAMDisk match the current hard drive? Our answer is yes. Because RAMDisk is the hardware information that is collected when the system is installed. Of course there are very low probability in the installation of the system, can not recognize the hard disk, but if the system is not installed, how to guide ah, how to say the boot process AH. During the boot process, RAMDisk is treated as a root file system until the root location is found and the root filesystem is mounted in a read-only manner. The location of the root is defined in the GRUB configuration file. After the root file system is mounted, the first application that starts the user space begins:/sbin/init

3.1. Naming of RAMDisk

    • CentOS 5:initrd-version.img

    • CentOS 6:initramfs-version.img

The reason for this change is that if the kernel accesses a block device, it caches the results in memory. And INITRD was in memory, and then cached a copy. Isn't that superfluous? As a result, the INITRD is made into a file system, and the kernel accesses the file system without caching

3.2. Production of RAMDisk

    • CentOS 5:MKINITRD

    • CentOS 6:DRACUT,MKINITRD

    • Dracut is used here.

    • Dracut [OPTION] ... <image> <kernel-version>

      • -M List: module listing

      • -d list: Driver list

Example: # dracut/boot/initramfs-$ (UNAME-R). IMG $ (UNAME-R)

4. Init

Init is interesting, and it's all different on centos5,6,7.

    • CentOS 5:SYSV Init

      • Features: SysV style's very old app. When the system starts, many services are started, and the services are started by script. There is a dependency between the scripts. On centos5, if there is a dependency between the a script and the B script, the B script starts after the a script starts and is serial initiated, causing the boot speed to be slow. And the script will start many processes.

      • Configuration file:/etc/inittab

    • CentOS 6:upstart

      • Features: The communication between Daemons relies on D-bus, so a similar parallel boot can be implemented basically. Script B can start in a moment when script a starts, without waiting for script A to finish.

      • Configuration file:/etc/inittab,/etc/init/*.conf two are to ensure compatibility with CentOS 5, in fact, CentOS 6 on the/etc/inittab is already a fake.

    • CentOS 7:SYSTEMD

      • Features: It does not start any services on boot, the service will only really start when the first access, and because the boot service is not dependent on the script, resulting in the creation of fewer processes.

      • Profile:/usr/lib/systemd/profile Many, this is just one of them

4.1. Init RunLevel

The init RunLevel is set for the purpose of system maintenance by setting up or shutting down the service implementation.

    • Init has 0-6 altogether 7 levels, of which:

      • 0: Shut down all services, shutdown

      • 1: Maintenance mode, single user mode, Sigle mode. This level allows root users to log in directly without authentication

      • 2: Maintenance mode, multi-user mode, requires user recognition, will start the network function, but does not support the use of NFS

      • 3: Normal level, full multi-user mode, text interface

      • 4: Reserved level

      • 5: Normal level, full multi-user mode, graphical interface

      • 6: Turn off all services, restart

The default level is 3 or 5


    • Switching levels:

      • init [0-6]

    • View levels:

      • RunLevel

      • Who–r

4.2. init configuration file

/etc/inittab (CENTOS5) configuration file format: Each row defines an action that is executed by Init, along with the corresponding program. Action is used to define when the program is run, RunLevel and action are integral

    • Format:

      • Id:runlevel:action:process

    • Example: Setting the default Run level

      • Id:3:initdefault:

    • Example: Define a script that completes system initialization

      • Si::sysinit:/etc/rc.d/rc.sysinit

5. Rc.sysinit

When the init process starts, it first reads the RunLevel in/etc/inittab. Then execute the/etc/rc.d/rc.sysinit script for system initialization: start the service. The start of the service is done through scripting, and the service script is stored in the/etc/rc.d/inin/directory

[[email protected] ~]# ls /etc/rc.d/init.d/abrt-ccpp          cpuspeed      httpd          messagebus      portreserve  rpcidmapd        sysstatabrtd              crond         ip6tables      netconsole      postfix      rpcsvcgssd       udev-postabrt-oops         cups           iptables      netfs            psacct        rsyslog         wdaemonacpid              dnsmasq       irqbalance    network          quota_nld    sandbox          winbindatd                firstboot     kdump          networkmanager  rdisc        saslauthd        wpa_supplicantauditd             functions     killall        nfs             restorecond   Singleautofs  &nbsP;         haldaemon     lvm2-lvmetad   nfslock         rngd          smartdblk-availability  halt           lvm2-monitor  ntpd             rpcbind      spice-vdagentdbluetooth          htcacheclean  mdmonitor     ntpdate          rpcgssd      sshd

But there is also a script directory:

[Email protected] ~]# ll/etc/init.d-dlrwxrwxrwx. 1 root root one Apr 08:13/etc/init.d-rc.d/init.d

Apparently, two directories are the same.

These scripts follow the definition specification of the LSB service script and accept at least four of the most basic parameters {Start|stop|status|restart}

These scripts can be called directly:/etc/init.d/svc_scripts {Start|stop|status|restart}

You can also use the Service command call: Service svc_scripts {Start|stop|status|restart}

But the script does not execute directly in this directory, but executes the script under the directory corresponding to the boot level in the/etc/rc.d/directory, which is why Init reads the system boot level first.

[Email protected] ~]# LS/ETC/RC.DINIT.D RC rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d rc.local rc.sysinit

If the start level is 3, the script under the RC3.D directory will be executed

[[email protected] ~]# ll /etc/rc.d/rc3.d/total 0lrwxrwxrwx. 1 root  ROOT&NBSP;16&NBSP;APR&NBSP;18&NBSP;08:23&NBSP;K01SMARTD&NBSP;-&GT;&NBSP, .... /init.d/smartdlrwxrwxrwx. 1 root root 17 apr 18 08:26 k05wdaemon  -&GT;&NBSP, .... /init.d/wdaemonlrwxrwxrwx. 1 root root 16 apr 18 08:24 k10psacct  -&GT;&NBSP, .... /init.d/psacctlrwxrwxrwx. 1 root root 19 apr 18 08:20 k10saslauthd &NBSP;-&GT;&NBSP, .... /init.d/saslauthdlrwxrwxrwx. 1 root root 22 apr 18 08:20  K15HTCACHECLEAN&NBSP;-&GT;&NBSP, .... /init.d/htcachecleanlrwxrwxrwx. 1 root root 15 apr 18 08:20 k15httpd &NBSP;-&GT;&NBSP, .... /init.d/httpdlrwxrwxrwx. 1 root root 24 apr 18 08:23 k30spice-vdagentd &NBSP;-&GT;&NBSP, .... /init.d/spice-vdagentdlrwxrwxrwx. 1 root root&NBSP;17&NBSP;APR&NBSP;18&NBSP;08:20&NBSP;K50DNSMASQ&NBSP;-&GT;&NBSP, .... /init.d/dnsmasqlrwxrwxrwx. 1 root root 20 apr 18 08:18 k50netconsole &NBSP;-&GT;&NBSP, .... /init.d/netconsolelrwxrwxrwx. 1 root root 13 apr 18 08:20 k60nfs  -&GT;&NBSP, .... /init.d/nfslrwxrwxrwx. 1 root root 20 apr 18 08:20 k69rpcsvcgssd  -&GT;&NBSP, .... /init.d/rpcsvcgssdlrwxrwxrwx. 1 root root 17 apr 18 08:18 k73winbind &NBSP;-&GT;&NBSP, .... /init.d/winbindlrwxrwxrwx. 1 root root 14 apr 18 08:20 k74ntpd - &GT;&NBSP, .... /init.d/ntpdlrwxrwxrwx. 1 root root 17 apr 18 08:20 k75ntpdate - &GT;&NBSP, .... /init.d/ntpdatelrwxrwxrwx. 1 root root 19 apr 18 08:23 k75quota_nld &NBSP;-&GT;&NBSP, .... /init.d/quota_nldlrwxrwxrwx. 1 root root 24&NBSP;APR&NBSP;18&NBSP;08:24&NBSP;K84WPA_SUPPLICANT&NBSP;-&GT;&NBSP, .... /init.d/wpa_supplicantlrwxrwxrwx. 1 root root 21 apr 18 08:18  K87RESTORECOND&NBSP;-&GT;&NBSP, .... /init.d/restorecondlrwxrwxrwx. 1 root root 15 apr 18 08:18 k89rdisc &NBSP;-&GT;&NBSP, .... /init.d/rdisclrwxrwxrwx. 1 root root 14 apr 18 08:23 k99rngd - &GT;&NBSP, .... /init.d/rngdlrwxrwxrwx. 1 root root 17 apr 18 08:22 s01sysstat - &GT;&NBSP, .... /init.d/sysstatlrwxrwxrwx. 1 root root 22 apr 18 08:23 s02lvm2-monitor &NBSP;-&GT;&NBSP, .... /init.d/lvm2-monitorlrwxrwxrwx. 1 root root 19 apr 18 08:20  S08IP6TABLES&NBSP;-&GT;&NBSP, .... /init.d/ip6tableslrwxrwxrwx. 1 root root 18 apr 18 08:18 s08iptables &NBSP;-&GT;&NBSP, .... /init.d/iptableslrwxrwxrwx. 1 ROOT&NBSP;ROOT&NBSP;17&NBSP;APR&NBSP;18&NBSP;08:18&NBSP;S10NETWORK&NBSP;-&GT;&NBSP, .... /init.d/networklrwxrwxrwx. 1 root root 16 apr 18 08:24 s11auditd  -&GT;&NBSP, .... /init.d/auditdlrwxrwxrwx. 1 root root 21 apr 18 08:14 s11portreserve &NBSP;-&GT;&NBSP, .... /init.d/portreservelrwxrwxrwx. 1 root root 17 apr 18 08:20 s12rsyslog &NBSP;-&GT;&NBSP, .... /init.d/rsysloglrwxrwxrwx. 1 root root 18 apr 18 08:23 s13cpuspeed &NBSP;-&GT;&NBSP, .... /init.d/cpuspeedlrwxrwxrwx. 1 root root 20 apr 18 08:21 s13irqbalance &NBSP;-&GT;&NBSP, .... /init.d/irqbalancelrwxrwxrwx. 1 root root 17 apr 18 08:15 s13rpcbind &NBSP;-&GT;&NBSP, .... /init.d/rpcbindlrwxrwxrwx. 1 root root 19 apr 18 08:18 s15mdmonitor &NBSP;-&GT;&NBSP, .... /init.d/mdmonitorlrwxrwxrwx.&nbSP;1&NBSP;ROOT&NBSP;ROOT&NBSP;15&NBSP;APR&NBSP;18&NBSP;08:19&NBSP;S20KDUMP&NBSP;-&GT;&NBSP, .... /init.d/kdumplrwxrwxrwx. 1 root root 20 apr 18 08:14 s22messagebus &NBSP;-&GT;&NBSP, .... /init.d/messagebuslrwxrwxrwx. 1 root root 24 apr 18 08:20  S23NETWORKMANAGER&NBSP;-&GT;&NBSP, .... /init.d/networkmanagerlrwxrwxrwx. 1 root root 17 apr 18 08:24  S24NFSLOCK&NBSP;-&GT;&NBSP, .... /init.d/nfslocklrwxrwxrwx. 1 root root 17 apr 18 08:24 s24rpcgssd &NBSP;-&GT;&NBSP, .... /init.d/rpcgssdlrwxrwxrwx. 1 root root 26 apr 18 08:23  S25BLK-AVAILABILITY&NBSP;-&GT;&NBSP, .... /init.d/blk-availabilitylrwxrwxrwx. 1 root root 14 apr 18 08:18  S25CUPS&NBSP;-&GT;&NBSP, .... /init.d/cupslrwxrwxrwx. 1 root root 15 apr 18 08:18 s25netfs - &GT;&NBSP, .... /init.d/netFSLRWXRWXRWX.&NBSP;1&NBSP;ROOT&NBSP;ROOT&NBSP;15&NBSP;APR&NBSP;18&NBSP;08:23&NBSP;S26ACPID&NBSP;-&GT;&NBSP, .... /init.d/acpidlrwxrwxrwx. 1 root root 19 apr 18 08:20 s26haldaemon &NBSP;-&GT;&NBSP, .... /init.d/haldaemonlrwxrwxrwx. 1 root root 19 apr 18 08:18 s26udev-post &NBSP;-&GT;&NBSP, .... /init.d/udev-postlrwxrwxrwx. 1 root root 16 apr 18 08:21 s28autofs &NBSP;-&GT;&NBSP, .... /init.d/autofslrwxrwxrwx. 1 root root 19 apr 18 08:21 s50bluetooth &NBSP;-&GT;&NBSP, .... /init.d/bluetoothlrwxrwxrwx. 1 root root 14 apr 18 08:23 s55sshd  -&GT;&NBSP, .... /init.d/sshdlrwxrwxrwx. 1 root root 17 apr 18 08:20 s80postfix - &GT;&NBSP, .... /init.d/postfixlrwxrwxrwx. 1 root root 19 apr 18 08:16 s82abrt-ccpp &NBSP;-&GT;&NBSP, .... /init.d/abrt-ccpplrWXRWXRWX.&NBSP;1&NBSP;ROOT&NBSP;ROOT&NBSP;15&NBSP;APR&NBSP;18&NBSP;08:16&NBSP;S82ABRTD&NBSP;-&GT;&NBSP, .... /init.d/abrtdlrwxrwxrwx. 1 root root 15 apr 18 08:20 s90crond - &GT;&NBSP, .... /init.d/crondlrwxrwxrwx. 1 root root 13 apr 18 08:15 s95atd -> &NBSP, .... /init.d/atdlrwxrwxrwx. 1 root root 19 apr 18 08:22 s99firstboot - &GT;&NBSP, .... /init.d/firstbootlrwxrwxrwx. 1 root root 11 apr 18 08:18 s99local &NBSP;-&GT;&NBSP, .... /rc.local

But LS the directory will find that this is all linked files, the path to the/etc/rc.d/init.d/directory is the script. In fact, only one copy of the script, all through the link to manage. The same is true for other levels of the directory. The benefits are also obvious.

These links start with S and K, all starting with S, are passed the start parameter to start; all start with K are passed the stop parameter to stop. The numbers that follow indicate the order in which they are started or closed. Smaller numbers indicate a higher order.

6. Chkconfig command

Set the start-up service, script symbolic link creation can be achieved through the Chkconfig command

    • Grammar:

      • Chkconfig [--level levels] Svc_scripts On|off

    • Options:

      • The chkconfig--level option explicitly specifies that the level is on or off and that the remaining levels are preserved. Default to Level 2,345

      • Chkconfig--list [svc_scripts]: View the status of the service at the corresponding level

      • Chkconfig--add|--del svc_scripts

        • --add: Add symbolic links to the corresponding/ETC/RC.D/RC0-6.D directory for a service that is stored in/ETC/INIT.D

        • --del: Delete the specified svc_scripts in the 7-level symbolic link

7. Start complete

When the service starts, 6 virtual terminals are started. Once each virtual terminal is started, an application--login will be attached to the terminal immediately, and if the default level is 5, a graphical virtual terminal will be launched with an X application attached. Finally, the user is logged in


END

Simple process for Linux system startup

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.