arm-linux之为开发板写上电自启动程序之方法

来源:互联网 发布:nginx跳转保持url不变 编辑:程序博客网 时间:2024/05/20 10:22

开发环境

开发板:AM335虚拟机:ubuntu 14.04编译器:gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf开发板内核:linux 4.4.12

首先开发板的文件使用的是systemd 并没有/etc/rc.local文件 所以要想修改rc.local这一简单的操作已经不存在 但是也是可以用systemd和initd两种方式解决这个问题
1.systemd
我这里是修改自带的service

root@am335x-evm:/etc/rc5.d# ls /lib/systemd/system/rc-local.service /lib/systemd/system/rc-local.service

在开发板这个目录我找到了rc-local.service文件 查看其内容

root@am335x-evm:/etc/rc5.d# cat /lib/systemd/system/rc-local.service   #  This file is part of systemd.##  systemd is free software; you can redistribute it and/or modify it#  under the terms of the GNU Lesser General Public License as published by#  the Free Software Foundation; either version 2.1 of the License, or#  (at your option) any later version.# This unit gets pulled automatically into multi-user.target by# systemd-rc-local-generator if /etc/rc.local is executable.[Unit]Description=/etc/rc.local CompatibilityConditionFileIsExecutable=/etc/rc.localAfter=network.target[Service]Type=forkingExecStart=/etc/rc.local startTimeoutSec=0RemainAfterExit=yes

可见开发板是支持/etc/rc.local文件的使用的 但是开发板下又没有/etc/rc.local文件 所以我们只能自己去建立了
在/lib/systemd/system/rc-local.service下加多一段文字

[Install]WantedBy=multi-user.target

multi-user.target指明的是非图形界面的多用户方式

然后就去创建rc.local文件

vi /etc/rc.cal

然后加入以下代码

#!/bin/shcase "$1" instart)/file_creat Tronlong                          ;;stop)exit 0;;      esac

然后就输入以下命令

    # chmod +x /etc/rc.local    # systemctl   enable   rc-local.service    # systemctl   --system  daemon-reload    # systemctl   start  rc-local.service

然后重启后就可以看到Tronlong这个文件了

2.initd
首先创建/etc/init.d/helloworld文件
vi /etc/init.d/helloworld
内容为

#!/bin/shxxxxxxxx //你要启动的程序命令
#  chmod +x /etc/init.d/helloworld  //加可执行权限#  ln -sf /etc/init.d/helloworld /etc/rc5.d/S99helloworld  //建立链接#  update-rc.d helloworld start 99 2 .  //设置成开机启动项

然后重启就能看到程序运行了

原创粉丝点击