Introduction to Linux & Boot Process

Introduction

             Linux is a set of open source UNIX-like operating systems that are free to use and freely disseminated. The English explanation is:  Linux is not Unix . It was written in 1991 by Linus Torvalds as a personal hobby when he was a student at the University of Helsinki, and was mainly inspired by the ideas of Minix and Unix.

             Linux can run major UNIX software tools, applications and network protocols. It supports 32-bit and 64-bit hardware. Linux inherits the network-centric design philosophy of Unix and is a multi-user network operating system with stable performance.

             Linux follows the GNU General Public License (GPL). Since Linux is open source free software, any individual or institution can freely use all the underlying source code of Linux, modify and redistribute a Linux distribution that meets their own needs.

Linux distribution

             To put it simply, a Linux distribution is a package of the Linux kernel and application software. The more well-known distributions currently on the market include: Ubuntu, RedHat, CentOS, Debian, Fedora, SuSE, OpenSUSE, Arch Linux, SolusOS, etc.

System startup process

             During the startup process of the Linux system, you will see a lot of startup information, but it is not as complicated as imagined. The process can be divided into 5 stages:

  • Kernel boot.
  • Run init.
  • system initialization.
  • Create a terminal.
  • User logs into the system.

kernel boot

             When the computer is powered on, it first performs a BIOS power-on self-test and starts according to the startup device (usually a hard disk) set in the BIOS.

             After the operating system takes over the hardware, it first reads the kernel file in the /boot directory.

