mirror of
https://github.com/JaKooLit/Debian-Hyprland.git
synced 2026-02-05 17:50:14 +01:00
Updated nvidia.sh to opt install proprietary/open drivers
Added HOWTO guide on using script Renamed original `nvidia.sh` script just in case On branch development Your branch is up to date with 'origin/development'. Changes to be committed: modified: CHANGELOG.md new file: HOWTO-Install-NVIDIA-drivers-in-Debian.md new file: install-scripts/nvidia-ori.sh modified: install-scripts/nvidia.sh
This commit is contained in:
parent
3e1ba4427f
commit
71031dccd8
11
CHANGELOG.md
11
CHANGELOG.md
@ -1,5 +1,16 @@
|
||||
## CHANGELOG
|
||||
|
||||
## 05 February 2026
|
||||
|
||||
- Updated `nvidia.sh`
|
||||
- Options to install:
|
||||
- Debian drivers (older NVIDIA GPUs)
|
||||
- For more recent NVIDIA GPUs
|
||||
- NVIDIA propriertary drivers
|
||||
- NVIDIA open drivers
|
||||
- You can switch between them later
|
||||
- Read `HOWTO-Install-NVIDIA-Drivers-in-Debian.md`
|
||||
|
||||
## 04 February 2026
|
||||
|
||||
- Updated Hyprland to current revision
|
||||
|
||||
157
HOWTO-Install-NVIDIA-drivers-in-Debian.md
Normal file
157
HOWTO-Install-NVIDIA-drivers-in-Debian.md
Normal file
@ -0,0 +1,157 @@
|
||||
# HOWTO: Install NVIDIA drivers on Debian 13+/testing/unstable
|
||||
|
||||
This guide explains how to install and maintain NVIDIA GPU drivers on Debian 13 (trixie), testing, and unstable using `install-scripts/nvidia.sh`.
|
||||
|
||||
Supported scope
|
||||
|
||||
- Debian 13 (trixie), Debian testing, Debian unstable.
|
||||
- Current-generation NVIDIA GPUs are best served by NVIDIA’s own repository (cuda-drivers or nvidia-open). Avoid Debian’s `nvidia-driver` for new cards.
|
||||
|
||||
Quick start
|
||||
|
||||
```bash
|
||||
# Interactive (recommended first run)
|
||||
install-scripts/nvidia.sh
|
||||
|
||||
# Install from NVIDIA CUDA repo (proprietary)
|
||||
install-scripts/nvidia.sh --mode=nvidia
|
||||
|
||||
# Install from NVIDIA CUDA repo (open kernel modules)
|
||||
install-scripts/nvidia.sh --mode=open
|
||||
|
||||
# Install Debian-packaged drivers (older; not recommended for new GPUs)
|
||||
install-scripts/nvidia.sh --mode=debian
|
||||
```
|
||||
|
||||
## What the script does
|
||||
|
||||
- Detects your GPU (prefers `nvidia-smi`, falls back to `lspci`).
|
||||
- Offers three installation paths (see below).
|
||||
- For NVIDIA repo paths:
|
||||
- Ensures the CUDA APT repo/keyring for Debian 13 is configured (idempotent).
|
||||
- Installs the selected meta package: `cuda-drivers` (proprietary) or `nvidia-open` (open kernel modules).
|
||||
- Adds kernel parameters to blacklist nouveau and enable DRM KMS, updates GRUB, and updates initramfs.
|
||||
- Runs a post-install verification (driver source, module loaded, `nvidia-smi`/OpenGL summary).
|
||||
- Prints an end-of-run summary of changes.
|
||||
|
||||
## Options and when to use them
|
||||
|
||||
- NVIDIA CUDA repo — proprietary (`--mode=nvidia`)
|
||||
- Installs `cuda-drivers` from NVIDIA’s APT repo. Best compatibility and newest drivers; recommended for RTX 30/40/50 series.
|
||||
- NVIDIA CUDA repo — open kernel modules (`--mode=open`)
|
||||
- Installs `nvidia-open` from NVIDIA’s APT repo. Uses the open-source kernel modules. Consider this if you prefer open modules and your GPU is supported.
|
||||
- Debian repo — packaged by Debian (`--mode=debian`)
|
||||
- Installs `nvidia-driver` and related packages from Debian. Typically older; acceptable for older GPUs, not recommended for current-generation cards.
|
||||
|
||||
## Important warnings shown by the script
|
||||
|
||||
When run interactively, the script displays this notice:
|
||||
|
||||
```
|
||||
[WARN] Default installs Debian repo NVIDIA drivers (often older).
|
||||
[WARN] NVIDIA driver options are currently in development.
|
||||
[WARN] If you have a current‑generation NVIDIA GPU, do NOT use Debian-based drivers.
|
||||
Choose an NVIDIA CUDA repo option below, or install drivers manually and re-run the Debian Hyprland install.
|
||||
[ACTION] Choose installation source:
|
||||
[D] Debian repo (default) — installs nvidia-driver and related pkgs
|
||||
[N] NVIDIA CUDA repo — installs cuda-drivers (proprietary)
|
||||
[O] NVIDIA CUDA repo — installs nvidia-open (open kernel modules)
|
||||
Select [D/n/o]: _
|
||||
```
|
||||
|
||||
## Non-interactive flags
|
||||
|
||||
- `--mode=debian|nvidia|open` Selects installation path.
|
||||
- `--switch` Switch from your current variant to the target mode (removes conflicting meta-packages).
|
||||
- `--force` Don’t exit early if already configured; re-run installs.
|
||||
- `-n, --dry-run` Simulate actions (uses `apt-get -s`, prints changes without applying).
|
||||
- `-h, --help` Show usage, options, and examples.
|
||||
|
||||
Examples
|
||||
|
||||
```bash
|
||||
# Switch from Debian-packaged driver to proprietary CUDA repo driver
|
||||
install-scripts/nvidia.sh --mode=nvidia --switch
|
||||
|
||||
# Re-run Debian path even if already configured
|
||||
install-scripts/nvidia.sh --mode=debian --force
|
||||
|
||||
# Dry-run the open-kernel flow without making changes
|
||||
install-scripts/nvidia.sh --mode=open --dry-run
|
||||
```
|
||||
|
||||
## Sample outputs
|
||||
|
||||
GPU detection
|
||||
|
||||
```
|
||||
[INFO] Detecting NVIDIA GPU...
|
||||
[OK] Detected (nvidia-smi): NVIDIA GeForce RTX 3050, 590.48.01
|
||||
```
|
||||
|
||||
(If drivers are not yet loaded, it falls back to `lspci` output.)
|
||||
|
||||
Post-install verification
|
||||
|
||||
```
|
||||
[INFO] Verifying NVIDIA installation...
|
||||
[OK] Driver source detected: proprietary (NVIDIA CUDA repo)
|
||||
[INFO] Kernel module loaded: yes
|
||||
[OK] nvidia-smi: NVIDIA GeForce RTX 3050, 590.48.01
|
||||
[INFO] OpenGL summary:
|
||||
OpenGL vendor string: NVIDIA Corporation
|
||||
OpenGL renderer string: NVIDIA GeForce RTX 3050/PCIe/SSE2
|
||||
OpenGL core profile version string: 4.6.0 NVIDIA 590.48.01
|
||||
```
|
||||
|
||||
End-of-run summary
|
||||
|
||||
```
|
||||
[OK] No changes made.
|
||||
```
|
||||
|
||||
Or, when changes occurred:
|
||||
|
||||
```
|
||||
[OK] Changes applied:
|
||||
- configured NVIDIA CUDA repo (debian13)
|
||||
- apt install: cuda-drivers
|
||||
- updated GRUB_CMDLINE_LINUX in /etc/default/grub
|
||||
- update-grub
|
||||
- update-initramfs -u
|
||||
```
|
||||
|
||||
Early exit when re-running
|
||||
|
||||
```
|
||||
[OK] NVIDIA is already configured for mode: nvidia
|
||||
[INFO] Use --force to re-run installs, or --switch to change variants.
|
||||
```
|
||||
|
||||
## What gets changed on your system
|
||||
|
||||
- APT: Adds/uses NVIDIA’s CUDA repo (Debian 13 path) via `cuda-keyring` (only if missing).
|
||||
- GRUB: Appends `rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 rcutree.rcu_idle_gp_delay=1` to `GRUB_CMDLINE_LINUX` and runs `update-grub`.
|
||||
- Modules: Ensures `nvidia nvidia_modeset nvidia_uvm nvidia_drm` are added to `/etc/initramfs-tools/modules`, then runs `update-initramfs -u`.
|
||||
|
||||
All changes are idempotent; re-running won’t duplicate entries. The script prints a clear summary of what, if anything, changed.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- Reboot required: After installing drivers, a reboot is often needed for the `nvidia` kernel module to load.
|
||||
- `nvidia-smi` missing: If `nvidia-smi` isn’t found right away, ensure the installation completed and reboot.
|
||||
- Switching variants: Use `--switch` with `--mode=...` to change between Debian, proprietary CUDA, and open kernel module variants; the script removes conflicting meta-packages first.
|
||||
|
||||
## Uninstall / switching notes
|
||||
|
||||
The meta-packages are mutually exclusive per variant:
|
||||
|
||||
- Debian: `nvidia-driver`
|
||||
- Proprietary CUDA: `cuda-drivers`
|
||||
- Open modules: `nvidia-open`
|
||||
|
||||
When switching, the script purges the conflicting meta-packages and runs `apt autoremove` before installing the target.
|
||||
|
||||
---
|
||||
|
||||
If you prefer to install drivers manually (outside the script), do so first, then re-run the Debian Hyprland installer, say `No` to installing NVIDIA, to continue with the rest of the setup.
|
||||
109
install-scripts/nvidia-ori.sh
Executable file
109
install-scripts/nvidia-ori.sh
Executable file
@ -0,0 +1,109 @@
|
||||
#!/bin/bash
|
||||
# 💫 https://github.com/JaKooLit 💫 #
|
||||
# Nvidia - Check Readme for more details for the drivers #
|
||||
# UBUNTU USERS, FOLLOW README!
|
||||
|
||||
nvidia_pkg=(
|
||||
nvidia-driver
|
||||
firmware-misc-nonfree
|
||||
nvidia-kernel-dkms
|
||||
linux-headers-$(uname -r)
|
||||
libnvidia-egl-wayland1
|
||||
libva-wayland2
|
||||
libnvidia-egl-wayland1
|
||||
nvidia-vaapi-driver
|
||||
)
|
||||
|
||||
## WARNING: DO NOT EDIT BEYOND THIS LINE IF YOU DON'T KNOW WHAT YOU ARE DOING! ##
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
# Change the working directory to the parent directory of the script
|
||||
PARENT_DIR="$SCRIPT_DIR/.."
|
||||
cd "$PARENT_DIR" || { echo "${ERROR} Failed to change directory to $PARENT_DIR"; exit 1; }
|
||||
|
||||
# Source the global functions script
|
||||
if ! source "$(dirname "$(readlink -f "$0")")/Global_functions.sh"; then
|
||||
echo "Failed to source Global_functions.sh"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Set the name of the log file to include the current date and time
|
||||
LOG="Install-Logs/install-$(date +%d-%H%M%S)_nvidia.log"
|
||||
MLOG="install-$(date +%d-%H%M%S)_nvidia2.log"
|
||||
|
||||
## adding the deb source for nvidia driver
|
||||
# Create a backup of the sources.list file
|
||||
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup 2>&1 | tee -a "$LOG"
|
||||
|
||||
## UBUNTU - NVIDIA (comment this two by adding # you dont need this!)
|
||||
# Add the comment and repository entry to sources.list
|
||||
echo "## for nvidia" | sudo tee -a /etc/apt/sources.list 2>&1 | tee -a "$LOG"
|
||||
echo "deb http://deb.debian.org/debian/ trixie main contrib non-free non-free-firmware" | sudo tee -a /etc/apt/sources.list 2>&1 | tee -a "$LOG"
|
||||
|
||||
# Update the package list
|
||||
sudo apt update
|
||||
|
||||
# Function to add a value to a configuration file if not present
|
||||
add_to_file() {
|
||||
local config_file="$1"
|
||||
local value="$2"
|
||||
|
||||
if ! sudo grep -q "$value" "$config_file"; then
|
||||
echo "Adding $value to $config_file"
|
||||
sudo sh -c "echo '$value' >> '$config_file'"
|
||||
else
|
||||
echo "$value is already present in $config_file."
|
||||
fi
|
||||
}
|
||||
|
||||
# Install additional Nvidia packages
|
||||
printf "${YELLOW} Installing ${SKY_BLUE}Nvidia packages${RESET} ...\n"
|
||||
for NVIDIA in "${nvidia_pkg[@]}"; do
|
||||
install_package "$NVIDIA" "$LOG"
|
||||
done
|
||||
|
||||
# adding additional nvidia-stuff
|
||||
printf "${YELLOW} adding ${SKY_BLUE}nvidia-stuff${RESET} to /etc/default/grub..."
|
||||
|
||||
# Additional options to add to GRUB_CMDLINE_LINUX
|
||||
additional_options="rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 rcutree.rcu_idle_gp_delay=1"
|
||||
|
||||
# Check if additional options are already present in GRUB_CMDLINE_LINUX
|
||||
if grep -q "GRUB_CMDLINE_LINUX.*$additional_options" /etc/default/grub; then
|
||||
echo "GRUB_CMDLINE_LINUX already contains the additional options"
|
||||
else
|
||||
# Append the additional options to GRUB_CMDLINE_LINUX
|
||||
sudo sed -i "s/GRUB_CMDLINE_LINUX=\"/GRUB_CMDLINE_LINUX=\"$additional_options /" /etc/default/grub
|
||||
echo "Added the additional options to GRUB_CMDLINE_LINUX"
|
||||
fi
|
||||
|
||||
# Update GRUB configuration
|
||||
sudo update-grub 2>&1 | tee -a "$LOG"
|
||||
|
||||
# Define the configuration file and the line to add
|
||||
config_file="/etc/modprobe.d/nvidia.conf"
|
||||
line_to_add="""
|
||||
options nvidia-drm modeset=1 fbdev=1
|
||||
options nvidia NVreg_PreserveVideoMemoryAllocations=1
|
||||
"""
|
||||
|
||||
# Check if the config file exists
|
||||
if [ ! -e "$config_file" ]; then
|
||||
echo "Creating $config_file"
|
||||
sudo touch "$config_file" 2>&1 | tee -a "$LOG"
|
||||
fi
|
||||
|
||||
add_to_file "$config_file" "$line_to_add"
|
||||
|
||||
# Add NVIDIA modules to initramfs configuration
|
||||
modules_to_add="nvidia nvidia_modeset nvidia_uvm nvidia_drm"
|
||||
modules_file="/etc/initramfs-tools/modules"
|
||||
|
||||
if [ -e "$modules_file" ]; then
|
||||
add_to_file "$modules_file" "$modules_to_add" 2>&1 | tee -a "$LOG"
|
||||
sudo update-initramfs -u 2>&1 | tee -a "$LOG"
|
||||
else
|
||||
echo "Modules file ($modules_file) not found." 2>&1 | tee -a "$LOG"
|
||||
fi
|
||||
|
||||
printf "\n%.0s" {1..2}
|
||||
@ -3,6 +3,12 @@
|
||||
# Nvidia - Check Readme for more details for the drivers #
|
||||
# UBUNTU USERS, FOLLOW README!
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
DRY_RUN=0
|
||||
CHANGES=()
|
||||
|
||||
# Default Debian repo packages (can be older than NVIDIA repo)
|
||||
nvidia_pkg=(
|
||||
nvidia-driver
|
||||
firmware-misc-nonfree
|
||||
@ -31,54 +37,303 @@ fi
|
||||
LOG="Install-Logs/install-$(date +%d-%H%M%S)_nvidia.log"
|
||||
MLOG="install-$(date +%d-%H%M%S)_nvidia2.log"
|
||||
|
||||
## adding the deb source for nvidia driver
|
||||
# Create a backup of the sources.list file
|
||||
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup 2>&1 | tee -a "$LOG"
|
||||
# ---------------- helpers ----------------
|
||||
run_cmd() {
|
||||
if [ "$DRY_RUN" -eq 1 ]; then
|
||||
echo "[DRY-RUN] $*"
|
||||
else
|
||||
eval "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
## UBUNTU - NVIDIA (comment this two by adding # you dont need this!)
|
||||
# Add the comment and repository entry to sources.list
|
||||
echo "## for nvidia" | sudo tee -a /etc/apt/sources.list 2>&1 | tee -a "$LOG"
|
||||
echo "deb http://deb.debian.org/debian/ trixie main contrib non-free non-free-firmware" | sudo tee -a /etc/apt/sources.list 2>&1 | tee -a "$LOG"
|
||||
record_change() {
|
||||
# $1: message
|
||||
if [ "$DRY_RUN" -eq 0 ]; then
|
||||
CHANGES+=("$1")
|
||||
fi
|
||||
}
|
||||
|
||||
# Update the package list
|
||||
sudo apt update
|
||||
_which() { command -v "$1" >/dev/null 2>&1; }
|
||||
|
||||
_detect_cuda_suite() {
|
||||
# We only support Debian 13+; use debian13 path for testing/unstable as well
|
||||
local codename
|
||||
codename=$(. /etc/os-release; echo "${DEBIAN_CODENAME:-${VERSION_CODENAME:-}}")
|
||||
case "$codename" in
|
||||
trixie|sid) echo "debian13" ;;
|
||||
*) echo "debian13" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
detect_variant() {
|
||||
if dpkg -l | grep -q -E '^ii\s+nvidia-open\b'; then echo open; return; fi
|
||||
if dpkg -l | grep -q -E '^ii\s+cuda-drivers\b'; then echo nvidia; return; fi
|
||||
if dpkg -l | grep -q -E '^ii\s+nvidia-driver\b'; then echo debian; return; fi
|
||||
echo none
|
||||
}
|
||||
|
||||
_apt_update_once() {
|
||||
echo -e "${INFO} Refreshing APT package lists..."
|
||||
if [ "$DRY_RUN" -eq 1 ]; then
|
||||
echo "[DRY-RUN] sudo apt update"
|
||||
else
|
||||
sudo apt update 2>&1 | tee -a "$LOG"
|
||||
fi
|
||||
}
|
||||
|
||||
apt_install() {
|
||||
# pass packages as args
|
||||
if [ "$DRY_RUN" -eq 1 ]; then
|
||||
echo "[DRY-RUN] sudo apt-get -s install -y $*"
|
||||
sudo apt-get -s install -y "$@" >/dev/null || true
|
||||
else
|
||||
sudo apt install -y "$@" 2>&1 | tee -a "$LOG"
|
||||
record_change "apt install: $*"
|
||||
fi
|
||||
}
|
||||
|
||||
apt_remove() {
|
||||
# pass packages as args
|
||||
if [ "$DRY_RUN" -eq 1 ]; then
|
||||
echo "[DRY-RUN] sudo apt-get -s remove --purge -y $*"
|
||||
sudo apt-get -s remove --purge -y "$@" >/dev/null || true
|
||||
else
|
||||
sudo apt remove --purge -y "$@" 2>&1 | tee -a "$LOG" || true
|
||||
sudo apt autoremove -y 2>&1 | tee -a "$LOG" || true
|
||||
record_change "apt remove --purge: $*"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_conflicting_for_target() {
|
||||
local target="$1"
|
||||
case "$target" in
|
||||
nvidia) apt_remove nvidia-open nvidia-driver ;;
|
||||
open) apt_remove cuda-drivers nvidia-driver ;;
|
||||
debian) apt_remove cuda-drivers nvidia-open ;;
|
||||
esac
|
||||
}
|
||||
|
||||
_install_via_debian() {
|
||||
echo -e "${INFO} Using Debian repo packages (may be older on testing/unstable)."
|
||||
_apt_update_once
|
||||
printf "${YELLOW} Installing ${SKY_BLUE}NVIDIA packages from Debian${RESET} ...\n"
|
||||
for NVIDIA in "${nvidia_pkg[@]}"; do
|
||||
apt_install "$NVIDIA"
|
||||
done
|
||||
}
|
||||
|
||||
_install_via_nvidia_repo_with() {
|
||||
# $1: package to install from NVIDIA repo (e.g., cuda-drivers or nvidia-open)
|
||||
local package="$1"
|
||||
local suite pkg url
|
||||
suite=$(_detect_cuda_suite)
|
||||
pkg="cuda-keyring_1.1-1_all.deb"
|
||||
url="https://developer.download.nvidia.com/compute/cuda/repos/${suite}/x86_64/${pkg}"
|
||||
|
||||
echo -e "${INFO} Ensuring NVIDIA CUDA repo for ${YELLOW}${suite}${RESET} is configured ..." | tee -a "$LOG"
|
||||
|
||||
# Skip keyring install if already present
|
||||
if dpkg -s cuda-keyring >/dev/null 2>&1 || [ -f "/etc/apt/sources.list.d/cuda-${suite}-x86_64.sources" ]; then
|
||||
echo -e "${OK} NVIDIA CUDA repo already configured." | tee -a "$LOG"
|
||||
else
|
||||
rm -f "$pkg"
|
||||
if [ "$DRY_RUN" -eq 1 ]; then
|
||||
echo "[DRY-RUN] wget -q '$url' -O '$pkg'"
|
||||
else
|
||||
if ! wget -q "$url" -O "$pkg"; then
|
||||
echo -e "${ERROR} Failed to download $pkg from $url" | tee -a "$LOG"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
run_cmd "sudo dpkg -i '$pkg' 2>&1 | tee -a '$LOG'"
|
||||
record_change "configured NVIDIA CUDA repo (${suite})"
|
||||
_apt_update_once
|
||||
fi
|
||||
|
||||
echo -e "${INFO} Installing ${YELLOW}${package}${RESET} from NVIDIA repo ..." | tee -a "$LOG"
|
||||
apt_install "${package}"
|
||||
}
|
||||
|
||||
_install_via_nvidia_repo() {
|
||||
_install_via_nvidia_repo_with "cuda-drivers"
|
||||
}
|
||||
|
||||
_install_via_nvidia_open() {
|
||||
_install_via_nvidia_repo_with "nvidia-open"
|
||||
}
|
||||
|
||||
_prompt_for_mode() {
|
||||
local mode_input=""
|
||||
echo
|
||||
echo -e "${WARN} Default installs ${YELLOW}Debian repo NVIDIA drivers${RESET} (often older)."
|
||||
echo -e "${WARN} ${YELLOW}NVIDIA driver options are currently in development${RESET}."
|
||||
echo -e "${WARN} If you have a current‑generation NVIDIA GPU, ${YELLOW}do NOT use Debian-based drivers${RESET}."
|
||||
echo -e " Choose an NVIDIA CUDA repo option below, or install drivers manually and re-run the Debian Hyprland install."
|
||||
echo -e "${CAT} Choose installation source:"
|
||||
echo -e " [D] Debian repo (default) — installs ${YELLOW}nvidia-driver${RESET} and related pkgs"
|
||||
echo -e " [N] NVIDIA CUDA repo — installs ${YELLOW}cuda-drivers${RESET} (proprietary)"
|
||||
echo -e " [O] NVIDIA CUDA repo — installs ${YELLOW}nvidia-open${RESET} (open kernel modules)"
|
||||
read -r -p "Select [D/n/o]: " mode_input || true
|
||||
case "${mode_input,,}" in
|
||||
o|open) echo "open" ;;
|
||||
n|nv|nvidia) echo "nvidia" ;;
|
||||
d|""|*) echo "debian" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
print_header() {
|
||||
echo -e "${INFO} NVIDIA driver setup (Debian 13+/testing/unstable supported)" \
|
||||
"\n${INFO} Logs: ${YELLOW}$LOG${RESET}"
|
||||
}
|
||||
|
||||
print_gpu_info() {
|
||||
echo -e "${INFO} Detecting NVIDIA GPU..."
|
||||
if _which nvidia-smi; then
|
||||
local line
|
||||
line=$(nvidia-smi --query-gpu=name,driver_version --format=csv,noheader 2>/dev/null | head -n1 || true)
|
||||
if [ -n "$line" ]; then
|
||||
echo -e "${OK} Detected (nvidia-smi): ${YELLOW}$line${RESET}"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
if _which lspci; then
|
||||
local l
|
||||
l=$(lspci -nnk | awk '/VGA|3D|Display/ && /NVIDIA/ {print; getline; print}' | head -n2)
|
||||
if [ -n "$l" ]; then
|
||||
echo -e "${OK} Detected (lspci):\n${YELLOW}$l${RESET}"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
echo -e "${NOTE} Could not positively identify an NVIDIA GPU (drivers may not be loaded yet)."
|
||||
}
|
||||
|
||||
print_usage() {
|
||||
cat <<EOF
|
||||
Usage: ${0##*/} [--mode=debian|nvidia|open] [--switch] [--force] [-n|--dry-run] [-h|--help]
|
||||
|
||||
Description:
|
||||
Installs NVIDIA drivers on Debian 13+/testing/unstable.
|
||||
- Default path installs Debian-packaged drivers (may be older).
|
||||
- NVIDIA repo paths install the latest drivers from NVIDIA's CUDA repo.
|
||||
|
||||
Warning:
|
||||
The NVIDIA driver options are currently in development.
|
||||
If you have a current-generation NVIDIA GPU, do NOT use Debian-based drivers.
|
||||
Use one of the NVIDIA CUDA repo options (proprietary or open), or install drivers manually
|
||||
and re-run the Debian Hyprland install.
|
||||
|
||||
Interactive options (shown if no --mode is provided):
|
||||
D Debian repo — installs nvidia-driver and related packages
|
||||
N NVIDIA CUDA repo — installs cuda-drivers (proprietary)
|
||||
O NVIDIA CUDA repo — installs nvidia-open (open kernel modules)
|
||||
|
||||
Flags:
|
||||
--mode=debian Use Debian repository packages
|
||||
--mode=nvidia Use NVIDIA CUDA repo (proprietary)
|
||||
--mode=open Use NVIDIA CUDA repo (open kernel modules)
|
||||
--switch Switch from the current variant to the one specified by --mode (removes conflicting meta packages)
|
||||
--force Do not exit early when already configured; re-run installs
|
||||
-n, --dry-run Simulate actions; do not modify the system
|
||||
-h, --help Show this help and exit
|
||||
|
||||
Examples:
|
||||
${0##*/}
|
||||
${0##*/} --mode=nvidia
|
||||
${0##*/} --mode=open
|
||||
${0##*/} --mode=nvidia --switch # switch from Debian or open to proprietary
|
||||
${0##*/} --mode=debian --force # re-run Debian path even if already configured
|
||||
EOF
|
||||
}
|
||||
|
||||
# ---------------- main ----------------
|
||||
print_header
|
||||
print_gpu_info
|
||||
|
||||
# Parse flags
|
||||
MODE=""
|
||||
SWITCH=""
|
||||
FORCE=""
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--mode=debian) MODE="debian" ;;
|
||||
--mode=nvidia) MODE="nvidia" ;;
|
||||
--mode=open) MODE="open" ;;
|
||||
--switch) SWITCH=1 ;;
|
||||
--force) FORCE=1 ;;
|
||||
-n|--dry-run) DRY_RUN=1 ;;
|
||||
-h|--help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$MODE" ]; then
|
||||
MODE=$(_prompt_for_mode)
|
||||
fi
|
||||
|
||||
# Early exit or switch handling
|
||||
variant_now=$(detect_variant)
|
||||
if [ -z "$SWITCH" ] && [ -z "$FORCE" ] && [ "$DRY_RUN" -ne 1 ] && [ "$variant_now" = "$MODE" ]; then
|
||||
echo -e "${OK} NVIDIA is already configured for mode: ${YELLOW}${MODE}${RESET}"
|
||||
echo -e "${INFO} Use --force to re-run installs, or --switch to change variants."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -n "$SWITCH" ] && [ "$variant_now" != none ] && [ "$variant_now" != "$MODE" ]; then
|
||||
echo -e "${INFO} Switching from ${YELLOW}$variant_now${RESET} to ${YELLOW}$MODE${RESET} ..."
|
||||
remove_conflicting_for_target "$MODE"
|
||||
fi
|
||||
|
||||
case "$MODE" in
|
||||
debian)
|
||||
_install_via_debian
|
||||
;;
|
||||
nvidia)
|
||||
_install_via_nvidia_repo
|
||||
;;
|
||||
open)
|
||||
_install_via_nvidia_open
|
||||
;;
|
||||
*)
|
||||
echo -e "${ERROR} Unknown mode: $MODE"; exit 1;
|
||||
;;
|
||||
esac
|
||||
|
||||
# ---------------- common post-install tweaks ----------------
|
||||
# Function to add a value to a configuration file if not present
|
||||
add_to_file() {
|
||||
local config_file="$1"
|
||||
local value="$2"
|
||||
|
||||
if ! sudo grep -q "$value" "$config_file"; then
|
||||
echo "Adding $value to $config_file"
|
||||
sudo sh -c "echo '$value' >> '$config_file'"
|
||||
if ! sudo grep -q "$value" "$config_file" 2>/dev/null; then
|
||||
echo "Adding $value to $config_file" | tee -a "$LOG"
|
||||
run_cmd "sudo sh -c 'echo \"$value\" >> \"$config_file\"'"
|
||||
record_change "appended to $config_file"
|
||||
else
|
||||
echo "$value is already present in $config_file."
|
||||
echo "$value is already present in $config_file." | tee -a "$LOG"
|
||||
fi
|
||||
}
|
||||
|
||||
# Install additional Nvidia packages
|
||||
printf "${YELLOW} Installing ${SKY_BLUE}Nvidia packages${RESET} ...\n"
|
||||
for NVIDIA in "${nvidia_pkg[@]}"; do
|
||||
install_package "$NVIDIA" "$LOG"
|
||||
done
|
||||
|
||||
# adding additional nvidia-stuff
|
||||
printf "${YELLOW} adding ${SKY_BLUE}nvidia-stuff${RESET} to /etc/default/grub..."
|
||||
printf "${YELLOW} Applying ${SKY_BLUE}NVIDIA boot/module settings${RESET} ...\n"
|
||||
|
||||
# Additional options to add to GRUB_CMDLINE_LINUX
|
||||
additional_options="rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 rcutree.rcu_idle_gp_delay=1"
|
||||
|
||||
# Check if additional options are already present in GRUB_CMDLINE_LINUX
|
||||
if grep -q "GRUB_CMDLINE_LINUX.*$additional_options" /etc/default/grub; then
|
||||
echo "GRUB_CMDLINE_LINUX already contains the additional options"
|
||||
if grep -q "GRUB_CMDLINE_LINUX.*$additional_options" /etc/default/grub 2>/dev/null; then
|
||||
echo "GRUB_CMDLINE_LINUX already contains the additional options" | tee -a "$LOG"
|
||||
else
|
||||
# Append the additional options to GRUB_CMDLINE_LINUX
|
||||
sudo sed -i "s/GRUB_CMDLINE_LINUX=\"/GRUB_CMDLINE_LINUX=\"$additional_options /" /etc/default/grub
|
||||
echo "Added the additional options to GRUB_CMDLINE_LINUX"
|
||||
if [ -f /etc/default/grub ]; then
|
||||
run_cmd "sudo sed -i 's/GRUB_CMDLINE_LINUX=\"/GRUB_CMDLINE_LINUX=\"$additional_options /' /etc/default/grub"
|
||||
echo "Added the additional options to GRUB_CMDLINE_LINUX" | tee -a "$LOG"
|
||||
record_change "updated GRUB_CMDLINE_LINUX in /etc/default/grub"
|
||||
run_cmd "sudo update-grub 2>&1 | tee -a '$LOG'"
|
||||
record_change "update-grub"
|
||||
else
|
||||
echo -e "${NOTE} /etc/default/grub not found; skipping GRUB update" | tee -a "$LOG"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Update GRUB configuration
|
||||
sudo update-grub 2>&1 | tee -a "$LOG"
|
||||
|
||||
# Define the configuration file and the line to add
|
||||
config_file="/etc/modprobe.d/nvidia.conf"
|
||||
@ -87,10 +342,11 @@ printf "${YELLOW} adding ${SKY_BLUE}nvidia-stuff${RESET} to /etc/default/grub...
|
||||
options nvidia NVreg_PreserveVideoMemoryAllocations=1
|
||||
"""
|
||||
|
||||
# Check if the config file exists
|
||||
# Ensure the config file exists
|
||||
if [ ! -e "$config_file" ]; then
|
||||
echo "Creating $config_file"
|
||||
sudo touch "$config_file" 2>&1 | tee -a "$LOG"
|
||||
echo "Creating $config_file" | tee -a "$LOG"
|
||||
run_cmd "sudo touch '$config_file' 2>&1 | tee -a '$LOG'"
|
||||
record_change "created $config_file"
|
||||
fi
|
||||
|
||||
add_to_file "$config_file" "$line_to_add"
|
||||
@ -101,9 +357,73 @@ printf "${YELLOW} adding ${SKY_BLUE}nvidia-stuff${RESET} to /etc/default/grub...
|
||||
|
||||
if [ -e "$modules_file" ]; then
|
||||
add_to_file "$modules_file" "$modules_to_add" 2>&1 | tee -a "$LOG"
|
||||
sudo update-initramfs -u 2>&1 | tee -a "$LOG"
|
||||
run_cmd "sudo update-initramfs -u 2>&1 | tee -a '$LOG'"
|
||||
record_change "update-initramfs -u"
|
||||
else
|
||||
echo "Modules file ($modules_file) not found." 2>&1 | tee -a "$LOG"
|
||||
fi
|
||||
|
||||
# ---------------- post-install verification ----------------
|
||||
post_install_verify() {
|
||||
echo -e "${INFO} Verifying NVIDIA installation..."
|
||||
|
||||
# Determine installed variant
|
||||
local variant="unknown"
|
||||
if dpkg -l | grep -q -E '^ii\s+nvidia-open\b'; then
|
||||
variant="open (NVIDIA CUDA repo)"
|
||||
elif dpkg -l | grep -q -E '^ii\s+cuda-drivers\b'; then
|
||||
variant="proprietary (NVIDIA CUDA repo)"
|
||||
elif dpkg -l | grep -q -E '^ii\s+nvidia-driver\b'; then
|
||||
variant="debian-packaged"
|
||||
fi
|
||||
echo -e "${OK} Driver source detected: ${YELLOW}${variant}${RESET}"
|
||||
|
||||
# Module load status
|
||||
local loaded="no"
|
||||
if lsmod | grep -q '^nvidia\b'; then loaded="yes"; fi
|
||||
echo -e "${INFO} Kernel module loaded: ${YELLOW}${loaded}${RESET}"
|
||||
if [ "$loaded" != "yes" ]; then
|
||||
echo -e "${NOTE} NVIDIA module not loaded. A reboot is often required after driver install."
|
||||
fi
|
||||
|
||||
# nvidia-smi (if available)
|
||||
if _which nvidia-smi; then
|
||||
local smi
|
||||
smi=$(nvidia-smi --query-gpu=name,driver_version --format=csv,noheader 2>/dev/null | head -n1 || true)
|
||||
if [ -n "$smi" ]; then
|
||||
echo -e "${OK} nvidia-smi: ${YELLOW}${smi}${RESET}"
|
||||
else
|
||||
echo -e "${NOTE} nvidia-smi present but returned no GPU entries."
|
||||
fi
|
||||
else
|
||||
echo -e "${NOTE} nvidia-smi not found; driver utilities may not be installed yet."
|
||||
fi
|
||||
|
||||
# GL stack info (best-effort)
|
||||
if _which glxinfo; then
|
||||
echo -e "${INFO} OpenGL summary:";
|
||||
glxinfo -B 2>/dev/null | grep -E 'OpenGL (vendor|renderer|version)' || true
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$DRY_RUN" -eq 1 ]; then
|
||||
echo "[DRY-RUN] Would run post-install verification (nvidia-smi, module status, glxinfo)."
|
||||
else
|
||||
post_install_verify || true
|
||||
fi
|
||||
|
||||
# ---------------- summary ----------------
|
||||
if [ "$DRY_RUN" -eq 1 ]; then
|
||||
echo -e "${INFO} Dry-run mode: no changes made."
|
||||
else
|
||||
if [ "${#CHANGES[@]}" -eq 0 ]; then
|
||||
echo -e "${OK} No changes made."
|
||||
else
|
||||
echo -e "${OK} Changes applied:"
|
||||
for c in "${CHANGES[@]}"; do
|
||||
echo " - $c"
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
printf "\n%.0s" {1..2}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user