执行sudo systemctl enable rc-local.servicesu提示The unit file
时间: 2023-12-14 12:38:25 浏览: 35
"rc-local.service" does not exist.
这个错误通常是因为你的系统上没有rc-local.service这个服务单元文件。这个服务单元文件是在一些较旧的Linux发行版中使用的,但在许多现代的发行版中已经被弃用了。
如果你想要启用一个类似于rc.local的启动脚本,你可以考虑使用systemd的systemd-rc-local-generator。这个生成器可以创建一个systemd服务单元文件,用来运行你的启动脚本。
你可以按照以下步骤来启用systemd-rc-local-generator:
1. 创建/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. 创建/etc/rc.local文件,并添加你想要执行的命令。注意,这个文件必须可执行,并且以#!/bin/sh开头。
3. 运行以下命令启用rc-local服务:
```
sudo systemctl enable rc-local.service
sudo systemctl start rc-local.service
```
这样,你的启动脚本就会在系统启动时自动执行了。