Ask Your Question
2

Turning off discrete videocard systemd service

asked 2013-08-14 03:29:19 -0500

polarfish gravatar image

updated 2013-08-14 05:23:24 -0500

I want to turn off discrete video card on system startup. I could do it as a root with next command:

$ echo OFF > /sys/kernel/debug/vgaswitcheroo/switch
$ cat /sys/kernel/debug/vgaswitcheroo/switch
0:IGD:+:Pwr:0000:00:02.0
1:DIS: :Off:0000:01:00.0

To automate it process I've decided to create startup service:

$ cd /etc/systemd/system/
$ touch discrete-video-off.service
$ cat > discrete-video-off.service
[Unit]
Description=Turns off discrete video card

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/usr/bin/echo OFF > /sys/kernel/debug/vgaswitcheroo/switch
ExecStop=/usr/bin/echo ON > /sys/kernel/debug/vgaswitcheroo/switch

[Install]
WantedBy=multi-user.target
^C
$ systemctl enable discrete-video-off.service

After reboot - service has been executed succesfully but discrete video card still gets power.

$ sudo systemctl status discrete-video-off.service
discrete-video-off.service - Turns off discrete video card
   Loaded: loaded (/etc/systemd/system/discrete-video-off.service; enabled)
   Active: active (exited) since Wed 2013-08-14 11:10:09 EEST; 4min 34s ago
  Process: 420 ExecStart=/usr/bin/echo OFF > /sys/kernel/debug/vgaswitcheroo/switch (code=exited, status=0/SUCCESS)
$ sudo cat /sys/kernel/debug/vgaswitcheroo/switch
0:IGD:+:Pwr:0000:00:02.0
1:DIS: :Pwr:0000:01:00.0
edit retag flag offensive close merge delete

Comments

Is this all even neede if I switched the discrete graphics in the BIOS? Please answer here if you know https://ask.fedoraproject.org/question/28239/how-to-make-sure-the-discrete-grahics-is-disabled/

Bucic gravatar imageBucic ( 2013-09-05 06:34:05 -0500 )edit

I suppose, if you turned off your discrete graphic card in the BIOS, you shouldn't bother about "my solution" (service that uses vgaswitcheroo/switch). Just wonder what cat /sys/kernel/debug/vgaswitcheroo/switch returns in your case? PS my BIOS doesn't provide "turning videocards off" option

polarfish gravatar imagepolarfish ( 2013-09-06 08:18:22 -0500 )edit

@polarfish I'd rather not fiddle with switcheroo (I don't have it installed).

Bucic gravatar imageBucic ( 2013-09-10 05:23:13 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-08-15 09:38:15 -0500

notting gravatar image

Just to close the loop - ExecStart is a command to execute, not a shell - if you want to redirect stdout/stderr, you need to wrap it in a /bin/sh command as you found.

edit flag offensive delete link more
2

answered 2013-08-15 02:06:13 -0500

polarfish gravatar image

updated 2013-09-04 06:02:20 -0500

I've found someone who has already wrote such service: http://github.com/fredoche/vgaswitcheroo_systemd/blob/master/vgaswitcheroo.service

Solution was to replace this:

ExecStart=/usr/bin/echo OFF > /sys/kernel/debug/vgaswitcheroo/switch
ExecStop=/usr/bin/echo ON > /sys/kernel/debug/vgaswitcheroo/switch

With that:

ExecStart=/usr/bin/sh -c "echo OFF > /sys/kernel/debug/vgaswitcheroo/switch"
ExecStop=/usr/bin/sh -c "echo ON > /sys/kernel/debug/vgaswitcheroo/switch"

If someone reads this answer with goal to implement his own service - look at link above, that guy did better job than me.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-08-14 03:29:19 -0500

Seen: 2,846 times

Last updated: Sep 04 '13