Linux · 18 11 月, 2019 0

ubuntu 18.04 配置 rc.local

ubuntu 18.04开机启动机制

ubuntu 18.04 不再使用 inited 管理系统,改用 systemd。虽然是进步(啊?),但很多人(包括我)还是喜欢用原本简单方便的 rc.local 作为系统启动脚本。

操作步骤

1.编辑文件nano /lib/systemd/system/rc.local.service

[Unit]
 Description=/etc/rc.local Compatibility
 Documentation=man:systemd-rc-local-generator(8)
 ConditionFileIsExecutable=/etc/rc.local
 After=syslog.target network.target remote-fs.target nss-lookup.target

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

 #这一段原文件没有,需要自己添加
 [Install]
 WantedBy=multi-user.target
 Alias=rc-local.service

2.设置软连接

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

3.编辑/etc/rc.local

#!/bin/bash
#开机启动脚本
exit 0

chmod +x /etc/rc.local添加执行权限

4.重启查看效果

参考