码迷,mamicode.com
首页 > 系统相关 > 详细

[转] 浅谈Linux系统的启动流程

时间:2016-10-12 13:37:13      阅读:231      评论:0      收藏:0      [点我收藏+]

标签:

原文:http://blog.csdn.net/justdb/article/details/9621271 版权声明:本文为博主原创文章。

 

 

Linux系统的启动时通过读取不同的配置文件,执行相应的Shell脚本完成的。当然本文只是简单的从文件的角度分析,更深层次的本文没涉及。    

主要读取了以下文件:

 1 /boot/grub/grub.conf
 2 /etc/inittab
 3 /etc/rc5.d(rc.d) 0-99 Seq
 4 /etc/passwd (Login,input username and password)
 5 /etc/shadow
 6 /etc/profile:init the env var of user
 7 /etc/profile.d/*.sh
 8 ~/.bash_profile
 9 ~/.bash_history
10 ~/.bashrc
11 /etc/bashrc

我们首先来看grub.conf文件

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

执行runlevel命令可以看到启动级别是5

1 [root@larrywen grub]# runlevel  
2 N 5

我们进入etc目录,可以看到很多rcX.d目录

1 [root@larrywen grub]# cd /etc/init.d  
2   
3 [root@larrywen init.d]# cd /etc  
4 [root@larrywen etc]# cd rc  
5 rc          rc0.d/      rc1.d/      rc2.d/      rc3.d/      rc4.d/      rc5.d/  
6 rc6.d/      rc.d/       rc.local    rc.sysinit    

我们进入/etc/profile.d目录,可以看到很多可执行脚本

 1 [root@localhost test]# ll /etc/profile.d/*.sh  
 2 -rw-r--r--. 1 root root 1143 Apr 28  2010 /etc/profile.d/colorls.sh  
 3 -rw-r--r--. 1 root root   78 Apr 21  2010 /etc/profile.d/cvs.sh  
 4 -rw-r--r--. 1 root root  192 Dec 12  2005 /etc/profile.d/glib2.sh  
 5 -rw-r--r--. 1 root root   70 Aug 12  2010 /etc/profile.d/gnome-ssh-askpass.sh  
 6 -rwxr-xr-x. 1 root root  288 Sep 24  2009 /etc/profile.d/kde.sh  
 7 -rw-r--r--. 1 root root 2706 Sep  2  2010 /etc/profile.d/lang.sh  
 8 -rw-r--r--. 1 root root  108 Feb  7  2007 /etc/profile.d/less.sh  
 9 -rw-r--r--. 1 root root  933 Jun 30  2010 /etc/profile.d/qt.sh  
10 -rw-r--r--. 1 root root 2142 Sep  8  2010 /etc/profile.d/udisks-bash-completion.sh  
11 -rw-r--r--. 1 root root  269 May 19  2010 /etc/profile.d/vim.sh  
12 -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文件内容

 1 [root@localhost grub]# cat ~/.bashrc   
 2 # .bashrc  
 3   
 4 # User specific aliases and functions  
 5   
 6 alias rm=rm -i  
 7 alias cp=cp -i  
 8 alias mv=mv -i  
 9   
10 # Source global definitions  
11 if [ -f /etc/bashrc ]; then  
12     . /etc/bashrc  
13 fi  

我们再来看看用户主目录下的.bash_profile文件内容

 1 [root@localhost grub]# cat ~/.bash_profile   
 2 # .bash_profile  
 3   
 4 # Get the aliases and functions  
 5 if [ -f ~/.bashrc ]; then  
 6     . ~/.bashrc  
 7 fi  
 8   
 9 # User specific environment and startup programs  
10   
11 PATH=$PATH:$HOME/bin  
12   
13 export PATH  

完整的流程图如下图:

技术分享

 

[转] 浅谈Linux系统的启动流程

标签:

原文地址:http://www.cnblogs.com/sevck/p/5952203.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!