本文解释了如何在Linux Debian 9中创建rc.local文件
以下是如何在Debian 9中添加rc.local的步骤。
在Debian 9中,传统的“rc.local”已被删除。对于传统Linux用户和管理员,可以通过SystemD将其恢复。请参阅下面的步骤(注意:所有命令必须以root权限运行):
1. 编辑不存在的文件“rc-local.service” :
vi /etc/systemd/system/rc-local.service
1.1. 将以下内容添加到“/etc/systemd/system/rc-local.service” :
[Unit]
Description=/etc/rc.local
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”文件 :
vi /etc/rc.local
2.1. 添加以下内容并保存文件
#!/bin/sh -e
#
# rc.local
#
# 此脚本在每个多用户运行级别的末尾执行。
# 确保脚本在成功时返回“exit 0”或在错误时返回其他
# 值。
#
# 要启用或禁用此脚本,只需更改执行
# 权限。
#
# 默认情况下,此脚本什么也不做。
exit 0
3. 更改权限
chmod +x /etc/rc.local
4. 在启动时启用“rc-local”脚本
systemctl enable rc-local
5. 启动“rc-local”脚本
systemctl start rc-local.service
6. 检查启动服务时是否发生错误
systemctl status rc-local.service
您现在可以在传统的“rc.local”中添加任何您想要的内容。类似的过程也适用于基于Debian的发行版,如Ubuntu、Elementary或Kali。
Please report any broken links by emailing elo.support@zebra.com and include a link to the knowledge article