Update 02-arch_install_1.sh

This commit is contained in:
RomanNum3ral 2026-06-09 23:47:40 +00:00
parent 765740a5aa
commit 32563e37d2
1 changed files with 48 additions and 47 deletions

View File

@ -1,20 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail
AUTO_REBOOT="${AUTO_REBOOT:-0}"
printf '%s\n' "=== Step 1: NVIDIA driver install for RTX 3060 / RTX 3090 on Arch Linux ==="
echo "=== Step 1: NVIDIA driver install for RTX 3060 / RTX 3090 on Arch Linux ==="
if [[ $EUID -ne 0 ]]; then
echo "Please run this script as root, e.g.: sudo bash $0"
exit 1
fi
if ! command -v pacman >/dev/null 2>&1; then
echo "This script is for Arch Linux. pacman was not found."
exit 1
fi
echo "Updating Arch package database and system..."
pacman -Syu --noconfirm
@ -29,53 +22,61 @@ pacman -S --needed --noconfirm \
base-devel \
linux-firmware
# Pick NVIDIA package based on the running kernel.
# - linux kernel: nvidia
# - linux-lts kernel: nvidia-lts
# - custom/zen/hardened kernels: nvidia-dkms + matching headers is usually safest
KERNEL_RELEASE="$(uname -r)"
NVIDIA_PACKAGES=(nvidia-utils nvidia-settings opencl-nvidia)
# Install kernel headers for whichever common Arch kernels are installed.
# DKMS needs matching headers to build the NVIDIA kernel module.
HEADER_PKGS=()
pacman -Q linux >/dev/null 2>&1 && HEADER_PKGS+=(linux-headers)
pacman -Q linux-lts >/dev/null 2>&1 && HEADER_PKGS+=(linux-lts-headers)
pacman -Q linux-zen >/dev/null 2>&1 && HEADER_PKGS+=(linux-zen-headers)
pacman -Q linux-hardened >/dev/null 2>&1 && HEADER_PKGS+=(linux-hardened-headers)
if [[ "$KERNEL_RELEASE" == *-lts ]]; then
NVIDIA_PACKAGES+=(nvidia-lts)
elif [[ "$KERNEL_RELEASE" == *-arch* ]]; then
NVIDIA_PACKAGES+=(nvidia)
if (( ${#HEADER_PKGS[@]} > 0 )); then
echo
echo "Installing kernel headers: ${HEADER_PKGS[*]}"
pacman -S --needed --noconfirm "${HEADER_PKGS[@]}"
else
NVIDIA_PACKAGES+=(nvidia-dkms)
# Try to install common headers. If this is a custom kernel, install your matching headers manually.
if pacman -Q linux-headers >/dev/null 2>&1 || pacman -Q linux >/dev/null 2>&1; then
NVIDIA_PACKAGES+=(linux-headers)
fi
if pacman -Q linux-lts >/dev/null 2>&1; then
NVIDIA_PACKAGES+=(linux-lts-headers)
fi
if pacman -Q linux-zen >/dev/null 2>&1; then
NVIDIA_PACKAGES+=(linux-zen-headers)
fi
if pacman -Q linux-hardened >/dev/null 2>&1; then
NVIDIA_PACKAGES+=(linux-hardened-headers)
fi
echo "WARNING: No standard Arch kernel package detected."
echo "If you use a custom kernel, install its matching headers before rebooting."
fi
echo
echo "Installing NVIDIA driver packages: ${NVIDIA_PACKAGES[*]}"
pacman -S --needed --noconfirm "${NVIDIA_PACKAGES[@]}"
echo "Installing NVIDIA driver packages for current Arch repos..."
echo "Using nvidia-open-dkms instead of old/removed nvidia package."
pacman -S --needed --noconfirm \
nvidia-open-dkms \
nvidia-utils \
nvidia-settings \
opencl-nvidia \
lib32-nvidia-utils \
lib32-opencl-nvidia \
egl-wayland \
vulkan-icd-loader \
lib32-vulkan-icd-loader
# Make sure nouveau does not grab the card first.
echo
echo "Enabling NVIDIA persistence daemon if available..."
systemctl enable nvidia-persistenced.service >/dev/null 2>&1 || true
echo "Blacklisting nouveau..."
cat >/etc/modprobe.d/blacklist-nouveau.conf <<'EONOUVEAU'
blacklist nouveau
options nouveau modeset=0
EONOUVEAU
# Enable NVIDIA DRM KMS for Wayland/KDE and smoother boot.
echo
echo "Rebuilding initramfs..."
mkinitcpio -P
echo "Enabling NVIDIA DRM modeset..."
cat >/etc/modprobe.d/nvidia-drm.conf <<'EONVIDIA'
options nvidia_drm modeset=1 fbdev=1
EONVIDIA
echo
echo "Driver install finished. Reboot, then run: nvidia-smi"
echo "If nvidia-smi works, run the second Arch script."
if [[ "$AUTO_REBOOT" == "1" ]]; then
echo "AUTO_REBOOT=1 set, rebooting now..."
reboot now
else
echo "Not rebooting automatically. Run this when ready: sudo reboot"
# Rebuild initramfs if mkinitcpio exists.
if command -v mkinitcpio >/dev/null 2>&1; then
echo
echo "Rebuilding initramfs..."
mkinitcpio -P
fi
echo
echo "Driver install finished. Reboot, then run:"
echo " nvidia-smi"
echo
echo "If nvidia-smi shows your RTX 3060/3090, continue with the second script."