UBUNTU 添加开机启动程序

1.在/etc/init.d/目录下新建脚本文件“jr”


注:脚本文件jr的内容格式,有严格规定。例程如下:


#! /bin/sh
### BEGIN INIT INFO
# Provides:          binfmt-support
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     S 1 2 3 4 5 6 
# Default-Stop:
# Short-Description: Support for extra binary formats
# Description:       Enable support for extra binary formats using the Linux
#                    kernel's binfmt_misc facility.
### END INIT INFO


echo "xx" >> /jr/jr.txt
exit 0





2.命令:#sudo update-rc.d jr defaults 98

//设置运行的优先级为98

//运行结果如下:


wu@ubuntu:~$ sudo update-rc.d jr defaults 98
update-rc.d: warning: jr start runlevel arguments (2 3 4 5) do not match LSB Default-Start values (S 1 2 3 4 5 6)
update-rc.d: warning: jr stop runlevel arguments (0 1 6) do not match LSB Default-Stop values (none)
 Adding system startup for /etc/init.d/jr ...
   /etc/rc0.d/K98jr -> ../init.d/jr
   /etc/rc1.d/K98jr -> ../init.d/jr
   /etc/rc6.d/K98jr -> ../init.d/jr
   /etc/rc2.d/S98jr -> ../init.d/jr
   /etc/rc3.d/S98jr -> ../init.d/jr
   /etc/rc4.d/S98jr -> ../init.d/jr
   /etc/rc5.d/S98jr -> ../init.d/jr
//表示已经在/etc/rcX.d/的相应目录下,创建启动脚本成功。


3.为了验证一下,可以运行#sysv-rc-conf

找到相应名称的脚本,看启动标志打开了没有。

4.放心地重启吧,看看效果。





原文地址:https://www.cnblogs.com/techstone/p/2661244.html