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