Answers:
主要有两种方法可以做到这一点:
systemd服务运行脚本。因此,您需要两个文件:脚本和.service文件(单元配置文件)。
确保您的脚本是可执行文件,并且第一行(shebang)是#!/bin/sh。然后在中创建.service文件/etc/systemd/system(纯文本文件,称为vgaoff.service)。
例如:
/usr/bin/vgaoff/etc/systemd/system/vgaoff.service现在,编辑单位文件。其内容取决于脚本的工作方式:
如果vgaoff只是关闭GPU,例如:
exec blah-blah pwrOFF etc 
则其内容vgaoff.service应为:
[Unit]
Description=Power-off gpu
[Service]
Type=oneshot
ExecStart=/usr/bin/vgaoff
[Install]
WantedBy=multi-user.target
如果vgaoff用于关闭GPU电源并重新打开电源,例如:
start() {
  exec blah-blah pwrOFF etc
}
stop() {
  exec blah-blah pwrON etc
}
case $1 in
  start|stop) "$1" ;;
esac
则其内容vgaoff.service应为:
[Unit]
Description=Power-off gpu
[Service]
Type=oneshot
ExecStart=/usr/bin/vgaoff start
ExecStop=/usr/bin/vgaoff stop
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
关机:
[Unit]
Description=Power-off gpu
[Service]
Type=oneshot
ExecStart=/bin/sh -c "echo OFF > /whatever/vga_pwr_gadget/switch"
[Install]
WantedBy=multi-user.target
打开和关闭电源:
[Unit]
Description=Power-off gpu
[Service]
Type=oneshot
ExecStart=/bin/sh -c "echo OFF > /whatever/vga_pwr_gadget/switch"
ExecStop=/bin/sh -c "echo ON > /whatever/vga_pwr_gadget/switch"
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
完成文件处理后,启用服务:
systemctl enable vgaoff.service
它将在下次启动时自动启动。您甚至可以一次启用并启动服务
systemctl enable --now vgaoff.service
截至systemd v.220(在较旧的设置中,您必须手动启动)。
有关更多详细信息,请参见systemd.service手册页。
故障排除。
从这里开始:
如何查看systemd服务的完整日志?
systemd服务出口代码和状态信息说明
echo SOMETHING > /some/file功能(或实际上是任何其他命令)的人们在尝试在系统上运行内容之前应熟悉CLI的基础知识。另外,FYI,请阅读如何在几种笔记本电脑型号上关闭dGPU,看看那里使用的命令是否可以用您建议的内容代替。另外,要恢复原始文件,通常需要重新安装拥有该文件的软件包。