Liunx start-up process and module management

Source: Internet
Author: User

  1. The system can be turned on through the process of integration into the bottom:
    1. Load the hardware information of the BIOS and conduct self-test, and obtain the first bootable device according to the setting;
    2. Read and execute the boot Loader (i.e. grub, spfdisk, etc.) of the MBR in the first boot device;
    3. According to the boot loader settings load Kernel, Kernel will start to detect hardware and load drivers;
    4. After the hardware driver is successful, Kernel will actively call the INIT program, and INIT will get run-level information;
    5. Init executes the/etc/rc.d/rc.sysinit file to prepare the operating environment for the software execution (e.g. network, time zone, etc.);
    6. Init executes the various services of run-level to start;
    7. Init executes the/etc/rc.d/rc.local file;
    8. Init executes the terminal emulator Mingetty to start the login program, and finally waits for the user to log in;
  2. The main features of boot loader are as follows:
    • Menu: Users can choose different boot items, which is also an important function of multi-boot!
    • Load the Core archives: direct point to the bootable program section to start the operating system;
    • Transfer other loader: The power-on management function is transferred to other loader.
  3. Problem: If Linux is installed on a SATA hard drive, the system will not be able to load the core without the drive of the SATA hard drive and the driver in the root directory.
    • Workaround: There is a virtual file system, the general file name is/BOOT/INITRD, the profile is that he can also be loaded into memory through the boot loader, then the file will be decompressed and emulated in memory as a root directory, And this simulation in the memory of the file system can provide an executable program, through the program to load the boot process of the most needed core modules, usually these modules are USB, RAID, LVM, SCSI and other file system and disk interface driver! When loading is complete, it will help the core to re-call/sbin/init to begin the subsequent normal boot process.
  4. Question: Is it not possible to boot without initrd?
    • Answer: Not necessarily! The most important reason to need initrd is that when the root cannot be mounted at boot time, it is necessary to initrd at this time, such as your root directory in a special disk interface (USB, SATA, SCSI), or your file system is more special (LVM, RAID), etc., you will need I Nitrd. If your Linux is installed on the IDE interface of the disk, and use the default Ext2/ext3 file system, then do not need to INITRD can also be successfully booted into Linux!
  5. First program init and configuration file/etc/inittab and RunLevel
    1. Run level: What are the levels of execution?
      • 0-halt (System direct shutdown)
      • 1-single user mode (single-use maintenance mode, for maintenance in case of system problems)
      • 2-multi-user, without NFS (similar to the bottom RunLevel 3, but no NFS service)
      • 3-full Multi-User mode (full text mode with network functionality)
      • 4-unused (System hold function)
      • 5-x11 (similar to RunLevel 3, but loaded using X Window)
      • 6-reboot (restart)
    2. Processing process for Init
      1. First obtain the runlevel that is the default level of implementation of the relevant level (with the bird's test machine For example, 5th number);
      2. Using/etc/rc.d/rc.sysinit for system initialization
      3. Since RunLevel is 5, only "L5:5:WAIT:/ETC/RC.D/RC 5" is performed and the other rows are skipped
      4. Set [Ctrl]+[alt]+[del] This group of key combination function
      5. Set the PF, PR two mechanism of the continuous electric system;
      6. Six terminals to start Mingetty (tty1 ~ tty6)
      7. Finally start the graphics interface with/etc/x11/perfdm-nodaemon!
    3. Init processing System initialization process (/ETC/RC.D/RC.SYSINIT)
      1. Get the network environment and host type:
        • Read the network configuration file/etc/sysconfig/network, get the hostname and the default gateway, etc. network environment.
      2. Test and Mount memory device/proc and USB device/sys:
        • In addition to mounting the memory device/proc, it also proactively detects if there is a USB device on the system, and if so, it actively loads the USB driver and attempts to mount the USB file system.
      3. Decide whether to start SELinux:
        • Detects if it is necessary to rewrite the standard SELinux type (auto relabel) for all files.
      4. To start the system's random number generator:
        • The random number generator can help the system perform some cryptographic cryptographic calculus functions, where it is necessary to start two random number generators.
      5. Set the terminal (console) Glyph:
      6. Set the Welcome screen (text banner) displayed in the boot process;
      7. Set the system time (clock) and time zone setting: Read into the/etc/sysconfig/clock setting value
      8. Detection of interface devices and testing of Plug and Play (PnP) Parameters:
        • The detection of interface devices such as IDE/SCSI/network/sound effects (/proc/sys/kernel/modprobe) is initiated based on the core detection results at boot-up, as well as the parameter testing of the PnP device using the core modules to be loaded.
      9. User-defined module loading
        • The user can add a custom module to the/etc/sysconfig/modules/*.modules and it will be loaded into the system at this time
      10. Load the relevant settings for the core:
        • The system will take the initiative to read the/etc/sysctl.conf this file set value, so that the core function as we want to look.
      11. Set hostname and initialize Power Management module (ACPI)
      12. Initialize the software disk array: mainly through the/etc/mdadm.conf to set the good.
      13. Initialize the file system capabilities of LVM
      14. Check disk File system with Fsck: FileSystem check
      15. Conversion of disk quota quota (not necessary):
      16. Re-mount the system disk in rewritable mode:
      17. Start the quota function: so we don't need to customize the Quotaon action
      18. To start the system virtual random number generator (pseudo-random):
      19. Clear the temporary files during boot:
      20. The boot-related information is loaded into the/VAR/LOG/DMESG file.
  6. Dynamic system services and related boot profiles (/ETC/RC.D/RC N &/etc/sysconfig)
    1. /ETC/RC.D/RC this file.
      • Get the script directory you want to execute by using the external first parameter ($). That is, the/ETC/RC.D/RC 5 can be obtained/etc/rc5.d/this directory to prepare to deal with the relevant script program;
      • Find/etc/rc5.d/k?? * Start the file and proceed with "/etc/rc5.d/k??" * Stop "action;
      • Find/etc/rc5.d/s?? * Start the file and proceed with "/etc/rc5.d/s??" * Start "action;
    2. etc/rc5.d/this file.
      • File names are all in Sxx or Kxx, where xx is a number, and these numbers are related to the file! All is the link file, link to stand alone service start directory/etc/init.d/go
      • /etc/rc5.d/[sk]xx actually ran to/etc/init.d/to find the corresponding service script, and then respectively start (SXX) or stop (KXX) action!
      • Because the different services are actually related to each other, some services are enabled first, and other services can be re-enabled. So there are sxx and kxx.
  7. User-defined boot loader (/etc/rc.d/rc.local)
    • Any work that you want to do at boot time, write it directly to/etc/rc.d/rc.local, then the work will be loaded automatically when the boot!
  8. Load terminal or X-window interface according to/etc/inittab
    • /etc/init/start-ttys.conf--------The configuration file defines six terminal windows
  9. The main configuration file that will be used during the boot process
    • In the course of/sbin/init's operation, we talked about multiple execution scripts, including/etc/rc.d/rc.sysinit and/ETC/RC.D/RC and so on, in fact, these scripts will use a considerable number of system configuration files, these boot process will use the configuration files are mostly placed in The/etc/sysconfig/directory. At the same time, because the core still need to load some drivers (core module), at this time the system customization of the device and module corresponding file (/etc/modprobe.conf) is very important AH!
    • About Modules:/etc/modprobe.conf
      • Cat/etc/modprobe.conf
      • Alias eth0 8139too <== let eth0 use 8139too module
    • /etc/sysconfig/*
      • authconfig: This file is primarily used to standardize the user's body backup authentication mechanism, including the use of native/etc/passwd,/etc/shadow, and/etc/shadow The password records which encryption algorithm to use, and whether to use the account authentication (NIS, LDAP) provided by the external password server. The system uses the MD5 encryption algorithm by default, and does not use the external body backup authentication mechanism;
      • Clock: This file sets the time zone for the Linux host, can use Greenwich Mean Time (GMT), or it can be used locally. Basically, the time zone referenced in the setting item "zone" in the clock file is located in a relative path in the/usr/share/zoneinfo directory. And to modify the time zone, you have to copy/usr/share/zoneinfo/asia/taipei this file into a/etc/localtime!
      • i18n:i18n in the use of some astonished system, such as the most troublesome text interface under the date display problem, garbled when changing the i18n file, the inside of the lc_time into en can!
      • Keyboard & Mouse:keyboard and mouse are in the form of keyboard and mouse settings,
      • Network:network can set whether to start the network, and set the host name and the Communication gate (gate ) These two important information
  10. switch at run level
    • different run level just is different from the service loaded, that is,/etc/rc5.d/and/etc/rc3.d within the sxxname and kxxname differences.
    • executes init3 from Run Level 5:
      1. compare files with K and S in/etc/rc3.d/and/etc/rc5.d first;
      2. in the new runlevel Also That is, the number of K-opening files within the/etc/rc3.d/is closed;
      3. starts with a new runlevel, which is the number of S-opening files in the/etc/rc3.d/;
    • Query Current run level     runlevel
  11. core and core modules  
    1. core and core modules
      • Core:/boot/vmlinuz or/boot/vmlinuz-version;
      • core unzip required R AM Disk:/BOOT/INITRD (/boot/initrd-version);
      • Core module:/lib/modules/version/kernel or/lib/modules/$ (uname-r)/ke Rnel
      • Core Source:/usr/src/linux (to be installed!) Otherwise the Presets are not installed!
    2. If the core is successfully loaded into the system, then there will be a few messages logged:
      • core version:/proc/version
      • System core features:/proc/ Sys/kernel
    3. add system and new supported hardware
      1. recompile the core and add the latest hardware driver source code;
      2. compiles the hardware driver into a module, Download the module
  12. core modules and dependencies
    1. /lib/modules/$ (uname-r)/kernel  content
      • arch: projects related to hardware platforms, such as CPU levels, etc.
      • Crypto: The encryption technology supported by the core, such as MD5 or DES, etc.;
      • drivers: Some hardware drivers, such as display adapters, network cards, PCI-related hardware, and so on;
      • FS: Filesystems supported by the core, such as VFAT, ReiserFS, NFS, and so on;
      • Lib: some function libraries;
      • Net: Network-related protocol data, as well as firewall modules (net/ipv4/netfilter/*), etc.
      • Sound: The various modules related to audio;
    2. /lib/modules/$ (Uname-r)/MODULES.DEP records the dependencies of the modules supported at the core,
      • depmod [-ane]
        • -A: When no parameters are added, Depmod will proactively analyze the current core modules and re-write/lib/modules/$ (uname-r)/modules.dep. If you add the-a parameter, then Depmod will search for a new module than the MODULES.DEP, and if a new module is found, it will be updated.
        • -N: Does not write to MODULES.DEP, but outputs the result to the screen (standard out);
        • -E: Displays the name of the non-executable module that is currently loaded
    3. For example: A network card driver with the file name A.ko, how to update the core dependencies
      1. CP a.ko/lib/modules/$ (UNAME-R)/kernel/drivers/net
      2. depmod
  13. Watch the core module
    •  lsmod ----------------See how many modules are currently loaded on the core
    • modinfo------------------Check the information for specific modules
      •  modinfo [-ADLN] [module_name|filename]
        • -A: Lists only the author name;
        • -D: Lists only the modules
        • -L: List only authorizations (license);
        • -N: Lists only the detailed path of the module.
  14. Core module loading and removal
    • does not actively analyze the module dependencies, if there is a dependency problem, will error, loading not
    • insmod [/full/path/module_name] [parameters]------- ------Self-loading module
    • Example: Load Cifs.ko This file system module
      • insmod/lib/modules/$ (uname-r)/kernel/fs/cifs/cifs.ko
      • lsmod | grep cifs
    • rmmod [-FW] module_name---------------A module
      • -F: Force the module removed, whether or not it is being used;
      • -W: If the module is being used, then Rmmod will wait for the module to be used before removing it!
    • proactively parses module dependencies
      • modprobe [-LCFR] module_name
        • -C: Lists all of the current system modules! (More detailed code-name correspondence table)
        • -L: Lists the full file name of all modules currently in/lib/modules/' Uname-r '/kernel
        • F: Force the module to load;
        • -R: Similar to Rmmod, is to remove a module ~
  15. additional parameter settings for the core module:/etc/modprobe.conf
    • vi/etc/modprobe.conf
      • alias eth0 Ne  eth0 and eth1 simultaneously Using NE, set with the same IO and IRQ
      • alias eth1 ne
      • options eth0 io=0x300 irq=5
      • options eth1 io=0x320 ir q=7
  16. boot Loader:grub
    • The first sector (sector) of the boot device is only 446 bytes, and the boot Loader entire program is not placed, so the program code execution of the boot Loader of Linux is executed in two stages with setpoint loading 。
    • stage1, execute boot loader main program, must be installed in the boot area, that is, MBR or boot loader. Installs only the smallest program, does not install the loader related profile
    • stage2, the main program loads the configuration file, the configuration file is in/boot     ls-l/boot/grub
      • Grub Configuration file/boot/grub/menu.lst and menu type
        • Grub benefits
          • recognize and support more file systems, and you can use grub The main program searches the file system directly for the core file name;
          • when booting, you can "edit and modify the boot setting item", similar to the command mode of bash,
          • can dynamically search the configuration file without needing to reinstall Grub after modifying the configuration file 。 That is, we just to modify the  /boot/grub/menu.lst inside the settings, the next time the power on will be effective!
      • /boot/grub/menu.lst configuration file:
        • Default=0
          • This must be compared with the title, in the configuration file there are several title, when the boot will have a few menus to choose from. Since the grub start number is No. 0, the default=0 means that the "first title item" is used for booting. Default means that if you do not move to the keyboard until the end of the second reading time, grub defaults to using this title item (number NO. 0) to boot.
        • Timeout=5
          • When the power-on will be read seconds, if in 5 seconds did not press any key, will use the above mentioned default after the title project to boot the meaning.
        • Splashimage= (hd0,0)/grub/splash.xpm.gz
          • Background image
        • Hiddenmenu
          • Does this mean that the menu should be displayed when booting? The current CentOS default is not to display the menu, if you want to display the menu, then the value of this setting is commented out!
        • Root:
          • It stands for "the partition, not the root directory, where the core files are placed" Oh! Don't make a mistake! In the case of Brother Bird, my root directory is/dev/hda2 and/boot Independent for/DEV/HDA1, because it is related to/boot, so the disk designator will become (hd0,0).
        • Kernel:
          • As for the kernel followed by the core file name, and after the file name is followed by the core parameters. Because of the need to mount the root directory during the boot process, so the kernel behind the ROOT=LABEL=/1 refers to the "Linux root directory in which partition" meaning. Remember the eighth chapter on the LABEL Mount feature? Yes, use the LABEL here to mount the root directory. As for the RHGB color display and quiet is quiet mode (the screen does not output the core detection information).
        • Initrd:
          • The INITRD made the file name of RAM Disk in the previous mention!
      • Transfer of control by means of chain loader
        • Vi/boot/grub/menu.lst
          • Title Windows partition
            • Hide (hd0,4) <== (hd0,4) This split slot (optional)
            • Root (hd0,0) <== settings Use this split slot (see which partition the system is mounted on)
            • or rootnoverify (hd0,0) <== does not test this split slot
            • Chainloader +1 <== +1 can be thought of as the first sector, i.e. boot sector
            • Makeactive <== sets this slot as the boot disk (active)---because the Windows boot disk needs to be set to active (active) state
  17. The importance of INITRD and the establishment of new INITRD archives
    • MKINITRD [-v] [--with= module name] INITRD file name Core version
      • -V: Shows how the MKINITRD works
      • --with= Module Name: module name refers to the name of the module, do not need to fill in the file name. For example, the current core version of the Ext3 file system module is the bottom file name:
      • /lib/modules/$ (uname-r)/kernel/fs/ext3/ext3.ko that you should write:--with=ext3 just fine (omit. Ko) said,
      • INITRD file name: You want to create a INITRD file name, try to make a meaningful and well-remembered name.
      • Core version: A core version, if the current core is "$ (uname-r)"
    • Example: Add 8139too initrd file for this module
      1. Mkinitrd-v--with=8139too initrd_vbirdtest $ (uname-r)
  18. Testing and installing Grub
    • Grub-install [--root-directory=dir] Install_device
      • --root-directory=dir that dir is the actual directory, using Grub-install defaults to copy all of the grub files to/boot/grub/*, if you want to copy to other directories and devices, you have to use this parameter.
      • Install_device Installed device Code!
    • Example: Installing grub under the MBR of the current system, my system is/dev/hda:
      • Grub-install/dev/hda
      • My/home is a standalone/dev/hda3, how to install grub to/dev/hda3
      • Grub-install--root-directory=/home/dev/hda3
    • The files are all in the installation! But notice that we don't have a profile! You have to build it yourself! Finally, the GRUB shell will be installed to install the GRUB main program to the MBR or boot sector!
      • Example: In the original menu.lst three new boot menu, respectively, the following description:
        • Assuming that the/DEV/HDA1 contains boot loader, how does this loader gain control?
        • How do I re-read the loader inside the MBR?
        • Use your original system core file to create a menu that can be forced into a single maintenance mode
      • Implementation process:
        • Vim/boot/grub/menu.lst
          • Default=0
            Timeout=30
            Splashimage= (hd0,0)/grub/splash.xpm.gz
            #hiddenmenu
            Title CentOS (2.6.18-92.EL5)
            Root (hd0,0)
            Kernel/vmlinuz-2.6.18-92.el5 ro root=label=/1 rhgb quiet
            Initrd/initrd-2.6.18-92.el5.img
            TITLE/DEV/HDA1 Boot Sector <== The first new menu in this example
            Root (hd0,0)
            Chainloader +1
            Title MBR loader <== New second menu
            Root (hd0) &LT;==MBR is the first sector of the entire disk, so use the name of the entire disk
            Chainloader +1
            Title Single user mode <== new third menu (actually copied from the original title)
            Root (hd0,0)
            Kernel/vmlinuz-2.6.18-92.el5 ro root=label=/1 rhgb quiet single
            Initrd/initrd-2.6.18-92.el5.img
          • The next time you turn it on, you'll find four menus to choose from, and the Presets will start with the first menu!
        • Install the Grub Master program again to the boot sector of/DEV/HDA1, and also want to reinstall Grub to the MBR
          • Introduction to GRUB Instructions
            • Use "root (hdx,x)" To select the partition code containing the GRUB directory;
            • Use "Find/boot/grub/stage1" to see if the installation information files can be found;
            • Use "Find/boot/vmlinuz" to see if you can find kernel file (not necessarily successful!). )
            • Install grub in boot sector or MBR with Setup (hdx,x) or setup (HDX);
            • Use "Quit" to leave the grub shell!
          • implementation:
            • [[email protected] ~]# Grub
                  1. First set the partition that contains the GRUB directory!
                   grub> Root (hd0,0)
                   2. To find out, is there stage1 this information file?
                   grub> find/grub/stage1
                    (hd0,0)
                     because the/boot is independent, and grub finds not the directory tree, but the file inside the device.
                  3. Find out if the core can be found? /boot/vmlinuz-2.6.18-92.el5?
                   grub> find/vmlinuz-2.6.18-92.el5
                    (hd0,0)
                   4. Install the main program! Install to MBR look!
                   grub> Setup (hd0)
                  5. So repeat the installation to my/dev/hda1? Which is the boot sector?
                   grub> Setup (hd0,0)
        • Finally, summarize:
          1. If you are transferring from another boot loader to grub, you must first install the Grub configuration file using Grub-install;
          2. Start editing Menu.lst this important configuration file;
          3. Install the main program into the system via grub, such as MBR (hd0) or boot sector (hd0,0), etc.

Liunx start-up process and module management

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.