无为清净楼资源网 Design By www.qnjia.com
Linux有自己一套完整的启动体系,抓住了Linux启动的脉络,Linux的启动过程将不再神秘。
阅读之前建议先看一下附图。
本文中假设inittab中设置的init tree为:
/etc/rc.d/rc0.d
/etc/rc.d/rc1.d
/etc/rc.d/rc2.d
/etc/rc.d/rc3.d
/etc/rc.d/rc4.d
/etc/rc.d/rc5.d
/etc/rc.d/rc6.d
/etc/rc.d/init.d
1. 关于Linux的启动
init是所有进程之父
init读取/etc/inittab,执行rc.sysinit脚本
(注意文件名是不一定的,有些unix甚至会将语句直接写在inittab中)
rc.sysinit脚本作了很多工作:
init $PATH
config network
start swap function
set hostname
check root file system, repair if needed
check root space
....
rc.sysinit根据inittab执行rc?.d脚本
Linux是多用户系统,getty是多用户与单用户的分水岭
在getty之前运行的是系统脚本
. 关于rc.d
所有启动脚本放置在 /etc/rc.d/init.d下
rc?.d中放置的是init.d中脚本的链接,
命名格式是:
S{number}{name}
K{number}{name}
S开始的文件向脚本传递start参数
K开始的文件向脚本传递stop参数
number决定执行的顺序
3. 启动脚本示例
这是一个用来启动httpd的 /etc/rc.d/init.d/apache 脚本:
代码:
#!/bin/bash
source /etc/sysconfig/rc
source $rc_functions
case "$1" in
start)
echo "Starting Apache daemon..."
/usr/local/apache2/bin/apachectl -k start
evaluate_retval
;;
stop)
echo "Stopping Apache daemon..."
/usr/local/apache2/bin/apachectl -k stop
evaluate_retval
;;
restart)
echo "Restarting Apache daemon..."
/usr/local/apache2/bin/apachectl -k restart
evaluate_retval
;;
status)
statusproc /usr/local/apache2/bin/httpd
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac可以看出他接受start,stop,restart,status参数
然后可以这样建立rc?.d的链接:
代码:
cd /etc/rc.d/init.d &&
ln -sf ../init.d/apache ../rc0.d/K28apache &&
ln -sf ../init.d/apache ../rc1.d/K28apache &&
ln -sf ../init.d/apache ../rc2.d/K28apache &&
ln -sf ../init.d/apache ../rc3.d/S32apache &&
ln -sf ../init.d/apache ../rc4.d/S32apache &&
ln -sf ../init.d/apache ../rc5.d/S32apache &&
ln -sf ../init.d/apache ../rc6.d/K28apache4. 关于rc.local
经常使用的 rc.local 则完全是习惯问题,不是标准。
各个发行版有不同的实现方法,可以这样实现:
代码:
touch /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc1.d/S999rc.local &&
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc2.d/S999rc.local &&
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc3.d/S999rc.local &&
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc4.d/S999rc.local &&
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc5.d/S999rc.local &&
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc6.d/S999rc.local5. 关于bash启动脚本
/etc/profile
/etc/bashrc
~/.bash_profile
~/.bashrc
是bash的启动脚本
一般用来设置单用户的启动环境,也可以实现开机单用户的程序,但要明确他们都是属于bash范畴而不是系统范畴。
他们的具体作用介绍如下:
/bin/bash这个命令解释程序(后面简称shell)使用了一系列启动文件来建立一个运行环境:
/etc/profile
/etc/bashrc
~/.bash_profile
~/.bashrc
~/.bash_logout
每一个文件都有特殊的功用并对登陆和交互环境有不同的影响。
/etc/profile 和 ~/.bash_profile 是在启动一个交互登陆shell的时候被调用。
/etc/bashrc 和 ~/.bashrc 是在一个交互的非登陆shell启动的时候被调用。
~/.bash_logout 在用户注销登陆的时候被读取
一个交互的登陆shell会在 /bin/login 成功登陆之后运行。一个交互的非登陆shell是通过命令行来运行的,如[prompt] $/bin/bash。一般一个非交互的shell出现在运行shell脚本的时候。之所以叫非交互的shell,是因为它不在命令行上等待输入而只是执行脚本程序。
阅读之前建议先看一下附图。
本文中假设inittab中设置的init tree为:
/etc/rc.d/rc0.d
/etc/rc.d/rc1.d
/etc/rc.d/rc2.d
/etc/rc.d/rc3.d
/etc/rc.d/rc4.d
/etc/rc.d/rc5.d
/etc/rc.d/rc6.d
/etc/rc.d/init.d
1. 关于Linux的启动
init是所有进程之父
init读取/etc/inittab,执行rc.sysinit脚本
(注意文件名是不一定的,有些unix甚至会将语句直接写在inittab中)
rc.sysinit脚本作了很多工作:
init $PATH
config network
start swap function
set hostname
check root file system, repair if needed
check root space
....
rc.sysinit根据inittab执行rc?.d脚本
Linux是多用户系统,getty是多用户与单用户的分水岭
在getty之前运行的是系统脚本
. 关于rc.d
所有启动脚本放置在 /etc/rc.d/init.d下
rc?.d中放置的是init.d中脚本的链接,
命名格式是:
S{number}{name}
K{number}{name}
S开始的文件向脚本传递start参数
K开始的文件向脚本传递stop参数
number决定执行的顺序
3. 启动脚本示例
这是一个用来启动httpd的 /etc/rc.d/init.d/apache 脚本:
代码:
#!/bin/bash
source /etc/sysconfig/rc
source $rc_functions
case "$1" in
start)
echo "Starting Apache daemon..."
/usr/local/apache2/bin/apachectl -k start
evaluate_retval
;;
stop)
echo "Stopping Apache daemon..."
/usr/local/apache2/bin/apachectl -k stop
evaluate_retval
;;
restart)
echo "Restarting Apache daemon..."
/usr/local/apache2/bin/apachectl -k restart
evaluate_retval
;;
status)
statusproc /usr/local/apache2/bin/httpd
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac可以看出他接受start,stop,restart,status参数
然后可以这样建立rc?.d的链接:
代码:
cd /etc/rc.d/init.d &&
ln -sf ../init.d/apache ../rc0.d/K28apache &&
ln -sf ../init.d/apache ../rc1.d/K28apache &&
ln -sf ../init.d/apache ../rc2.d/K28apache &&
ln -sf ../init.d/apache ../rc3.d/S32apache &&
ln -sf ../init.d/apache ../rc4.d/S32apache &&
ln -sf ../init.d/apache ../rc5.d/S32apache &&
ln -sf ../init.d/apache ../rc6.d/K28apache4. 关于rc.local
经常使用的 rc.local 则完全是习惯问题,不是标准。
各个发行版有不同的实现方法,可以这样实现:
代码:
touch /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc1.d/S999rc.local &&
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc2.d/S999rc.local &&
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc3.d/S999rc.local &&
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc4.d/S999rc.local &&
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc5.d/S999rc.local &&
ln -sf /etc/rc.d/rc.local /etc/rc.d/rc6.d/S999rc.local5. 关于bash启动脚本
/etc/profile
/etc/bashrc
~/.bash_profile
~/.bashrc
是bash的启动脚本
一般用来设置单用户的启动环境,也可以实现开机单用户的程序,但要明确他们都是属于bash范畴而不是系统范畴。
他们的具体作用介绍如下:
/bin/bash这个命令解释程序(后面简称shell)使用了一系列启动文件来建立一个运行环境:
/etc/profile
/etc/bashrc
~/.bash_profile
~/.bashrc
~/.bash_logout
每一个文件都有特殊的功用并对登陆和交互环境有不同的影响。
/etc/profile 和 ~/.bash_profile 是在启动一个交互登陆shell的时候被调用。
/etc/bashrc 和 ~/.bashrc 是在一个交互的非登陆shell启动的时候被调用。
~/.bash_logout 在用户注销登陆的时候被读取
一个交互的登陆shell会在 /bin/login 成功登陆之后运行。一个交互的非登陆shell是通过命令行来运行的,如[prompt] $/bin/bash。一般一个非交互的shell出现在运行shell脚本的时候。之所以叫非交互的shell,是因为它不在命令行上等待输入而只是执行脚本程序。
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年10月09日
2024年10月09日
- 《崩坏:星穹铁道》造物大赛卷出新高度
- 《王菲 菲常传奇 2CD》[WAV+CUE][950MB]
- 《王菲 空灵独味唱腔 非常传奇 紫水晶2CD》[WAV+CUE][860MB]
- 《车载专业测试王1号 极品音质》[WAV/分轨][980MB]
- 炉石传说的国服回归送什么奖励 炉石传说9.25回归最新消息介绍
- 云顶之弈最强阵容汇总2024 云顶之弈最强阵容搭配最新版本
- S14lol全球总决赛在哪观看 lol全球总决赛观赛直播地址汇总
- 黄思婷2011-感谢天[豪记唱片][WAV+CUE]
- 孙淑媚2013-太阳[台湾首版][WAV+CUE]
- LaviniaMeijer-Voyage(2015)[WAV]
- 大雷肉腿美女姐姐Cos图赏:2B、约尔、露西等
- 《寂静岭2:重制版》《龙珠:电光炸裂!ZERO》销售榜前三:上PC的重要性!
- 隰县小西天扭转差评:副县长驻唱、文旅局长化身唐僧
- 《原神》「和声的回响」网页活动壁纸展示
- 原神「星路拾忆」网页活动壁纸展示(三)