CentOS Study Notes & mdash; Start, ROOT password, centos Study Notes

Source: Internet
Author: User

CentOS Study Notes-start, ROOT password, and centos Study Notes
Startup Process Overview


Simply put, the process of system startup can be merged into the following process:

  • Load BIOS hardware information and perform self-testing, and obtain the first device that can be started according to the configuration;
  • Read and run the boot Loader (grub, spfdisk, and other programs) of MBR in the first startup device );
  • Based on the boot loader configuration, the Kernel starts to detect the hardware and load the driver;
  • After the hardware driver is successful, the Kernel will call the init program and the init will obtain the run-level information;
  • Run the/etc/rc. d/rc. sysinit file in init to prepare the job environment (such as network and Time Zone) where the software runs );
  • Start of each Service Running run-level in init (script Mode );
  • Run the/etc/rc. d/rc. local file in init;
  • Init runs the terminal simulation program mingetty to start the login program, and finally waits for the user to log on;

For details, see the Linux private house dish of laruence-basic learning directory.Startup Process, module management and loader

Boot Loader: Grub

At present, grub is the most popular boot loader in Linux.

Two stages of boot loader

After reading the BIOS information, the next step is to read the boot loader from the MBR of the first startup device. This boot loader can have menu functions, direct loading of core files, and control transfer functions. The system must have loader to load the core of the operating system. However, we all know that MBR is the first block in the entire hard disk, and its size is only 446 bytes at best. Our loader is so powerful that it is impossible for program code and configuration data to only occupy less than 446 bytes of capacity? So how to install it?

To solve this problem, Linux divides the program code running and Configuration value loading of boot loader into two stages for running:

  • Stage 1: run the boot loader main program:
    The first stage is the main program running boot loader. The main program must be installed in the boot zone, that is, MBR or boot sector. But as mentioned above, because MBR is too small, MBR or boot sector usually only installs the minimum main program of boot loader, and does not have the relevant configuration file of loader;
  • Stage 2: The main program load configuration file:
    The second stage is to load all configuration files and Related Environment Parameter files (including the file system definition and main configuration file menu. lst) through the boot loader. Generally, the configuration files are under/boot.

So where are these configuration files? All grub-related files are stored in/boot/grub.

[Root @ www ~] # Ls-l/boot/grub-rw-r -- device. map <= grub device file (mentioned below) -rw-r -- e2fs_stage00005 <= ext2/ext3 file system definition file-rw-r -- fat_stage00005 <= definition file of the FAT file system-rw-r -- r -- ffs_stage00005 <= FFS file system definition file-rw ------- grub. conf <= grub configuration file in Red Hat-rw-r -- iso9660_stage00005 <= optical drive file system definition file-rw-r -- jfs_stage00005 <= jfs File the system definition file lrwxrwxrwx menu. lst->. /grub. conf <= actually menu. lst is the configuration file! -Rw-r -- minix_stage1_5 <= minix file system definition file-rw-r -- reiserfs_stage1_5 <= reiserfs file system definition file-rw-r -- splash.xpm.gz <= background icon under grub at startup-rw-r -- stage1 <= stage 1-rw-r -- stage2 <= stage 2 -rw-r -- ufs2_stage00005 <= UFS file system definition file-rw-r -- vstafs_stage00005 <= vstafs file system definition file-rw-r -- r -- xfs_stage1_5 <= xfs file system definition file
From the above description, you can know that the most important thing in the/boot/grub/directory is the configuration file (menu. lst) and the definition of various file systems! After reading the definition data of this file system, our loader can recognize the file system and read the core files in the file system. The configuration file name of grub should be menu. lst, which is defined as/boot/grub. conf in Red Hat.
  • /Boot/grub/menu. lst configuration file:
    [Root @ localhost ~] # Cat/boot/grub/menu. lst # grub. conf generated by anaconda # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a/boot partition. this means that # all kernel and initrd paths are relative to/boot/, eg. # root (hd0, 0) # kernel/vmlinuz-version ro root =/dev/mapper/VolGroup-lv_root # initrd/initrd-[generic-] version. img # boot =/dev/sdadefault = 0 timeout = 5 splashimage = (hd0, 0)/grub/splash.xpm.gz hiddenmenutitle CentOS (2.6.32-279. el6.i686) root (hd0, 0) kernel/vmlinuz-2.6.32-279.el6.i686 ro root =/dev/mapper/VolGroup-lv_root rd_NO_LUKS .......... initrd/initramfs-2.6.32-279.el6.i686.img (omitted)

    The four rows before the title belong to the overall configuration of grub, including the default waiting time, the default startup project, and the displayed image features. The title is followed by the specified start core file or boot loader control. The following items are common in overall configuration:

    • Default = 0
      This must be compared with the title. There are several titles in the configuration file, and several menus can be selected at startup. Since the Starting number of grub is 0, default = 0 indicates that the "First title Project" is used to start. Default means that if the keyboard is not moved before the end of the second, grub uses this title item (0 here) by default to start.
    • Timeout = 5
      It will be read for seconds at startup. If you do not press any buttons within five seconds, the title project followed by the default mentioned above will be used for start. If you think 5 seconds is too short, you can increase the value (for example, 30 seconds. In addition, if timeout = 0, the default value is directly used to start without reading the second. If timeout =-1, the system directly enters the menu and does not read the second!
    • Splashimage = (hd0, 0)/grub/splash.xpm.gz
      Did you find that the background of your CentOS was not black or white but color changed when it was started? That is the background graph provided by this file (note 3 )! But how is the actual path of this file written like this? Very easy ~ The above means: the grub/splash.xpm.gz file under the top-level directory in the (hd0, 0) Split slot. The/boot directory is independent of/dev/hda1. Therefore, grub/splash.xpm.gz in/dev/hda1 is written here! Think about it. What will happen if your/boot directory is not a separate split slot?
    • Hiddenmenu
      In this case, do you want to display the menu at startup? Currently, CentOS does not display menus by default. If you want to display menus, comment out the configuration value!

    The overall configuration is probably like this, while the title below shows the startup configuration item.

    • Root: indicates the partition where the core file is placed, not the root directory! Don't make a mistake! /Boot is generally independent of/dev/hda1, so the disk code is (hd0, 0.
    • Kernel: the Core File Name is followed by the kernel, and the file name is followed by the core parameter. Since the root directory needs to be mounted during startup, the root =/dev/mapper/VolGroup-lv_root followed by the kernel refers to the meaning of "Which partition is the root directory of Linux.
    • Initrd: the file name of the RAM Disk created by initrd!
Solution to forgetting the root password

What should I do if I forget the root password? In fact, in Linux, the root password can still be saved when it is forgotten! As long as you can access and mount/, and then reconfigure the root password, it will be saved! This is because in the startup process, if the core is forced to enter runlevel 1, a root shell is obtained by default without a password. The whole action is a bit like this:

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.