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/sysstemd/system/rc-local.service
7. 重開機
sudo reboot
相關連結: 透過 crontab 實現重開機時自動執行 script
https://helloworld.pixnet.net/blog/post/48872828-%e9%80%8f%e9%81%8e-crontab-%e5%af%a6%e7%8f%be%e9%87%8d%e9%96%8b%e6%a9%9f%e6%99%82%e8%87%aa%e5%8b%95%e5%9f%b7%e8%a1%8c-script
留言列表