CentOS8 Linux系统启动过程探秘

菜鸟教程当中的Linux包括Linux相关的mysql等教程已经与现有版本有所差异,实际使用还是要以官方的Document为准。

系统版本:CentOS 8

LINUX的启动过程被分为

  1. 内核引导
  2. init运行
  3. 系统初始化
  4. 建立终端
  5. 用户登录

1.内核引导

通过BIOS引导将硬件控制权移交给Operating System(LINUX),Linux读取 /root下的内容

boot目录当中的所有内传递容(参考此处:https://blog.csdn.net/dulin201004/article/details/7396968

[root@localhost boot]# ls -l
total 188992
-rw-r--r--. 1 root root   187648 May  8 19:07 config-4.18.0-193.el8.x86_64 # Kernel Config
drwxr-xr-x. 3 root root     4096 Sep 13 19:01 efi
drwx------. 4 root root     4096 Sep 27 12:32 grub2 # GRUB (GRand Unified Bootloader -- GNU)
-rw-------. 1 root root 98497217 Sep 13 19:10 initramfs-0-rescue-93ba7aa1b0e04b168569886f86cc6b0e.img # Kernel-rescue initramfs img
-rw-------. 1 root root 53410540 Sep 13 19:13 initramfs-4.18.0-193.el8.x86_64.img # Kernel initramfs img
-rw-------. 1 root root 19650613 Sep 13 19:30 initramfs-4.18.0-193.el8.x86_64kdump.img # Kernel initramfs img
drwxr-xr-x. 3 root root     4096 Sep 13 19:06 loader
drwx------. 2 root root    16384 Sep 13 18:59 lost+found
-rw-------. 1 root root  3909996 May  8 19:07 System.map-4.18.0-193.el8.x86_64
-rwxr-xr-x. 1 root root  8913656 Sep 13 19:08 vmlinuz-0-rescue-93ba7aa1b0e04b168569886f86cc6b0e # Kernel-rescue
-rwxr-xr-x. 1 root root  8913656 May  8 19:07 vmlinuz-4.18.0-193.el8.x86_64 # Kernel

config -x.xx:Kernel config 配置文件

grubx:GRUBGRand Unified Bootloader简称“GRUB”)是一个来自GNU项目的多操作系统启动程序

initramfs:(ramfs,rootfs等详解)初始化ramfs(文件系统),initramfs的前身是initrd

System.map:

NOTE:Ramfs是什么?通过使用盘缓冲机制来创造一个类似RAM文件系统的文件系统

Ramfs is a very simple filesystem that exports Linux’s disk caching mechanisms (the page cache and dentry cache) as a dynamically resizable RAM-based filesystem.

通过 ramfs可以让linux本身的盘缓冲机制导出为一个动态可变得ram的文件系统

Normally all files are cached in memory by Linux. Pages of data read from backing store (usually the block device the filesystem is mounted on) are kept around in case it’s needed again, but marked as clean (freeable) in case the Virtual Memory system needs the memory for something else. Similarly, data written to files is marked clean as soon as it has been written to backing store, but kept around for caching purposes until the VM reallocates the memory. A similar mechanism (the dentry cache) greatly speeds up access to directories.

Files或Dentry的缓存通常会从backing store读取,并暂存以防再次使用。但会由于某种内存原因而被mark为可清除。

With ramfs, there is no backing store. Files written into ramfs allocate dentries and page cache as usual, but there’s nowhere to write them to. This means the pages are never marked clean, so they can’t be freed by the VM when it’s looking to recycle memory.

使用ramfs,即不再有backing store了。也就没有地方可以被标志clean。

The amount of code required to implement ramfs is tiny, because all the work is done by the existing Linux caching infrastructure. Basically, you’re mounting the disk cache as a filesystem. Because of this, ramfs is not an optional component removable via menuconfig, since there would be negligible space savings.

这样做,实现ramfs的代码是很少的,因为基本上还是再利用盘缓冲作为一个filesystem,并由于空间本身占有少,ramfs也无法从menuconfig当中作为可选项被移除。

 Initramfs是什么?https://www.cnblogs.com/tongyishu/p/12085153.html

All 2.6 Linux kernels contain a gzipped “cpio” format archive, which is extracted into rootfs when the kernel boots up.

Initramfs会被提取到rootfs当中,当内核启动时,随后内核检查rootfs当中是否包含init文件,并将其作为PID 1来执行。随后Init负责系统剩余项的启动。

 2. Init启动

新版本的inittab不再使用,转而使用systemd来设置 ->https://blog.csdn.net/frank_good/article/details/47724897

 

 

即通过systemd进程来替代原先的service同时包括了开机时的init。systemctl用来设置操控systemd

同样的init 0 1 2 3 4 5 6也分别对应如下

在 /usr/lib/systemd/system

例如 原始的init 5 -> graphic.target

3.系统初始化

查看原先inittab文件当中引导的/etc/rc.d/init.d当中的README文件,其中描述传统init.d当中的scripts已经被移除,取而代之通过systemctl来运行,同样的,如果需要在开机时使用打开service,可以自行编写systemctl的service来实现。

即第二步的init和第三步的初始化过程被合并到了systemctl当中去了。

4.生成终端并登录

tty是什么?https://blog.csdn.net/fuhanghang/article/details/83691158

基本概念:

1> tty(终端设备的统称):
       tty一词源于Teletypes,或teletypewriters,原来指的是电传打字机,是通过串行线用打印机键盘通过阅读和发送信息的东西,后来这东西被键盘和显示器取代,所以现在叫终端比较合适。
       终端是一种字符型设备,他有多种类型,通常使用tty来简称各种类型的终端设备。
2> pty(虚拟终端):
       但是假如我们远程telnet到主机或使用xterm时不也需要一个终端交互么?是的,这就是虚拟终端pty(pseudo-tty)
3> pts/ptmx(pts/ptmx结合使用,进而实现pty:
       pts(pseudo-terminal slave)是pty的实现方法,和ptmx(pseudo-terminal master)配合使用实现pty。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值