Linux的系统启动流程
Linux的系統啟動流程
- 一、systemd進程介紹
- 1.systemd服務介紹
- 2.systemd功能
- 3.服務單元
- 3.查看以激活狀態的服務單元
- 4.查看服務之間的依賴關系
- 二、Linux的運行級別
- 1.運行級別
- 2.target類型
- 3.查看當前系統默認啟動的運行目標
- 4.切換當前運行目標
- 三、系統啟動內核
- 1.查看默認內核啟動項信息
- 2.修改內核的默認啟動項
- 1.根據開機啟動菜單欄索引號
- 2.根據綁定特定的內核版本
- 3.修改內核啟動參數
- 1.采用VIM編輯方式
- 2.采用命令修改方式
- 四、Linux系統啟動流程
- 1.BIOS初始化過程
- 2.grub階段
- 五、系統重要文件查看
- 1./sbin/init
- 2.系統啟動的內核
- 3.系統的內核源代碼文件
- 4.內核的信息文件
- 5.grub2的信息文件
一、systemd進程介紹
1.systemd服務介紹
systemd守護進程管理Linux的啟動,一般包括服務啟動和服務管理,它可以在系統引導時以及運行中的系統激活系統的資源、服務器守護進程和其他進程。
2.systemd功能
①并行化功能,同時啟動多個服務,可以提高系統的啟動速度。
②按需啟動激活進程
③自動服務依賴管理
3.服務單元
列出所有的服務單元
[root@tianyi ~]# systemctl list-units --type=service UNIT LOAD ACTIVE SUB DESCRIPTION atd.service loaded active running Job spooling tools auditd.service loaded active running Security Auditing Service cloud-config.service loaded active exited Apply the settings specified in cloud-config cloud-final.service loaded active exited Execute cloud user/final scripts cloud-init-local.service loaded active exited Initial cloud-init job (pre-networking) cloud-init.service loaded active exited Initial cloud-init job (metadata service crawler) cloudResetPwdUpdateAgent.service loaded active running cloudResetPwdUpdateAgent crond.service loaded active running Command Scheduler dbus.service loaded active running D-Bus System Message Bus denyhosts.service loaded active running SYSV: Activates/Deactivates the dracut-shutdown.service loaded active exited Restore /run/initramfs on shutdown firewalld.service loaded active running firewalld - dynamic firewall daemon getty@tty1.service loaded active running Getty on tty1 httpd.service loaded active running The Apache HTTP Server import-state.service loaded active exited Import network configuration from initramfs iscsi-shutdown.service loaded active exited Logout off all iSCSI sessions on shutdown kdump.service loaded active exited Crash recovery kernel arming kmod-static-nodes.service loaded active exited Create list of required static device nodes for the current kernel libstoragemgmt.service loaded active running libstoragemgmt plug-in server daemon lvm2-monitor.service loaded active exited Monitoring of LVM2 mirrors, snapshots etc. using dmeventd or progress polling mcelog.service loaded active running Machine Check Exception Logging Daemon multi-queue-hw.service loaded active exited LSB: NIC multiple queues init mysqld.service loaded active running MySQL 8.0 database server NetworkManager-wait-online.service loaded active exited Network Manager Wait Online NetworkManager.service loaded active running Network Manager nis-domainname.service loaded active exited Read and set NIS domainname from /etc/sysconfig/network php-fpm.service loaded active running The PHP FastCGI Process Manager polkit.service loaded active running Authorization Manager qemu-guest-agent.service loaded active running QEMU Guest Agent rngd.service loaded active running Hardware RNG Entropy Gatherer Daemon rsyslog.service loaded active running System Logging Service smartd.service loaded active running Self Monitoring and Reporting Technology (SMART) DaemonUNIT :服務單元的名稱
LOAD :systemd是否正確解析了單元的配置,并將該單元加載到內存中
ACTIVE:單元的高級別激活狀態,此信息表明單元是否正常啟動。
SUB:單元的低級別激活狀態,信息視單元類型、狀態以及單元執行方式而異。
3.查看以激活狀態的服務單元
[root@tianyi ~]# systemctl list-unit-files --type=service UNIT FILE STATE arp-ethers.service disabled atd.service enabled auditd.service enabled autovt@.service enabled blk-availability.service disabled bolt.service static chrony-dnssrv@.service static chrony-wait.service disabled chronyd.service disabled clean-mount-point@.service static cloud-config.service enabled cloud-final.service enabled cloud-init-local.service enabled cloud-init.service enabled cloudResetPwdAgent.service enabled cloudResetPwdUpdateAgent.service enabled cockpit-motd.service static cockpit.service static console-getty.service disabled container-getty@.service static cpupower.service disabled crond.service enabled dbus-org.fedoraproject.FirewallD1.service enabled dbus-org.freedesktop.hostname1.service static dbus-org.freedesktop.locale1.service static dbus-org.freedesktop.login1.service static dbus-org.freedesktop.NetworkManager.service enabled dbus-org.freedesktop.nm-dispatcher.service enabled dbus-org.freedesktop.portable1.service static dbus-org.freedesktop.timedate1.service enabled4.查看服務之間的依賴關系
[root@tianyi ~]# systemctl list-dependencies httpd httpd.service ● ├─-.mount ● ├─httpd-init.service ● ├─php-fpm.service ● ├─system.slice ● └─sysinit.target ● ├─dev-hugepages.mount ● ├─dev-mqueue.mount ● ├─dracut-shutdown.service ● ├─import-state.service ● ├─iscsi.service ● ├─kmod-static-nodes.service ● ├─ldconfig.service ● ├─loadmodules.service ● ├─lvm2-lvmpolld.socket ● ├─lvm2-monitor.service ● ├─multipathd.service ● ├─nis-domainname.service ● ├─plymouth-read-write.service ● ├─plymouth-start.service ● ├─proc-sys-fs-binfmt_misc.automount ● ├─rngd.service ● ├─selinux-autorelabel-mark.service ● ├─sys-fs-fuse-connections.mount ● ├─sys-kernel-config.mount ● ├─sys-kernel-debug.mount ● ├─systemd-ask-password-console.path ● ├─systemd-binfmt.service ● ├─systemd-firstboot.service ● ├─systemd-hwdb-update.service ● ├─systemd-journal-catalog-update.service ● ├─systemd-journal-flush.service ● ├─systemd-journald.service ● ├─systemd-machine-id-commit.service ● ├─systemd-modules-load.service ● ├─systemd-random-seed.service ● ├─systemd-sysctl.service ● ├─systemd-sysusers.service ● ├─systemd-tmpfiles-setup-dev.service ● ├─systemd-tmpfiles-setup.service ● ├─systemd-udev-trigger.service ● ├─systemd-udevd.service ● ├─systemd-update-done.service二、Linux的運行級別
1.運行級別
REL6.0及之前版本的定義————
0:關機,停機模式
1:單用戶模式
2:多用戶模式
3:完整的多用戶文本模式
4:系統未使用,保留一般不用
5:圖形化模式
6:重啟模式
運行級就是操作系統當前正在運行的功能級別。這個級別從0到6,具有不同的功能。
2.target類型
RHEL8.0新版本————
graphical.target:系統支持多用戶、圖形和基于文本登錄。
multi-user.target:系統支持多用戶和基于文本登錄。
rescue.target:系統初始化以完成,需要root登錄。
emergency.target:只讀掛載根文件系統,需要root權限。
3.查看當前系統默認啟動的運行目標
[root@tianyi ~]# systemctl get-default multi-user.target4.切換當前運行目標
[root@tianyi ~]# systemctl set-default multi-user.target [root@tianyi ~]# systemctl get-default multi-user.target三、系統啟動內核
1.查看默認內核啟動項信息
[root@control ~]# grubby --default-kernel /boot/vmlinuz-4.18.0-80.el8.x86_64 [root@control ~]# grubby --info=/boot/vmlinuz-4.18.0-80.el8.x86_64 index=0 kernel="/boot/vmlinuz-4.18.0-80.el8.x86_64" args="ro resume=UUID=2f261207-03e5-47d7-ac83-9a4424fb6f74 rhgb quiet $tuned_params" root="UUID=11568b58-6451-40da-a59f-7da0c2536cd3" initrd="/boot/initramfs-4.18.0-80.el8.x86_64.img $tuned_initrd" title="Red Hat Enterprise Linux (4.18.0-80.el8.x86_64) 8.0 (Ootpa)" id="043c7535dbf0487cbd536e7ea6413864-4.18.0-80.el8.x86_64"2.修改內核的默認啟動項
1.根據開機啟動菜單欄索引號
[root@control ~]# grubby --default-index 0 [root@control ~]# grub2-set-default 0 [root@control ~]# grubby --default-index 02.根據綁定特定的內核版本
[root@control boot]# ll total 107080 -rw-r--r--. 1 root root 180942 Mar 13 2019 config-4.18.0-80.el8.x86_64 drwxr-xr-x. 3 root root 17 Dec 8 2020 efi drwx------. 4 root root 83 Mar 2 09:19 grub2 -rw-------. 1 root root 65698603 Dec 8 2020 initramfs-0-rescue-043c7535dbf0487cbd536e7ea6413864.img -rw-------. 1 root root 24257032 Dec 8 2020 initramfs-4.18.0-80.el8.x86_64.img drwxr-xr-x. 3 root root 21 Dec 8 2020 loader -rw-------. 1 root root 3751920 Mar 13 2019 System.map-4.18.0-80.el8.x86_64 -rwxr-xr-x. 1 root root 7872864 Dec 8 2020 vmlinuz-0-rescue-043c7535dbf0487cbd536e7ea6413864 -rwxr-xr-x. 1 root root 7872864 Mar 13 2019 vmlinuz-4.18.0-80.el8.x86_64 [root@control boot]# grubby --set-default /boot/vmlinuz-0-rescue-043c7535dbf0487cbd536e7ea6413864 The default is /boot/loader/entries/043c7535dbf0487cbd536e7ea6413864-0-rescue.conf with index 1 and kernel /boot/vmlinuz-0-rescue-043c7535dbf0487cbd536e7ea6413864 [root@control boot]# grubby --default-kernel /boot/vmlinuz-0-rescue-043c7535dbf0487cbd536e7ea64138643.修改內核啟動參數
1.采用VIM編輯方式
[root@control boot]# cat /etc/default/grub GRUB_TIMEOUT=10 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="resume=UUID=2f261207-03e5-47d7-ac83-9a4424fb6f74 rhgb quiet" GRUB_DISABLE_RECOVERY="true" GRUB_ENABLE_BLSCFG=trueVIM編輯修改需更新grub2配置文件grub2-mkconfig -o /boot/grub2/grub.cfg
2.采用命令修改方式
[root@control boot]# grubby --remove-args="rhgb quiet" --args=console=ttyS0,115200 --update-kernel /boot/vmlinuz-4.18.0-80.el8.x86_64四、Linux系統啟動流程
1.BIOS初始化過程
電腦通電開機,完成硬件初始化。BIOS加電自檢,BIOS進行初始化。
2.grub階段
1.把MBR加載到內存, MBR=512字節=引導程序(446字節)+64字節(分區表)+2字節
2.BIOS加載grub引導程序,系統控制交給引導程序。
3.引導程序加載配置文件/boot/grub2/grub.cfg,告訴/boot目錄所在分區和內核文件在哪,并加載內核和initramfs,并放入內存中。initramfs包含啟動時硬件必要的內核模塊和初始化腳本。
4.Kernel自身初始化,且內核在initramfs中找到所有硬件的驅動程序,初始化這些硬件。
5.initramfs中的/sbin/init以pid為1的進程啟動,并鏈接到systemd。
6.內核將根從initramfs切換到真正的根。
7.啟動第一個程序systemd
五、系統重要文件查看
1./sbin/init
[root@control ~]# ll -ld /sbin/init lrwxrwxrwx. 1 root root 22 Feb 26 2019 /sbin/init -> ../lib/systemd/systemd2.系統啟動的內核
[root@control boot]# pwd /boot [root@control boot]# ll total 107080 -rw-r--r--. 1 root root 180942 Mar 13 2019 config-4.18.0-80.el8.x86_64 drwxr-xr-x. 3 root root 17 Dec 8 2020 efi drwx------. 4 root root 83 Mar 2 09:19 grub2 -rw-------. 1 root root 65698603 Dec 8 2020 initramfs-0-rescue-043c7535dbf0487cbd536e7ea6413864.img -rw-------. 1 root root 24257032 Dec 8 2020 initramfs-4.18.0-80.el8.x86_64.img drwxr-xr-x. 3 root root 21 Dec 8 2020 loader -rw-------. 1 root root 3751920 Mar 13 2019 System.map-4.18.0-80.el8.x86_64 -rwxr-xr-x. 1 root root 7872864 Dec 8 2020 vmlinuz-0-rescue-043c7535dbf0487cbd536e7ea6413864 -rwxr-xr-x. 1 root root 7872864 Mar 13 2019 vmlinuz-4.18.0-80.el8.x86_64 [root@control boot]#3.系統的內核源代碼文件
[root@control kernels]# pwd /usr/src/kernels [root@control kernels]# ll total 8 drwxr-xr-x. 23 root root 4096 Feb 1 14:35 4.18.0-80.el8.x86_64 drwxr-xr-x. 23 root root 4096 Feb 1 14:35 4.18.0-80.el8.x86_64+debug4.內核的信息文件
cat /boot/grub2/grub.cfg # # DO NOT EDIT THIS FILE # # It is automatically generated by grub2-mkconfig using templates # from /etc/grub.d and settings from /etc/default/grub #### BEGIN /etc/grub.d/00_header ### set pager=1if [ -f ${config_directory}/grubenv ]; thenload_env -f ${config_directory}/grubenv elif [ -s $prefix/grubenv ]; thenload_env fi if [ "${next_entry}" ] ; thenset default="${next_entry}"set next_entry=save_env next_entryset boot_once=true elseset default="${saved_entry}" fiif [ x"${feature_menuentry_id}" = xy ]; thenmenuentry_id_option="--id" elsemenuentry_id_option="" fiexport menuentry_id_optionif [ "${prev_saved_entry}" ]; thenset saved_entry="${prev_saved_entry}"save_env saved_entryset prev_saved_entry=save_env prev_saved_entryset boot_once=true fi5.grub2的信息文件
[root@control system]# cat /etc/default/grub GRUB_TIMEOUT=10 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=saved GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="resume=UUID=2f261207-03e5-47d7-ac83-9a4424fb6f74 rhgb quiet" GRUB_DISABLE_RECOVERY="true" GRUB_ENABLE_BLSCFG=true總結
以上是生活随笔為你收集整理的Linux的系统启动流程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python基础之循环语句
- 下一篇: Shell脚本实战之文件批量创建和修改