共計(jì) 1465 個(gè)字符,預(yù)計(jì)需要花費(fèi) 4 分鐘才能閱讀完成。
這篇文章主要介紹“Ubuntu 怎么添加開(kāi)機(jī)啟動(dòng)項(xiàng)”,在日常操作中,相信很多人在 Ubuntu 怎么添加開(kāi)機(jī)啟動(dòng)項(xiàng)問(wèn)題上存在疑惑,丸趣 TV 小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”Ubuntu 怎么添加開(kāi)機(jī)啟動(dòng)項(xiàng)”的疑惑有所幫助!接下來(lái),請(qǐng)跟著丸趣 TV 小編一起來(lái)學(xué)習(xí)吧!
1、方法一,編輯 rc.loacl 腳本
Ubuntu 開(kāi)機(jī)之后會(huì)執(zhí)行 /etc/rc.local 文件中的腳本,
所以我們可以直接在 /etc/rc.local 中添加啟動(dòng)腳本。
當(dāng)然要添加到語(yǔ)句:exit 0 前面才行。
如:
sudo vi /etc/rc.local
然后在 exit 0 前面添加好腳本代碼。
2、方法二,添加一個(gè) Ubuntu 的開(kāi)機(jī)啟動(dòng)服務(wù)。
如果要添加為開(kāi)機(jī)啟動(dòng)執(zhí)行的腳本文件,
可先將腳本復(fù)制或者軟連接到 /etc/init.d/ 目錄下,
然后用:update-rc.d xxx defaults NN 命令 (NN 為啟動(dòng)順序),
將腳本添加到初始化執(zhí)行的隊(duì)列中去。
注意如果腳本需要用到網(wǎng)絡(luò),則 NN 需設(shè)置一個(gè)比較大的數(shù)字,如 99。
1) 將你的啟動(dòng)腳本復(fù)制到 /etc/init.d 目錄下
以下假設(shè)你的腳本文件名為 test。
2) 設(shè)置腳本文件的權(quán)限
$ sudo chmod 755 /etc/init.d/test
3) 執(zhí)行如下命令將腳本放到啟動(dòng)腳本中去:
$ cd /etc/init.d
$ sudo update-rc.d test defaults 95
注:其中數(shù)字 95 是腳本啟動(dòng)的順序號(hào),按照自己的需要相應(yīng)修改即可。在你有多個(gè)啟動(dòng)腳本,而它們之間又有先后啟動(dòng)的依賴關(guān)系時(shí)你就知道這個(gè)數(shù)字的具體作用了。該命令的輸出信息參考如下:
update-rc.d: warning: /etc/init.d/test missing LSB information
update-rc.d: see http://wiki.debian.org/LSBInitScripts
Adding system startup for /etc/init.d/test ...
/etc/rc0.d/K95test - ../init.d/test
/etc/rc1.d/K95test - ../init.d/test
/etc/rc6.d/K95test - ../init.d/test
/etc/rc2.d/S95test - ../init.d/test
/etc/rc3.d/S95test - ../init.d/test
/etc/rc4.d/S95test - ../init.d/test
/etc/rc5.d/S95test - ../init.d/test
卸載啟動(dòng)腳本的方法:
$ cd /etc/init.d
$ sudo update-rc.d -f test remove
命令輸出的信息參考如下:
Removing any system startup links for /etc/init.d/test ...
/etc/rc0.d/K95test
/etc/rc1.d/K95test
/etc/rc2.d/S95test
/etc/rc3.d/S95test
/etc/rc4.d/S95test
/etc/rc5.d/S95test
/etc/rc6.d/K95test
到此,關(guān)于“Ubuntu 怎么添加開(kāi)機(jī)啟動(dòng)項(xiàng)”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注丸趣 TV 網(wǎng)站,丸趣 TV 小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!