ubuntu没有rc.local文件

        当我们设置开机自启时候,一般都在rc.local文件里设置,但是有的Ubuntu版本没有这个文件

了,此时我们可以自己创建一个。

1、创建一个rc-local.service文件

sudo vim /etc/systemd/system/rc-local.service

  复制粘贴以下内容到文件里

[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


2、 启动rc-local.service服务并设置开机自启

sudo systemctl start rc-local.service
sudo systemctl enable rc-local.service


3.、创建/etc/rc.local文件

sudo vim /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


给予脚本执行权限

sudo chmod +x /etc/rc.local
 

猜你喜欢

转载自blog.csdn.net/qq_35002542/article/details/127999561