Linux系統啟動過程和使用者登陸過程分析__Linux

來源:互聯網
上載者:User
Linux系統啟動和使用者登陸過程分析:

一、系統啟動過程
1、載入核心
2、執行init程式
3、/etc/rc.d/rc.sysinit ?                 說明:由init執行的第一個指令碼
4、/etc/rc.d/rc${RUNLEVEL}d/*             說明:$RUNLEVEL為預設的運行模式
5、/etc/rc.d/rc.local ???                 說明:相應層級服務啟動之後、在執行該檔案(其實也可以把需要執行的命令寫到該檔案中)
6、/sbin/mingetty                         說明:等待使用者登入

說明:
   (一)其中 /etc/rc.d/rc.sysinit的執行與運行模式(即$RUNLEVEL,包括1,2,3,4,5,6六個層級)無關,都執行相同的初始化任務:

    1)、調入keymap以及系統字型
    2)、啟動swapping
    3)、設定主機名稱
    4)、設定NIS網域名稱
    5)、檢查(fsck)並mount檔案系統
    6)、開啟quota
    7)、裝載音效卡模組
    8)、設定系統時鐘
    9)、其它

   (二)執行完 rc.sysinit 指令碼之後,系統根據運行模式選擇相應的/etc/rc.d/rcx.d ,
         其中運行模式從/etc/inittab 檔案中的 “id:3:initdefault: ”位置讀取;
         執行完/etc/rc.d/rcx.d 下相應的指令碼之後,就執行 /etc/rc.local 檔案中的內容;
         再接下來就是等待使用者登入,使用者登入時會執行一系列使用者環境的初始化指令碼。

二、使用者登陸過程
    與使用者登陸相關的指令碼有:
    1)、etc目錄下的profile,bashrc
    2)、使用者宿主目錄下的.bash_profile, .bashrc

    (一)、通過在每個指令碼開頭添加 echo 輸出並重新導向到    /tmp/bashtest   下面的測試結果:

    [root@www ~]# cat /tmp/bashtest
    I am /etc/profile ,executed at Fri Jun  6 20:01:30 CST 2014.
    I am .bash_profile ,executed at Fri Jun  6 20:01:30 CST 2014.
    I am .bashrc,executed at Fri Jun  6 20:01:30 CST 2014.
    I am /etc/bashrc ,executed at Fri Jun  6 20:01:30 CST 2014.
    [root@www ~]#

    (二)、可以得知,以上指令碼執行的順序是: /etc/bash_profile  =>  ~/.bash_profile =>  ~/.bashrc   =>  /etc/bashrc,並且經過測試得知,
    /etc/profile.d/目錄下面的指令碼執行也是在 ~/.bash_profile 之前執行的。

    退出系統後,使用其他使用者登陸,發現 .bash開頭的檔案沒有執行:
    由此可見,四個檔案/etc/profile,/etc/bashrc,~/.bash_profile,~/.bashrc中:
    前兩件是全域的,每一個使用者登入都會執行
    後兩個是專用的,針對特定使用者設定,即針對使用者自身設定的

    (三)、再來分析 ~/.bash_profile,~/.bashrc 這兩個檔案

    1) .bash_profile檔案中的注釋:
    # .bash_profile
    # Get the aliases and functions

    可見:.bash_profile作用:設定自訂的環境和開機啟動程式

    2) .bashrc檔案中的注釋:
    # .bashrc
    # User specific aliases and functions

    可見:.bashrc作用:設定自訂別名和函數。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.