天天看點

Ubuntu18.04設定開機自啟Ubuntu開機設定

Ubuntu18.04開機自啟設定

  • Ubuntu開機設定
    • 設定說明
    • 設定步驟
    • rc.local腳本

Ubuntu開機設定

Ubuntu-16.0開始不再使用initd管理系統,改用systemd

設定說明

systemd預設讀取/etc/systemd/system下的配置檔案,該目錄下的檔案會連結/lib/systemd/system下的檔案。

設定步驟

1、進入/lib/systemd/system下,找到rc.local.service

腳本内容:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
           

啟動檔案主要分成三部分:

[Unit] 段: 啟動順序與依賴關系
[Service] 段: 啟動行為,如何啟動,啟動類型
[Install] 段: 定義如何安裝這個配置檔案,即怎樣做到開機啟動
           

rc.local.service中沒有[Install],也就沒有定義如何開機自啟,在改檔案中加上[Install]段

[Install] 
WantedBy=multi-user.target 
Alias=rc-local.service
           

2、Ubuntu18.04中/etc/rc.local這個檔案沒有生成的,需要自己建立

sudo touch /etc/rc.local
           

3、在/etc/systemd/system目錄下建立軟連結

sudo ln -s /lib/systemd/system/rc.local.service /etc/systemd/system/ 
           

rc.local腳本

rc.lcoal腳本是Ubuntu開機後會自動執行的腳本

腳本路徑:/etc/rc.local

具體格式:

#!/bin/sh -e
 #
 # rc.local
 #
 # This script is executed at the end of each multiuser runlevel.
 # Make sure that the script will "exit 0" on success or any other
 # value on error.
 #
 # In order to enable or disable this script just change the execution
 # bits.
 #
 # By default this script does nothing.
   
exit 0
           

修改rc.local

sudo vim /etc/rc.local
           

注意:

一定要将指令添加在exit 0之前

過往作品:

打标工具brat的安裝與使用

[1]:https://blog.csdn.net/black_lightning/article/details/103673532

繼續閱讀