当我们设置开机自启时候,一般都在rc.local文件里设置,但是有的Ubuntu版本没有这个文件
了,此时我们可以自己创建一个。
- 创建一个rc-local.service文件
bash
sudo vim /etc/systemd/system/rc-local.service
复制粘贴以下内容到文件里
shell
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
- 启动rc-local.service服务并设置开机自启
sudo systemctl start rc-local.service
sudo systemctl enable rc-local.service
- 创建/etc/rc.local文件
sudo vim /etc/rc.local
复制粘贴以下内容到文件里
bash
#!/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
给予脚本执行权限
bash
sudo chmod +x /etc/rc.local
参考文章: https://blog.csdn.net/weixin_39246554/article/details/129675373/