adinxu
by adinxu
1 分钟 阅读用时

分类

linux基础

**开机流程**

bios/uefi->mbr->bootloader->kernel
其中bios和uefi是位于主板上的固件,它将是开机后第一个启动的程序,当其启动时,将会去分析计算机里面有哪些储存设备,BIOS会依据使用者的设定去取得能够开机的硬盘, 并且到该硬盘里面去读取第一个扇区的 MBR 位置,从而取得开机管理程序.

u盘方式安装系统时会先进bios把u盘启动改为最高优先级,重启后就能进u盘里刻录好的系统安装程序了

像linux的grub就是一种bootloader,bootloader的功能有:

**kernel基本组成**

1.内存管理
2.任务调度
3.硬件驱动
4.文件系统
5.shell

**login shell启动流程**

shell 启动
有一个框里有三个文件,先找到那个读哪个,应该是兼容问题吧..
其中:

文件 .

|——

/etc/profile login shell 才会读 ~/.bash_profile那三个之一 login shell 才会读 ~/.bashrc non-login shell 会读

一些有用的文件


文件 作用

|——

/etc/issue, /etc/motd bash 的进站与欢迎讯息 /etc/man_db.conf man page搜索的路径 ~/.bash_history 历史命令 ~/.bash_logout 注销shell执行 /etc/modules-load.d/*.conf 想要内核加载的模块 /etc/modprobe.d/*.conf 模块参数配置 /lib/modules/version/kernel 或 /lib/modules/$(uname -r)/kernel 模块位置 `注` /lib/modules/$(uname -r)/modules.dep 记录加载模块间依赖性;`depmod`可更新此文件 etc/default/grub grub环境配置文件 /etc/grub.d 结合grub配置文件产生/boot/grub/grub.cfg /boot/grub/grub.cfg 真正的grub配置文件

:模块(驱动)的文件后缀名一般为.ko(kernel object)

**系统守护进程与服务**

服务(service):常驻在内存中的程序,且可以提供一些系统或网络功能
守护进程(daemon):完成服务的程序??
这两个不必仔细区分(真的吗。。感觉好像不是一个东东。。)
据说System V的机制被废弃了,但还是有一部分init脚本处理方式被留下来了,位置在/etc/init.d下:
如下:
这里写图片描述

这些服务的操作(daemon代表脚本名字):

lrwxrwxrwx 1 root root 20 5月  16 23:21 /sbin/init -> /lib/systemd/systemd

而现今通过init启动脚本来开机的方式已经被废弃不用了,改用 systemd (system daemon)这个启动服务管理机制,systemd仅通过systemctl就可以完成所有控制~。systemd将过去的daemon执行脚本都称为unit,并将unit进行了分类,主要类型如下:

service:文件后缀为.service,用于定义系统服务;
socket:文件后缀为.socket,用于标识进程间通信使用的socket文件;
target:文件后缀.target,用于模拟实现“运行级别”;
snapshot:文件后缀.snapshot,用于管理系统快照;
device:文件后缀.device,用于定义内核识别的设备;
mount:文件后缀.mount,用于定义文件系统挂载点;
automount:文件后缀.automount,用于定义文件系统的自动挂载点;
swap:文件后缀.swap,用于标识swap设备;
timer:文件后缀.timer,用于管理计划任务;
path:文件后缀.path,用于根据文件系统上特定对象的变化来启动其他服务;
slice:文件后缀.slice,用于资源管理;
scope:文件后缀.scope,用于外部创建的进程;

unit主要保存在:

1、/lib/systemd/systemd
2、/run/systemd/system
3、/etc/systemd/system

还有就是有一个target的概念,它就相当于systemV 的 init 的 runlevel,执行某个 target 就是执行好多个daemon脚本。。。
比如去文字界面:

systemctl isolate multi-user.target

返回图形界面:

systemctl isolate graphical.target

**日志文件系统**

日志就是用来记录系统产生的各种消息的,而完成日志信息记录到日志文件靠的是rsyslog.service,就是靠这个服务各种日志信息得以记录。。一般来说日志都会在/var/log下,但不同发行版关于日志文件命名可能不同,可以查看rsyslogd 这个 daemon的配置文件,位于/etc/rsyslog.conf,如下:

#  /etc/rsyslog.conf    Configuration file for rsyslog.
#
#           For more information see
#           /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html
#
#  Default logging rules can be found in /etc/rsyslog.d/50-default.conf

...
省略
#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf

好吧,接着找:

#  Default rules for rsyslog.
#
#           For more information see rsyslog.conf(5) and /etc/rsyslog.conf

#
# First some standard log files.  Log by facility.
#
auth,authpriv.*         /var/log/auth.log
*.*;auth,authpriv.none      -/var/log/syslog
#cron.*             /var/log/cron.log
#daemon.*           -/var/log/daemon.log
kern.*              -/var/log/kern.log
#lpr.*              -/var/log/lpr.log
mail.*              -/var/log/mail.log
#user.*             -/var/log/user.log

#
# Logging for the mail system.  Split it up so that
# it is easy to write scripts to parse these files.
#
#mail.info          -/var/log/mail.info
#mail.warn          -/var/log/mail.warn
mail.err            /var/log/mail.err

#
# Some "catch-all" log files.
#
#*.=debug;\
#   auth,authpriv.none;\
#   news.none;mail.none -/var/log/debug
#*.=info;*.=notice;*.=warn;\
#   auth,authpriv.none;\
#   cron,daemon.none;\
#   mail,news.none      -/var/log/messages

#
# Emergencies are sent to everybody logged in.
#
*.emerg             :omusrmsg:*

#
# I like to have messages displayed on the console, but only on a virtual
# console I usually leave idle.
#
#daemon,mail.*;\
#   news.=crit;news.=err;news.=notice;\
#   *.=debug;*.=info;\
#   *.=notice;*.=warn   /dev/tty8

由此,各种日志的存放位置就清楚了