How to set up startup without rc.local file
# ls /etc/rc.local
ls: 无法访问'/etc/rc.local': 没有那个文件或目录
In this case, you need to follow the configuration below to make it take effect
Create rc.local
# touch /etc/rc.local
# chmod +x /etc/rc.local
Add a command to be executed on boot
# vi /etc/rc.local
#!/bin/bash -e
echo 666 > /tmp/test.txt ## 随便创建一个文件,作为验证文件。
View rc-local process status
# systemctl status rc-local
● rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
Drop-In: /usr/lib/systemd/system/rc-local.service.d
└─debian.conf
Active: inactive (dead)
Docs: man:systemd-rc-local-generator(8)
## 启动rc.local
# systemctl enable rc-local --now
# systemctl status rc-local
● rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/lib/systemd/system/rc-local.service; static; vendor preset: enabled)
Drop-In: /usr/lib/systemd/system/rc-local.service.d
└─debian.conf
Active: active (exited) since Fri 2022-11-11 14:53:05 CST; 5s ago
Docs: man:systemd-rc-local-generator(8)
Process: 13830 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
11月 11 14:53:05 zclinux systemd[1]: Starting /etc/rc.local Compatibility...
11月 11 14:53:05 zclinux systemd[1]: Started /etc/rc.local Compatibility.
Try restarting (use with caution in production)
# reboot
verify
# cat /tmp/test.txt
666