Skip to content

Commit 7cd7082

Browse files
committed
extensions/nvidia: pre-ship modprobe blacklist; remove + modprobe at boot when GPU is found
Previous flow on a host without an NVIDIA GPU: - First boot: kernel modules auto-load from initrd udev → probe fails → noisy dmesg ("nvidia: probe failed", DKMS rebuild artefacts in journal, etc.) - armbian-nvidia-autodetect runs in userspace → writes blacklist + purges packages - Second boot: clean Inverting the default so the first boot is also clean: 1. Build-time write of /etc/modprobe.d/armbian-nvidia-disabled.conf BEFORE the apt install. nvidia-dkms postinst triggers update-initramfs which now bakes the blacklist into initramfs, so initrd udev doesn't try to load nvidia* at all. 2. Boot-time autodetect: - lspci finds [10de:] → rm -f blacklist file + modprobe nvidia_drm modeset=1 (pulls nvidia + nvidia_modeset via deps; Wayland-friendly KMS). Display-manager (we're Before= it) sees the driver loaded. - No [10de:] → keep blacklist + purge packages (unchanged). Self-healing for hosts that gain a GPU later: rootfs blacklist file deleted on first NVIDIA-detected boot; next kernel upgrade regenerates initramfs from the (now blacklist-free) rootfs, so subsequent boots are clean directly from initrd. Until that kernel upgrade, the runtime modprobe covers the gap each boot. || true on modprobe handles the edge case where packages were previously purged on a no-GPU run, then the operator swapped in a GPU but hasn't re-apt-installed. Operator runs apt install manually in that case; the cleared blacklist makes it work on next boot.
1 parent 7a00894 commit 7cd7082

1 file changed

Lines changed: 32 additions & 10 deletions

File tree

extensions/nvidia.sh

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ function extension_finish_config__build_nvidia_kernel_module() {
3131
function post_install_kernel_debs__build_nvidia_kernel_module() {
3232
[[ "${INSTALL_HEADERS}" != "yes" ]] || [[ "${KERNEL_HAS_WORKING_HEADERS}" != "yes" ]] && return 0
3333

34+
# Pre-ship the modprobe blacklist BEFORE installing nvidia packages.
35+
# nvidia-dkms postinst triggers update-initramfs; with the file already
36+
# in /etc/modprobe.d/, the regenerated initramfs has the blacklist
37+
# baked in. Result: no spurious "nvidia: probe failed" lines on hosts
38+
# without an NVIDIA GPU during the first boot. The boot-time
39+
# armbian-nvidia-autodetect helper removes this file (and modprobes
40+
# nvidia_drm) when lspci does see [10de:].
41+
mkdir -p "${SDCARD}/etc/modprobe.d"
42+
cat <<- EOF > "${SDCARD}/etc/modprobe.d/armbian-nvidia-disabled.conf"
43+
# Installed by build/extensions/nvidia.sh.
44+
# Removed at boot by armbian-nvidia-autodetect when [10de:] is present.
45+
blacklist nvidia
46+
blacklist nvidia_drm
47+
blacklist nvidia_modeset
48+
blacklist nvidia_uvm
49+
EOF
50+
3451
# Resolve which nvidia-dkms / nvidia-driver package(s) to install.
3552
# Three cases:
3653
# 1. Operator pinned NVIDIA_DRIVER_VERSION (env/config) → trust it.
@@ -174,20 +191,25 @@ function install_armbian_nvidia_autodetect_helper() {
174191
# `lspci -nn` output so non-VGA NVIDIA devices (Tegra USB-C,
175192
# audio over HDMI, etc.) also count.
176193
if lspci -nn 2>/dev/null | grep -qiE '\[10de:'; then
177-
# Hardware is present. If a previous boot ran on a host
178-
# without NVIDIA, the modprobe blacklist file is still on
179-
# disk and would keep the driver from loading even now.
180-
# Remove it so the modules can bind on the next boot. rm -f
181-
# is idempotent on the common case where the file never
182-
# existed. Package reinstall is intentionally NOT attempted
183-
# here - apt-installing proprietary NVIDIA drivers without
184-
# user consent and without guaranteed network/apt-sources
185-
# is out of scope for a boot-time detector. If packages were
186-
# previously purged, the operator runs apt install manually.
194+
# Hardware is present. The build framework ships a default
195+
# /etc/modprobe.d/armbian-nvidia-disabled.conf so initrd udev
196+
# doesn't try to load nvidia* on no-GPU hosts. Now that we've
197+
# confirmed there IS a GPU, clear the file and modprobe so
198+
# display-manager (we are Before= it) starts with the driver
199+
# loaded. The rootfs deletion self-heals initramfs on the
200+
# next kernel upgrade — until then, initrd stays stale but
201+
# this runtime modprobe covers the gap each boot.
202+
#
203+
# rm -f is idempotent. modprobe nvidia_drm with modeset=1
204+
# pulls nvidia + nvidia_modeset via dependencies and gives
205+
# Wayland-friendly KMS in one shot. || true on the modprobe
206+
# in case the package was previously purged and isn't
207+
# installed - the operator handles re-install separately.
187208
if [ -f /etc/modprobe.d/armbian-nvidia-disabled.conf ]; then
188209
rm -f /etc/modprobe.d/armbian-nvidia-disabled.conf
189210
echo "armbian-nvidia-autodetect: NVIDIA hardware detected; cleared modprobe blacklist" | systemd-cat -t armbian-nvidia-autodetect 2>/dev/null || true
190211
fi
212+
modprobe nvidia_drm modeset=1 2>/dev/null || true
191213
exit 0
192214
fi
193215

0 commit comments

Comments
 (0)