前言
雖然是原創,畢竟自己對Ubuntu的開機啟動研究了整整兩天,期間看鳥哥linux私房菜、研究/etc/init.d/下shell源碼等等,但是不可否認看了很多國內國外的文章,最終搞定也是基於一篇不錯的博客文章,這裡首先進行推薦:通過update-rc.d管理ubuntu開機啟動 http://www.linuxidc.com/Linux/2013-01/77553.htm
接下來,我會按照參考博客內容記錄一些自己的收獲(測試環境ubuntu10.04 && ubuntu12.04)
Ubuntu系統運行級別
- 0 系統停機狀態
- 1 單用戶或系統維護狀態
- 2~5 多用戶狀態
- 6 重新啟動
update-rc.d概要
Linux services can be started, stopped and reload with the use of scripts stocked(貯存) in
/etc/init.d/. However, during start up or when changing runlevel, those scripts are searched in /etc/rcX.d/ where X is the runlever number(可以用runlevel命令查看系統默認的runlevel). This tutorial will explain how one can activate(激活), disactivate or modifu a service start up. When installing a new service under debian, the default is to enable it. So for instance, if you just installed apache2 package, after you installed it, apache service will be started and so will it be upon the next reboots. If you do not use apache all the time, you might want to disable this service from starting up upon boot up and simply start it manually when you actually need it by running this command:
sudo /etc/init.d/apache2 start
You could either disable this service on boot up by removing any symbolic links in /etc/rcX.d/SYYapache2 or by using update-rc.d.The advantage of using update-rc.d is that is will take care of removing/adding any required links to /etc/init.d automatically.Taking apache2 as an example.
As you can see, for runlevels 0, 1 and 6 there is a K at the begining of the link, for runlevels 2, 3, 4 and 5, there is a S. Those two letters stands for Kill and Start.
Removing A Service
If you want to totally disable apache2 service by hand, you would need to delete every single link in /etc/rcX.d/. Using update-rc.d it is a simple as :
update-rc.d [-f] servicename remove