Linux Grub, Linux runlevel, terminal mode login

First, what is Grub?

The full name of Grub is Grand Unified Bootloader, and grub can boot multiple operating systems.

When the boot button is pressed, the chassis will emit a drip, which indicates that BIOS has completed the boot self-check and the hardware is normal.

Next, BIOS will read 512 bytes of data from 0 cylinder, 0 track and 1 sector of hard disk by default to boot the system. However, because the grub program is very large, the start-up process of Grub is divided into two steps:

Firstly, stage 1 is used as the main boot program to locate and load the second stage program and transfer control to stage 2.

Then, it's stage 2.


Grub files are placed under the / boot/grub directory. There is a stage 1, which is 512 bytes in size and just a sector large. This stage 1 is a copy of MBR, and MBR is the master boot record. For example, when using the U disk as a system, first write the master boot record to the U disk, and then burn the iso file.

In addition, you can see a stage 2, which is a larger program to be loaded by stage 1.

Other xxxx_stage 1_5 files, if you look carefully and find that xxx are: e2fs, fat, ffs, jfs, minix, reiserfs, ufs2, vstafs, xfs are all driver files of various file systems, because stage 2 files may be stored in different file systems, so when stage 1 reads stage 2, it will It will determine what file system stage 2 is, and then read stage 2 through this driver.

  1. [root@ggg2 Desktop]# ls -al /boot/grub  
  2. total 284  
  3. drwxr-xr-x. 2 root root   1024 Aug 18 23:52 .  
  4. dr-xr-xr-x. 5 root root   1024 Aug 18 23:50 ..  
  5. -rw-r--r--. 1 root root     63 Aug 18 23:21 device.map  
  6. -rw-r--r--. 1 root root  13396 Aug 18 23:21 e2fs_stage1_5  
  7. -rw-r--r--. 1 root root  12636 Aug 18 23:21 fat_stage1_5  
  8. -rw-r--r--. 1 root root  11780 Aug 18 23:21 ffs_stage1_5  
  9. -rw-------. 1 root root    771 Aug 18 23:52 grub.conf  
  10. -rw-r--r--. 1 root root  11772 Aug 18 23:21 iso9660_stage1_5  
  11. -rw-r--r--. 1 root root  13284 Aug 18 23:21 jfs_stage1_5  
  12. lrwxrwxrwx. 1 root root     11 Aug 18 23:21 menu.lst -> ./grub.conf  
  13. -rw-r--r--. 1 root root  11972 Aug 18 23:21 minix_stage1_5  
  14. -rw-r--r--. 1 root root  14428 Aug 18 23:21 reiserfs_stage1_5  
  15. -rw-r--r--. 1 root root   1341 Nov 15  2010 splash.xpm.gz  
  16. -rw-r--r--. 1 root root    512 Aug 18 23:21 stage1  
  17. -rw-r--r--. 1 root root 126116 Aug 18 23:21 stage2  
  18. -rw-r--r--. 1 root root  12040 Aug 18 23:21 ufs2_stage1_5  
  19. -rw-r--r--. 1 root root  11380 Aug 18 23:21 vstafs_stage1_5  
  20. -rw-r--r--. 1 root root  13980 Aug 18 23:21 xfs_stage1_5  
  21. [root@ggg2 Desktop]#   

Next, you can see that there is a link file menu.lst, which links to grub.conf in the same directory. This is the configuration file of grub, that is, / boot/grub/grub.conf. If you modify this file, it will directly affect the next boot.

The content of this document:

  1. [root@ggg2 Desktop]# cat /boot/grub/grub.conf  
  2. # grub.conf generated by anaconda  
  3. #  
  4. # Note that you do not have to rerun grub after making changes to this file  
  5. # NOTICE:  You have a /boot partition.  This means that  
  6. #          all kernel and initrd paths are relative to /boot/, eg.  
  7. #          root (hd0,0)  
  8. #          kernel /vmlinuz-version ro root=/dev/sda3  
  9. #          initrd /initrd-[generic-]version.img  
  10. #boot=/dev/sda  
  11. default=0  
  12. timeout=5  
  13. splashimage=(hd0,0)/grub/splash.xpm.gz  
  14. hiddenmenu  
  15. title CentOS 6 (2.6.32-504.el6.x86_64)  
  16.     root (hd0,0)  
  17.     kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=c1fa03c8-abf9-4d89-a8e0-4571c69955e0 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=128M  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet  
  18.     initrd /initramfs-2.6.32-504.el6.x86_64.img  
  19. [root@ggg2 Desktop]#   

Among them:

default=0: The default starts with the first title (here starting from 0), and if windows is installed first on the machine and then linux is installed, there will be two titles.

2. timeout=5: There are 5 seconds to select the title to start by the up and down keys. Actually, it's also in windows.That's the boot.ini file.

