rc.local每次开机重置
时间: 2023-11-02 21:07:07 浏览: 52
rc.local 是一个在 Linux 系统中用于启动系统服务或应用程序的脚本文件。如果您的系统每次开机重置 rc.local 文件,则可能是由于您的系统配置了 systemd,而系统服务已经从 rc.local 转移到了 systemd。您可以尝试使用 systemctl 命令来管理系统服务,而不是通过修改 rc.local 文件来启动服务。如果您需要在系统启动时运行某些自定义命令或脚本,可以尝试将其添加到 systemd 的 service 文件中。
相关问题
rc.local无法开机
回答: 当rc.local无法开机时,你可以尝试以下几个步骤来解决问题。首先,你可以使用命令systemctl list-unit-files|grep rc.local来检查rc.local服务是否已经开启。如果显示为static,则代表已经开启,如果显示为disable,则代表未开启。你可以使用命令systemctl enable rc-local.service来手动开启rc.local服务,并使用systemctl start rc-local.service命令来手动启动一次rc.local服务,以查看是否有问题。你还可以检查/etc/rc.d/rc.local文件的格式是否正确,确保在文件开头加上了"#!/bin/bash"。你可以手动执行rc.local,并查看中间是否有执行错误的systemctl status rc-local.service。另外,你可以检查/etc/rc.d/rc.local文件的权限是否正确,可以使用命令ll /etc/rc.d/rc.local来查看权限。<em>1</em><em>2</em><em>3</em>
#### 引用[.reference_title]
- *1* *2* *3* [【Linux】rc.local和rc.d/rc.local的区别|rc.local文件开机不执行](https://blog.csdn.net/bandaoyu/article/details/128541771)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item]
[ .reference_list ]
rc.local配置开机自启
在 Ubuntu 系统中,你可以使用 `rc.local` 文件来配置开机自启动。
首先,打开终端,并以管理员权限运行以下命令来编辑 `rc.local` 文件:
```
sudo nano /etc/rc.local
```
在打开的文件中,你可以添加需要在系统启动时运行的命令或脚本。例如,假设你想要在启动时执行一个脚本文件 `/path/to/my_script.sh`,则可以将以下内容添加到 `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.
/path/to/my_script.sh
exit 0
```
请确保在 `exit 0` 之前添加了你的命令或脚本,并保存文件。
接下来,为 `rc.local` 文件设置可执行权限。在终端中运行以下命令:
```
sudo chmod +x /etc/rc.local
```
现在,你的命令或脚本将在系统启动时自动执行。
请注意,`rc.local` 文件在最新的 Ubuntu 版本中可能已经被弃用。如果你使用的是较新的 Ubuntu 版本,可以考虑使用其他方法,如 systemd 服务或 Upstart 来配置开机自启动。