Jetson Xavier 自带ubuntu18.04系统,ubuntu18.04默认不带/etc/rc.local
文件,我们需要通过配置来让rc.local.service
生效。我们修改/etc/rc.local
文件来启动风扇。
1.查找服务
ls /lib/systemd/system | grep rc
找到rc.local.service文件
2.修改rc.local.service文件
打开后可以看到包含[Unit]和[Service]两个部分内容
一般启动文件需要三个部分:
[Unit] 启动顺序与依赖关系
[Service] 启动行为, 如何启动,启动类型
[Install] 定义如何安装这个配置文件,即怎样做到开机启动
在文件最后加入以下内容后保存:
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
3.创建rc.local文件
sudo vi /etc/rc.local
将以下内容复制到
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo "this shows rc.local is start onboot" > /usr/local/rc-local-info.log
# add your scritp here
echo 100 >/sys/devices/pwm-fan/target_pwm
exit 0
保存后,添加执行权限 chmod 755 /etc/rc.local
这段shell 脚本主要是添加了 echo 100 >/sys/devices/pwm-fan/target_pwm 将风扇的pwm 调到了100,原因参考我的另一篇博客,开启风扇
4.建立软链接
systemd 默认读取 /etc/systemd/system 下的配置文件, 所以还需要在 /etc/systemd/system 目录下创建软链接
sudo ln -s /lib/systemd/system/rc.local.service /etc/systemd/system/
启用服务并启动
sudo systemctl enable rc-local
sudo systemctl start rc-local.service
sudo systemctl status rc-local.service
重启即可自动开启风扇。