splashimage: This is the image that the boot is displayed. If it is a sata disk, the first disk is sda, the second disk is sdb, and the first partition of the first disk is sda1, and the second partition is sda2, so (hd0, 0)/grub/splash.x Pm.gz is / sda1/grub/splash.xpm.gz, that is, / boot/grub/splash.xpm.gz.

This file is a compressed file, which is decompressed at startup.

3. hiddenmenu: Start the standard menu interface that does not display grub.

4. titile: The name of the system to boot.

5. root (hd0,0): denotes the partition in which the kernel resides.

6. Kernel/vmlinuz-2.6.32-504.el6.x86_64: is the / boot/vmlinuz-2.6.32-504.el6.x86_64 file that specifies the path of the kernel, i.e. (hd0,0) partition.

7. RO root=UUID=c1fa03c8-abf9-4d89-a8e0-4571c69955e0 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8rd_NO_MD SYSFONT=arcyrheb-sun16 crash kernel=128M KEYBOARDTYPE=pc KEYTABLE=us_rd_NO_rhgb quiet: It is a parameter that is passed into the inner core.

8. initrd/initramfs-2.6.32-504.el6.x86_64.img: specify the path of initrd file, initrd is boot loader initialized RAM disk, boot loader initialized RAM disk, is the memory disk used for initialization, the temporary file system at system start-up, the kernel through initrd to obtain various device drivers, executable files, and then go to hang. Load the read real file system, and then uninstall the temporary file system, but in many embedded systems, initrd is used directly as an official file system.


Second, what is the operating level of Linux?

There are seven levels of operation: rd0-rd7.

When bios completes the boot-up self-check, it loads mbr, stage 1 above, and the control is transferred to Grub.

Next stage 1 loads the file system driver, such as xxx_stage 1_5, through initrd temporary file system, through which stage 2 is read.

Then stage 2 loads the linux kernel vmlinuz, and then the kernel vmlinuz loads / sbin/init.

And / sbin/init will be initialized according to / etc/inittab, which holds the linux runlevel:

  1. [root@ggg2 Desktop]# cat /etc/inittab  
  2. # inittab is only used by upstart for the default runlevel.  
  3. #  
  4. # ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.  
  5. #  
  6. # System initialization is started by /etc/init/rcS.conf  
  7. #  
  8. # Individual runlevels are started by /etc/init/rc.conf  
  9. #  
  10. # Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf  
  11. #  
  12. # Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,  
  13. # with configuration in /etc/sysconfig/init.  
  14. #  
  15. # For information on how to write upstart event handlers, or how  
  16. # upstart works, see init(5), init(8), and initctl(8).  
  17. #  
  18. # Default runlevel. The runlevels used are:  
  19. #   0 - halt (Do NOT set initdefault to this)  
  20. #   1 - Single user mode  
  21. #   2 - Multiuser, without NFS (The same as 3, if you do not have networking)  
  22. #   3 - Full multiuser mode  
  23. #   4 - unused  
  24. #   5 - X11  
  25. #   6 - reboot (Do NOT set initdefault to this)  
  26. #   
  27. id:5:initdefault:  
  28. [root@ggg2 Desktop]#   

That is to say:

Running level 0: System downtime status, the default operating level of the system can not be set to 0, otherwise it can not start normally.

Running Level 1: Single user working status, root authority, for system maintenance, prohibit remote login

Run Level 2: Multiuser Status (No NFS)
Run Level 3: Complete Multiuser Status (with NFS), Enter Console Command Line Mode after login
Run Level 4: System Not Used, Reserved
Running Level 5:X11 Console, Enter Graphic GUI Mode after Login
Run Level 6: The system shuts down and restarts normally. The default run level cannot be set to 6, otherwise it cannot start normally.


Terminal mode landing

After going through the above two stages, you can login to the system.

By default, linux has six terminals, using the combination key ctrl+alt+F1, you can enter the first terminal, and so on.

And the terminal is called tty, that is, tty1-tty6.


Press CTRL+ALT+F2 and enter the second terminal, tty2, as shown below:


The contents are as follows:

1. The name and version number of the distribution.

2. Kernel version and hardware platform.

3. Host name ggg2.

4. login: Wait for the user name to be entered, where root is entered.

5. password: It is prompted to enter a password.

6. Last Login: It shows the time of the last landing and which tty it was.

7. [root@ggg2 ~]#: root denotes the login user name, ggg2 is the host name, ~denotes the current user's home directory, # denotes that the current user is a super-privileged user root user, and if it is an ordinary user, $.


In addition, by modifying the content of / etc/issue, different text can be displayed when landing at the terminal.

A line "Hello, Linux!" was added at the end. :



Then, after entering exit, it enters tty again, as shown below:

Keywords: Linux Windows Anaconda CentOS

Added by craigbabe on Wed, 17 Jul 2019 01:32:50 +0300