Skip to content

Instantly share code, notes, and snippets.

@bedawi
Created February 5, 2023 09:37
Show Gist options
  • Save bedawi/8bcba545007a57e748d9208809a408a9 to your computer and use it in GitHub Desktop.
Save bedawi/8bcba545007a57e748d9208809a408a9 to your computer and use it in GitHub Desktop.
MacBookPro5,3, Fedora Linux: Disable discrete GPU and optimize power consumption
#!/bin/bash
echo 1 > /sys/bus/pci/devices/0000\:02\:00.0/remove

The attached Ansible playbook helps setting up Fedora Linux on a 2009 Macbook Pro with dual Nvidia graphics.

Only applies when for the specific Macbook Pro with dual Nvidia graphics

lspci | grep VGA
02:00.0 VGA compatible controller: NVIDIA Corporation G96CM [GeForce 9600M GT] (rev a1)
03:00.0 VGA compatible controller: NVIDIA Corporation C79 [GeForce 9400M] (rev b1)

Problems solved:

  1. Monitor shows wrong virtual display
  2. High energy consumption

Solutions applied:

  1. Disable GeForce 9600M GT permanently at boot time
  2. Replace energy management with TLP

How is it done?

The Ansible playbook sets up a systemd service which turns off the GeForce 9600M GT during boot. TLP is being installed and power-profiles-daemon is being removed

Step by step

  1. Connect the device with an ethernet cable
  2. Install Fedora 35 (37 does not install on old Macs, 36 might - I am not sure)
  3. After installation you see only a blank screen. Reboot, temporarily (only for this boot) add the following parameters to grub:
nouveau.modeset=0 rd.driver.blacklist=nouveau video=vesa:off
  1. finish the installation
  2. Open a terminal
  3. Clone this gist into Downloads folder
git clone <this gist>
cd <this gist>
sudo dnf -y install ansible
sudo ansible-playbook macbookpro53-setup.yml
  1. Reboot without the grub paramters from step 3
  2. Enjoy, update Fedora 35 and then upgrade to the latest Fedora Linux
---
- name: macbookpro53-setup.yml
# This is the host or host group to apply this playbook to. Set to "localhost" optionally.
hosts: localhost
tasks:
- name: Deploy Script to disable discrete GPU
ansible.builtin.copy:
src: disabledgpu.sh
dest: /usr/local/bin/disabledgpu.sh
mode: 0755
owner: root
group: root
- name: Restore SELinux-Context for disabledgpu script
ansible.builtin.command: restorecon -v /usr/local/bin/disabledgpu.sh
- name: Deploying service to disable discrete GPU
blockinfile:
path: /etc/systemd/system/disabledgpu.service
create: yes
block: |
[Unit]
Description=Custom startup script
Requires=multi-user.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/disabledgpu.sh
[Install]
RequiredBy=graphical.target
owner: root
group: root
- name: Update systemd (daemon-reload) and enable disabledgpu
ansible.builtin.systemd:
name: disabledgpu
enabled: yes
daemon_reload: yes
- name: Installing latest version of TLP
ansible.builtin.dnf:
name:
- tlp
- tlp-rdw
state: latest
- name: Removing power-profiles-daemon
ansible.builtin.dnf:
name:
- power-profiles-daemon
state: absent
- name: Starting and enabling TLP
ansible.builtin.systemd:
name: tlp.service
enabled: yes
state: started
- name: Masking systemd-rfkill.service
ansible.builtin.systemd:
name: systemd-rfkill.service
masked: yes
- name: Masking systemd-rfkill.socket
ansible.builtin.systemd:
name: systemd-rfkill.socket
masked: yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment