Linux设置开机自启动

时间:2023-01-30 15:36:49

1、进入/etc/init.d文件夹,编辑一个自定义的开机自启动脚本例如auto_start

#!/bin/bash
touch /auto_start.txt
ls /dev > /auto_start.txt

2、设置脚本文件auto_start的权限为可执行:

chmod 777 auto_start

3、执行chkconfig命令,chkconfig的man手册解释是:enable or disable system services,chkconfig  is used to manipulate the runlevel links at boot time,就是在系统启动阶段开启或者关闭一个系统服务,用来 检查,设置系统的各种服务。执行命令:

chkconfig auto_start on
运行后出现错误提示:

/sbin/insserv:No such file or directory
一般这个文件会在/usr/lib/insserv/insserv中,所以解决办法是:

ln -s /usr/lib/insserv/insserv /sbin/insserv
然后继续执行chkconfig命令即可打开auto_start服务,然后重启系统发现根文件目录下有了auto_start.txt文件了,代表自启动程序运行了。