淺談Linux系統的啟動流程

來源:互聯網
上載者:User

Linux系統的啟動時通過讀取不同的設定檔,執行相應的Shell指令碼完成的。當然本文只是簡單的從檔案的角度分析,更深層次的本文沒涉及。

主要讀取了以下檔案:

/boot/grub/grub.conf
/etc/inittab
/etc/rc5.d(rc.d) 0-99 Seq
/etc/passwd (Login,input username and password)
/etc/shadow
/etc/profile:init the env var of user
/etc/profile.d/*.sh
~/.bash_profile
~/.bash_history
~/.bashrc
/etc/bashrc

我們首先來看grub.conf檔案

[root@ www.bkjia.com grub]# ll menu.lst
lrwxrwxrwx. 1 root root 11  7o?=o?= 19 10:52 menu.lst -> ./grub.conf
[root@ www.bkjia.com grub]# pwd
/boot/grub
grub.conf檔案內容:
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux (2.6.32-220.el6.i686)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.32-220.el6.i686 ro
root=UUID=ed98469d-857b-4ae5-91e4-118e0167ead7 rd_NO_LUKS rd_NO_LVM
LANG=en_US.UTF-8 rd_NO_MD quiet SYSFONT=lat    arcyrheb-sun16 rhgb
crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM
        initrd /boot/initramfs-2.6.32-220.el6.i686.img

執行runlevel命令可以看到啟動層級是5

[root@ www.bkjia.com grub]# runlevel

N 5

我們進入etc目錄,可以看到很多rcX.d目錄

[root@ www.bkjia.com grub]# cd /etc/init.d

[root@ www.bkjia.com init.d]# cd /etc
[root@ www.bkjia.com etc]# cd rc
rc          rc0.d/      rc1.d/      rc2.d/      rc3.d/      rc4.d/      rc5.d/
rc6.d/      rc.d/      rc.local    rc.sysinit 

我們進入/etc/profile.d目錄,可以看到很多可執行指令碼

[root@localhost test]# ll /etc/profile.d/*.sh
-rw-r--r--. 1 root root 1143 Apr 28  2010 /etc/profile.d/colorls.sh
-rw-r--r--. 1 root root  78 Apr 21  2010 /etc/profile.d/cvs.sh
-rw-r--r--. 1 root root  192 Dec 12  2005 /etc/profile.d/glib2.sh
-rw-r--r--. 1 root root  70 Aug 12  2010 /etc/profile.d/gnome-ssh-askpass.sh
-rwxr-xr-x. 1 root root  288 Sep 24  2009 /etc/profile.d/kde.sh
-rw-r--r--. 1 root root 2706 Sep  2  2010 /etc/profile.d/lang.sh
-rw-r--r--. 1 root root  108 Feb  7  2007 /etc/profile.d/less.sh
-rw-r--r--. 1 root root  933 Jun 30  2010 /etc/profile.d/qt.sh
-rw-r--r--. 1 root root 2142 Sep  8  2010 /etc/profile.d/udisks-bash-completion.sh
-rw-r--r--. 1 root root  269 May 19  2010 /etc/profile.d/vim.sh
-rw-r--r--. 1 root root  169 May 20  2009 /etc/profile.d/which2.sh

因為啟動層級是5,所以我們進入rc5.d,可以看到很多檔案,S表示當系統啟動時執行,K表示當系統關閉時執行。

[root@localhost grub]# ll /etc/rc5.d/
K01certmonger      K50netconsole      K75ntpdate          K89rdisc            S11auditd          S24avahi-daemon    S26pcscd            S82abrtd
K01smartd          K50snmpd            K76ipsec            K95cgconfig        S11portreserve      S24nfslock          S26udev-post        S85qpidd
K02oddjobd          K50snmptrapd        K80kdump            K95firstboot        S12rsyslog          S24openct          S28autofs          S90crond
K10psacct          K50vsftpd          K80sblim-sfcb      S00microcode_ctl    S13cpuspeed        S24rpcgssd          S30vboxadd          S95atd
K10saslauthd        K60nfs              K80sssd            S01sysstat          S13irqbalance      S24rpcidmapd        S30vboxadd-x11      S97rhnsd
K15httpd            K69rpcsvcgssd      K84wpa_supplicant  S02lvm2-monitor    S13rpcbind          S25cups            S35vboxadd-service  S98tog-pegasus
K20tomcat6          K73ypbind          K86cgred            S08ip6tables        S15mdmonitor        S25netfs            S50bluetooth        S99local
K36mysqld          K74nscd            K87restorecond      S08iptables        S22messagebus      S26acpid            S55sshd           
K50dnsmasq          K74ntpd            K88nslcd            S10network          S23NetworkManager  S26haldaemon        S80postfix   

我們再來看看使用者主目錄下的.bashrc檔案內容

[root@localhost grub]# cat ~/.bashrc
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
 . /etc/bashrc
fi

我們再來看看使用者主目錄下的.bash_profile檔案內容

[root@localhost grub]# cat ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
 . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

完整的流程圖如:

推薦閱讀:

詳細講解Linux啟動流程及啟動用到的設定檔及指令碼

Linux系統啟動流程學習筆記

Linux啟動流程知多少之迷你系統

Linux啟動流程介紹

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.