Linux的系统启动流程
Linux的系統(tǒng)啟動(dòng)流程
- 一、systemd進(jìn)程介紹
- 1.systemd服務(wù)介紹
- 2.systemd功能
- 3.服務(wù)單元
- 3.查看以激活狀態(tài)的服務(wù)單元
- 4.查看服務(wù)之間的依賴關(guān)系
- 二、Linux的運(yùn)行級(jí)別
- 1.運(yùn)行級(jí)別
- 2.target類型
- 3.查看當(dāng)前系統(tǒng)默認(rèn)啟動(dòng)的運(yùn)行目標(biāo)
- 4.切換當(dāng)前運(yùn)行目標(biāo)
- 三、系統(tǒng)啟動(dòng)內(nèi)核
- 1.查看默認(rèn)內(nèi)核啟動(dòng)項(xiàng)信息
- 2.修改內(nèi)核的默認(rèn)啟動(dòng)項(xiàng)
- 1.根據(jù)開機(jī)啟動(dòng)菜單欄索引號(hào)
- 2.根據(jù)綁定特定的內(nèi)核版本
- 3.修改內(nèi)核啟動(dòng)參數(shù)
- 1.采用VIM編輯方式
- 2.采用命令修改方式
- 四、Linux系統(tǒng)啟動(dòng)流程
- 1.BIOS初始化過程
- 2.grub階段
- 五、系統(tǒng)重要文件查看
- 1./sbin/init
- 2.系統(tǒng)啟動(dòng)的內(nèi)核
- 3.系統(tǒng)的內(nèi)核源代碼文件
- 4.內(nèi)核的信息文件
- 5.grub2的信息文件
一、systemd進(jìn)程介紹
1.systemd服務(wù)介紹
systemd守護(hù)進(jìn)程管理Linux的啟動(dòng),一般包括服務(wù)啟動(dòng)和服務(wù)管理,它可以在系統(tǒng)引導(dǎo)時(shí)以及運(yùn)行中的系統(tǒng)激活系統(tǒng)的資源、服務(wù)器守護(hù)進(jìn)程和其他進(jìn)程。
2.systemd功能
①并行化功能,同時(shí)啟動(dòng)多個(gè)服務(wù),可以提高系統(tǒng)的啟動(dòng)速度。
②按需啟動(dòng)激活進(jìn)程
③自動(dòng)服務(wù)依賴管理
3.服務(wù)單元
列出所有的服務(wù)單元
[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 :服務(wù)單元的名稱
LOAD :systemd是否正確解析了單元的配置,并將該單元加載到內(nèi)存中
ACTIVE:單元的高級(jí)別激活狀態(tài),此信息表明單元是否正常啟動(dòng)。
SUB:單元的低級(jí)別激活狀態(tài),信息視單元類型、狀態(tài)以及單元執(zhí)行方式而異。
3.查看以激活狀態(tài)的服務(wù)單元
[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.查看服務(wù)之間的依賴關(guān)系
[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的運(yùn)行級(jí)別
1.運(yùn)行級(jí)別
REL6.0及之前版本的定義————
0:關(guān)機(jī),停機(jī)模式
1:單用戶模式
2:多用戶模式
3:完整的多用戶文本模式
4:系統(tǒng)未使用,保留一般不用
5:圖形化模式
6:重啟模式
運(yùn)行級(jí)就是操作系統(tǒng)當(dāng)前正在運(yùn)行的功能級(jí)別。這個(gè)級(jí)別從0到6,具有不同的功能。
2.target類型
RHEL8.0新版本————
graphical.target:系統(tǒng)支持多用戶、圖形和基于文本登錄。
multi-user.target:系統(tǒng)支持多用戶和基于文本登錄。
rescue.target:系統(tǒng)初始化以完成,需要root登錄。
emergency.target:只讀掛載根文件系統(tǒng),需要root權(quán)限。
3.查看當(dāng)前系統(tǒng)默認(rèn)啟動(dòng)的運(yùn)行目標(biāo)
[root@tianyi ~]# systemctl get-default multi-user.target4.切換當(dāng)前運(yùn)行目標(biāo)
[root@tianyi ~]# systemctl set-default multi-user.target [root@tianyi ~]# systemctl get-default multi-user.target三、系統(tǒng)啟動(dòng)內(nèi)核
1.查看默認(rèn)內(nèi)核啟動(dòng)項(xiàng)信息
[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.修改內(nèi)核的默認(rèn)啟動(dòng)項(xiàng)
1.根據(jù)開機(jī)啟動(dòng)菜單欄索引號(hào)
[root@control ~]# grubby --default-index 0 [root@control ~]# grub2-set-default 0 [root@control ~]# grubby --default-index 02.根據(jù)綁定特定的內(nèi)核版本
[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.修改內(nèi)核啟動(dòng)參數(shù)
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系統(tǒng)啟動(dòng)流程
1.BIOS初始化過程
電腦通電開機(jī),完成硬件初始化。BIOS加電自檢,BIOS進(jìn)行初始化。
2.grub階段
1.把MBR加載到內(nèi)存, MBR=512字節(jié)=引導(dǎo)程序(446字節(jié))+64字節(jié)(分區(qū)表)+2字節(jié)
2.BIOS加載grub引導(dǎo)程序,系統(tǒng)控制交給引導(dǎo)程序。
3.引導(dǎo)程序加載配置文件/boot/grub2/grub.cfg,告訴/boot目錄所在分區(qū)和內(nèi)核文件在哪,并加載內(nèi)核和initramfs,并放入內(nèi)存中。initramfs包含啟動(dòng)時(shí)硬件必要的內(nèi)核模塊和初始化腳本。
4.Kernel自身初始化,且內(nèi)核在initramfs中找到所有硬件的驅(qū)動(dòng)程序,初始化這些硬件。
5.initramfs中的/sbin/init以pid為1的進(jìn)程啟動(dòng),并鏈接到systemd。
6.內(nèi)核將根從initramfs切換到真正的根。
7.啟動(dòng)第一個(gè)程序systemd
五、系統(tǒng)重要文件查看
1./sbin/init
[root@control ~]# ll -ld /sbin/init lrwxrwxrwx. 1 root root 22 Feb 26 2019 /sbin/init -> ../lib/systemd/systemd2.系統(tǒng)啟動(dòng)的內(nèi)核
[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.系統(tǒng)的內(nèi)核源代碼文件
[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.內(nèi)核的信息文件
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總結(jié)
以上是生活随笔為你收集整理的Linux的系统启动流程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python基础之循环语句
- 下一篇: Shell脚本实战之文件批量创建和修改