Skip to content

Instantly share code, notes, and snippets.

@satmandu
Last active February 25, 2025 16:44
Show Gist options
  • Save satmandu/4e17a3e8a67f04275049679671a32b9d to your computer and use it in GitHub Desktop.
Save satmandu/4e17a3e8a67f04275049679671a32b9d to your computer and use it in GitHub Desktop.
Nvidia drivers with Ubuntu 25.04 for MacBookPro11,3 (Mid-2014 15"MBP) on top of kernel 6.14.0-rc4

For anyone trying to get this working on Ubuntu 25.04, I created the necessary deb packages as follows, which works on my MacBookPro11,3:

mkdir -p ~/src/nvidia
cd ~/src/nvidia
curl -Olf http://archive.ubuntu.com/ubuntu/pool/restricted/n/nvidia-graphics-drivers-470/nvidia-graphics-drivers-470_470.256.02.orig-amd64.tar.gz
curl -OLf http://archive.ubuntu.com/ubuntu/pool/restricted/n/nvidia-graphics-drivers-470/nvidia-graphics-drivers-470_470.256.02.orig.tar.gz
git clone https://github.com/canonical/nvidia-graphics-drivers.git
cd nvidia-graphics-drivers
git checkout 470
tar fx nvidia-graphics-drivers-470_470.256.02.orig-amd64.tar.gz
mv nvidia-graphics-drivers-470.orig-amd64amd64

sudo tee debian/templates/dkms_nvidia.conf.in >/dev/null <<'EOF'
PACKAGE_NAME="nvidia"
PACKAGE_VERSION="#VERSION#"
CLEAN="make clean"
BUILT_MODULE_NAME[0]="nvidia"
DEST_MODULE_LOCATION[0]="/kernel/drivers/char/drm"
PROCS_NUM=`nproc`
[ $PROCS_NUM -gt 16 ] && PROCS_NUM=16
MAKE[0]="unset ARCH; env NV_VERBOSE=1 \
    'make' -j$PROCS_NUM NV_EXCLUDE_BUILD_MODULES='#NVEXCLUDEMODULES#' KERNEL_UNAME=${kernelver} IGNORE_XEN_PRESENCE=1 IGNORE_CC_MISMATCH=1 SYSSRC=$kernel_source_dir LD=/usr/bin/ld.bfd CONFIG_X86_KERNEL_IBT= modules"
BUILT_MODULE_NAME[1]="nvidia-modeset"
DEST_MODULE_LOCATION[1]="/kernel/drivers/char/drm"
BUILT_MODULE_NAME[2]="nvidia-drm"
DEST_MODULE_LOCATION[2]="/kernel/drivers/char/drm"
AUTOINSTALL="yes"
PATCH[0]="disable_fstack-clash-protection_fcf-protection.patch"
PATCH[1]="kernel-6.10.patch"
PATCH[2]="0001-Fix-conftest-to-ignore-implicit-function-declaration.patch"
PATCH[3]="0002-Fix-conftest-to-use-a-short-wchar_t.patch"
PATCH[4]="0003-Fix-conftest-to-use-nv_drm_gem_vmap-which-has-the-se.patch"
PATCH[5]="nvidia-470xx-fix-linux-6.12.patch"
PATCH[6]="nvidia-470xx-fix-linux-6.13.patch"
PATCH[7]="nvidia-470xx-fix-linux-6.14.patch"
# Apply from v4 to v5.12 kernels
# v5.13 kernels already disable both by default
# v5.19 kernels may need cf-protection=branch
PATCH_MATCH[0]='^(4\.[0-9]*)|(5\.[0-9]\.0)|(5\.1[0-2]\.0)'
EOF
cd debian/dkms_nvidia/patches
curl -OLf https://aur.archlinux.org/cgit/aur.git/plain/kernel-6.10.patch?h=nvidia-470xx-utils&id=df0426ab325cb0ad8909a3058d66336ce1f872ce
curl -Olf https://aur.archlinux.org/cgit/aur.git/plain/0001-Fix-conftest-to-ignore-implicit-function-declaration.patch?h=nvidia-470xx-utils&id=df0426ab325cb0ad8909a3058d66336ce1f872ce
curl -OLf https://aur.archlinux.org/cgit/aur.git/plain/0002-Fix-conftest-to-use-a-short-wchar_t.patch?h=nvidia-470xx-utils&id=df0426ab325cb0ad8909a3058d66336ce1f872ce
curl -OLf https://aur.archlinux.org/cgit/aur.git/plain/0003-Fix-conftest-to-use-nv_drm_gem_vmap-which-has-the-se.patch?h=nvidia-470xx-utils&id=df0426ab325cb0ad8909a3058d66336ce1f872ce
curl -Olf https://gist.github.com/joanbm/a6d3f7f873a60dec0aa4a734c0f1d64e/raw/6bae5606c033b6c6c08233523091992370e357b7/nvidia-470xx-fix-linux-6.12.patch
curl -OLf https://gist.github.com/joanbm/d1f89391a4b20f4b56ba931ef6ca62da/raw/8458c7c58249a0dceb5ab1b5aada7e705a88b4ff/nvidia-470xx-fix-linux-6.13.patch
curl -OLf https://gist.github.com/joanbm/d0cb8790ca610fbd2c2e43f30707ce18/raw/acdef6aac381bf6d8a21d095b673b644a188c2b9/nvidia-470xx-fix-linux-6.14.patch
cd ../../../
sudo apt install -y execstack dh-modaliases xserver-xorg-dev  libkmod-dev libnvidia-egl-wayland1
sudo apt install -y dpkg-dev devscripts

# This is where you can run dch -i to change the distribution, add comments, etc to the changelog.
# dch -i

export DEB_CFLAGS_MAINT_APPEND="-flto=auto -pipe -O3 -ffat-lto-objects -fipa-pta -fno-semantic-interposition -fdevirtualize-at-ltrans"
export DEB_CXXFLAGS_MAINT_APPEND="-flto=auto -pipe -O3 -ffat-lto-objects -fipa-pta -fno-semantic-interposition -fdevirtualize-at-ltrans"
export DEB_LDFLAGS_MAINT_APPEND="-flto"
dpkg-buildflags
export DEB_BUILD_OPTIONS="noddebs nocheck nodoc"
export DPKG_GENSYMBOLS_CHECK_LEVEL=0
sudo rm *build-deps*.buildinfo
sudo rm *build-deps*.changes
sudo rm *.deb
dpkg-source -b .
debuild -S -sa
nice -n 20 debuild -us -uc -d
cd ..
mkdir disabled
mv *headless* disabled/
sudo apt install -y *470_470*.deb
sudo apt install -y nvidia-vaapi-driver

sudo tee /etc/modprobe.d/enable-nvidia-modeset.conf >/dev/null <<'EOF'
options nvidia-drm modeset=1
EOF

tee -a ~/.bashrc >/dev/null <<'EOF'
# Nvidia tweaks
export MOZ_DISABLE_RDD_SANDBOX=1
export LIBVA_DRIVER_NAME=nvidia
export __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/10_nvidia.json
# egl is the non-default NVD_BACKEND option
# NVD_BACKEND=direct
EOF

sudo update-initramfs -u -k all

# Setup MacBookPro11,3 to boot up with NVIDIA gpu enabled.
git clone https://github.com/0xbb/gpu-switch.git
cd gpu-switch
sudo ./gpu-switch -d

# Force GDM to use X11 since this NVIDA driver doesn't support GBM.
sudo sed -i 's/# WaylandEnable=false/WaylandEnable=false/' /etc/gdm3/custom.conf

# Reboot and follow rhe instructions at 
# https://github.com/elFarto/nvidia-vaapi-driver?tab=readme-ov-file#firefox to allow Firefox to use acceleration.
# You may also have to run nvidia-settings and save a config from there to /etc/X11/xorg.conf.d/99-nvidia.conf
# (I was not able to do this from the nvidia-settings app directly.)
# Some useful information was also here:
# https://github.com/hemzaz/nvidia-acceleration-on-ubuntu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment