我需要在 Debian linux 启动时将补丁 ram 应用到蓝牙芯片。此补丁使用 /dev/mem
重置 GPIO。此更新的蓝牙初始化脚本包含在 /etc/init.d/bluetooth
中。
我的bluetooth.service
是
[Unit]
Description=Bluetooth service
Documentation=man:bluetoothd(8)
[Service]
Type=dbus
BusName=org.bluez
ExecStart=/etc/init.d/bluetooth start
User=root
NotifyAccess=main
[Install]
WantedBy=bluetooth.target
Alias=dbus-org.bluez.service
但是,当我重新启动时,我收到一条错误消息“无法打开/dev/mem:不允许操作”
我知道 /dev/mem
只能由 root 访问,但我不是以 root 身份运行我的初始化脚本吗?
最佳答案
明明说你没有运行脚本的权限,你可以
您需要以 root 用户身份运行脚本
ExecStart=/etc/init.d/bluetooth 启动
此命令应以根用户身份运行
只需以 root 身份登录并重新运行脚本
系统启动时运行脚本
在/etc/init.d/目录中创建一个名为 bluetooth.service 的脚本(以 root 身份登录)
vi/etc/init.d/bluetooth.service
设置脚本的可执行权限:
chmod +x/etc/init.d/bluetooth.service
确保每次 Debian Linux 系统启动/启动时执行此脚本:
update-rc.d bluetooth.service 默认为 100
其中,bluetooth.service: 是你的启动脚本名称 defaults :参数“defaults”指的是默认运行级别,即 2 到 5。 100 :数字 100 表示脚本将在任何包含数字 101 的脚本之前执行。 只需运行命令
ls –l /etc/rc3.d/
此命令将使用数字软链接(soft link)到/etc/init.d。
下次您重新启动系统时,您的自定义命令或脚本将通过 bluetooth.services 执行。对
- 在系统启动时执行shell脚本 打开/etc/init.d/目录下的 bluetooth.service 文件
关于linux - 无法使用 systemctl 以 root 身份运行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31258141/