run init

             The init process is the starting point for all processes in the system. Without this process, no process in the system will start.

             The init program first needs to read the configuration file /etc/inittab. Type of init program:

  • SysV:  init, before CentOS 5, configuration file: /etc/inittab.
  • Upstart:  init, CentOS 6, configuration files: /etc/inittab, /etc/init/*.conf.
  • Systemd:  systemd, CentOS 7, configuration files: /usr/lib/systemd/system, /etc/systemd/system.

runlevel

             Many programs require booting. They are called "services" in Windows and "daemons" in Linux. A major task of the init process is to run these programs that are started at boot. However, different programs need to be started in different situations. For example, when used as a server, Apache (Apache Web server software) needs to be started, but when used as a desktop, it is not required.

             Linux allows allocating different boot programs for different occasions, which is called run level . That is to say, based on the "run level" at startup, which programs are determined to be run.

             Linux systems have 7 runlevels:

  • Run level 0: The system is in shutdown state. The default run level of the system cannot be set to 0, otherwise it will not start normally.
  • Run level 1: single-user working state, root authority, used for system maintenance, remote login is prohibited
  • Runlevel 2: Multi-user state (no NFS)
  • Run level 3: Complete multi-user state (with NFS), enter console command line mode after logging in
  • Run level 4: System is not in use, reserved
  • Run level 5: X11 console, enter graphical GUI mode after logging in
  • Run level 6: The system shuts down and restarts normally. The default run level cannot be set to 6, otherwise it cannot start normally.

system initialization

             There is this line in the init configuration file:

 si::sysinit:/etc/rc.d/rc.sysinit

             It calls and executes /etc/rc.d/rc.sysinit. rc.sysinit is a bash shell script. It mainly completes some system initialization work. rc.sysinit is an important script that must be run first at every run level. , its main tasks are: activating the swap partition, checking the disk, loading hardware modules and other tasks that need to be performed first.

l5:5:wait:/etc/rc.d/rc 5

             This line means running /etc/rc.d/rc with 5 as the parameter. /etc/rc.d/rc is a Shell script that accepts 5 as the parameter to execute the /etc/rc.d/rc5.d/ directory. All rc startup scripts in the /etc/rc.d/rc5.d/ directory are actually connection files, not real rc startup scripts. The real rc startup scripts are actually Place it in the /etc/rc.d/init.d/ directory. These rc startup scripts have similar usage. They generally accept parameters such as start, stop, restart, status, etc.

             The rc startup script in /etc/rc.d/rc5.d/ is usually a connection file starting with K or S. For startup scripts starting with S, it will be run with the start parameter. If it is found that there is a corresponding script and a connection starting with K, and it is already in the running state (using the file under /var/lock/subsys/ as a sign), these started daemons will be stopped first with stop as the parameter. process and then run it again. This is done to ensure that when init changes run levels, all related daemons will be restarted.

             As for which daemons will be run in each run level, users can set it themselves through "System Services" in chkconfig or setup.

Create a terminal

             After rc is executed, return to init. At this time, the basic system environment has been set up and various daemon processes have been started. init will then open 6 terminals so that users can log in to the system. The following 6 lines in inittab define 6 terminals:

1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6

             As can be seen from the above, the mingetty program will be run in respawn mode in run levels 2, 3, 4, and 5. The mingetty program can open the terminal and set the mode. At the same time, it will display a text login interface, which is the login interface we often see. In this login interface, the user will be prompted to enter a user name, and the user entered by the user will be passed as a parameter to the login program to verify the user's identity.

User login system

             Generally speaking, there are three ways for users to log in:

  • Command line login
  • ssh login
  • Graphical interface login

             For graphical users running level 5, login is through a graphical login interface. After successful login, you can directly enter window managers such as KDE and Gnome.

             This article mainly talks about text-based login: when you see the mingetty login interface, you can enter your username and password to log in to the system. The Linux account verification program is login. Login will receive the user name sent by mingetty as the user name parameter. Then login will analyze the user name: if the user name is not root and the /etc/nologin file exists, login will output the contents of the nologin file and then exit. This is usually used to prevent non-root users from logging in during system maintenance. Only terminals registered in /etc/securetty allow the root user to log in. If this file does not exist, the root user can log in on any terminal. The /etc/usertty file is used to impose additional access restrictions on users. If this file does not exist, there are no other restrictions.

How to switch between graphics mode and text mode

             Linux default provides six command window terminals for us to log in to. The default login is the first window, which is tty1. The six windows are tty1, tty2...tty6. You can press Ctrl + Alt + F1 ~ F6 to switch them.

             If you have installed a graphical interface, you will enter the graphical interface by default. At this time, you can press Ctrl + Alt + F1 ~ F6 to enter one of the command window interfaces.

             When you enter the command window interface and return to the graphical interface, just press Ctrl + Alt + F7 to come back.

             If you are using a vmware virtual machine, the shortcut key for switching the command window is Alt + Space + F1~F6. If you are in a graphical interface, please press Alt + Shift + Ctrl + F1~F6 to switch to the command window.

Linux shutdown

             In the field of Linux, it is mostly used on servers, and shutdown operations are rarely encountered. After all, there is no end to running a service on the server. Unless under special circumstances, it will be shut down as a last resort.

             The correct shutdown process is: sync > shutdown > reboot > halt

sync 将数据由内存同步到硬盘中

             The shutdown command is: shutdown. You can enter the command: man shutdown to see the help document.

             For example, you can run the following command to shut down:

shutdown 关机指令,可以使用:man shutdown 来查看帮助文档。例如:

shutdown –h 10     // 计算机将在10分钟后关机,并且会显示在登陆用户的当前屏幕中。
shutdown –h 20:25  // 系统会在今天20:25关机
shutdown –h +10    // 十分钟后关机
shutdown -c        // 取消即将进行的关机
shutdown –h now    // 立马关机
shutdown –r now    // 系统立马重启
shutdown –r +10    // 系统十分钟后重启
init 0             // 立马关机
init 6             // 系统立马重启
reboot             // 重启,等同于:shutdown –r now
halt               // 关闭系统,发送一个 ACPI 信号来通知系统关机。等同于:shutdown –h now 和 poweroff

             Note: Whether you restart the system or shut down the system, you must first run  the sync  command to write the data in the memory to the disk.

Replenish

             Several shortcut keys that are sometimes useful;

Tab

[Tab]      // 接在一串指令的第一个字的后面,则为『命令补全』
[Tab]      // 接在一串指令的第二个字以后时,则为『文件补齐』

             If you install the bash-completion software, you can perform the "option/parameter completion" function when using the [tab] key after certain instructions!

Ctrl + C

             If you enter an incorrect command or parameter under Linux and want to stop the current program, you can enter: Ctrl + c.

Ctrl + d

             The meaning of keyboard input end (End Of File, EOF or End Of Input) is equivalent to typing exit. For example, if you want to leave the terminal window directly, you can press: Ctrl + d

shift +  PageUP / Page Down 

Shift + Page Up     // 往前翻页
Shift + Page Down   // 往后翻页

Guess you like

Origin blog.csdn.net/weixin_60461563/article/details/132890237