[ubuntu]啟用 ubuntu 20.04 /etc/rc.local

參考網址:https://helloworld.pixnet.net/blog/post/47874794-%E5%95%9F%E7%94%A8-ubuntu-20.04–etc-rc.local

ubuntu 20.04 預設重開機時無法啟用 /etc/rc.local
如果要重開機後執行的話,修改方式如下

1. 在檔案的最末端加入以下三行,存檔離開
sudo vi /lib/systemd/system/rc-local.service
[Install] 
WantedBy=multi-user.target
Alias=rc-local.service

2. 建立 rc.local
sudo vi /etc/rc.local
#!/bin/sh -e

echo `date` >> /tmp/reboot.log

exit 0

3. 加入可執行權限
sudo chmod u+x /etc/rc.local

4. 設定開機啟動,並手動啟用測試
sudo systemctl enable rc-local
sudo systemctl start rc-local


5. 檢視是否已啟用
sudo systemctl status rc-local
● rc-local.service – /etc/rc.local Compatibility
     Loaded: loaded (/lib/systemd/system/rc-local.service; enabled; vendor preset: enabled)
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: active (exited) since Fri 2021-09-17 01:53:56 UTC; 3s ago
       Docs: man:systemd-rc-local-generator(8)
    Process: 989234 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

Sep 17 01:53:56 example systemd[1]: Starting /etc/rc.local Compatibility…
Sep 17 01:53:56 example systemd[1]: Started /etc/rc.local Compatibility.

6. 建立連結
sudo ln -s /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service

7. 重開機
sudo reboot

本篇發表於 Linux系統。將永久鏈結加入書籤。