diff options
author | Jonathan Bauer | 2020-05-13 11:04:02 +0200 |
---|---|---|
committer | Jonathan Bauer | 2020-05-13 11:04:02 +0200 |
commit | 1130873aa55c9b0a7e5af48edc44bd6c6fd1f888 (patch) | |
tree | 0fcfa186cd631d8d36611b3d4bc509fd38841d51 /modules.d/slx-drm | |
parent | Merge branch 'centos8' into downloader (diff) | |
download | systemd-init-1130873aa55c9b0a7e5af48edc44bd6c6fd1f888.tar.gz systemd-init-1130873aa55c9b0a7e5af48edc44bd6c6fd1f888.tar.xz systemd-init-1130873aa55c9b0a7e5af48edc44bd6c6fd1f888.zip |
restructure repo
* remove packager
* move everything from builder/* back to root
Diffstat (limited to 'modules.d/slx-drm')
-rw-r--r-- | modules.d/slx-drm/hooks/activate-nvidia-drivers.sh | 42 | ||||
-rw-r--r-- | modules.d/slx-drm/hooks/copy-nvidia-drivers.sh | 28 | ||||
-rwxr-xr-x | modules.d/slx-drm/module-setup.sh | 22 |
3 files changed, 92 insertions, 0 deletions
diff --git a/modules.d/slx-drm/hooks/activate-nvidia-drivers.sh b/modules.d/slx-drm/hooks/activate-nvidia-drivers.sh new file mode 100644 index 00000000..5c9310e8 --- /dev/null +++ b/modules.d/slx-drm/hooks/activate-nvidia-drivers.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +type emergency_shell >/dev/null 2>&1 || . /lib/dracut-lib.sh + +detect_nvidia_cards() { + # hard check on nvidia graphic cards + local cards="$(lspci | grep 'Class 0300: 10de:' | awk '{print $4}')" + if ! [ -d "/drm.cfg.d" ] && [ -n $cards ]; then + warn "Failed to find '/drm.cfg.d' or nvidia cards." + return 1 + fi + for card in $cards; do + local driver="$(awk '$1 = /'"$card"'/ {print $2}' /drm.cfg.d/*)" + [ -z "$driver" ] && continue + driver="${driver//@/}" + driver="${driver//-/\/}" + local driver_dir="/lib/modules/${driver}" + [ -d "$driver_dir" ] || continue + local driver_target="/lib/modules/$(uname -r)/kernel/drivers/gpu/drm/nvidia" + if [ -d "$driver_target" ]; then + warn "'$driver_target' exists, will not overwrite!" + return 1 + fi + # all good, move it over + if ! mv "$driver_dir" "$driver_target" 2>&1; then + warn "Failed to move '$driver_dir' to '$driver_target'." + return 1 + fi + # finally run depmod to make it visible to udev + if ! depmod -a 2>&1 ; then + warn "Failed to run depmod, udev won't see the nvidia modules." + return 1 + fi + # blacklist nouveau + echo 'blacklist nouveau' > "/lib/modprobe.d/disable-nouveau.conf" + info "Initialized nvidia drivers." + return 0 + done +} + +detect_nvidia_cards +: diff --git a/modules.d/slx-drm/hooks/copy-nvidia-drivers.sh b/modules.d/slx-drm/hooks/copy-nvidia-drivers.sh new file mode 100644 index 00000000..323af6d2 --- /dev/null +++ b/modules.d/slx-drm/hooks/copy-nvidia-drivers.sh @@ -0,0 +1,28 @@ +#!/bin/ash +# +# This script checks whether the nvidia kernel module was loaded by udev +# and copies the kernel modules over to stage4 and disables nouveau + +type emergency_shell >/dev/null 2>&1 || . /lib/dracut-lib.sh + +copy_nvidia_modules() { + local nvidia_moddir="/lib/modules/$(uname -r)/kernel/drivers/gpu/drm/nvidia" + if [ -d "${NEWROOT}/${nvidia_moddir}" ]; then + warn "Stage4 contains nvidia driver which would be overwritten - skipping." + return 1 + fi + if ! ( cp -r "$nvidia_moddir" "${NEWROOT}/${nvidia_moddir}" \ + && depmod -a -b "$NEWROOT" ); then + warn "Failed to copy/depmod nvidia modules to stage4." + return 1 + fi + # nouveau driver would needlessly load, prevent that + mkdir -p "${NEWROOT}/etc/modprobe.d" # cause why not + echo "blacklist nouveau" > "${NEWROOT}/etc/modprobe.d/disable-nouveau.conf" + return 0 +} + +if lsmod | grep -q nvidia; then + copy_nvidia_modules +fi +: # fake success diff --git a/modules.d/slx-drm/module-setup.sh b/modules.d/slx-drm/module-setup.sh new file mode 100755 index 00000000..4baa5b2a --- /dev/null +++ b/modules.d/slx-drm/module-setup.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +check() { + # Tell dracut that this module should only be included if it is required + # explicitly. + return 255 +} +depends() { + echo drm +} +installkernel() { + instmods acpi_ipmi +} +install() { + # grab what mltk produced, to externalize this part! + for dir in "/drm.cfg.d" "/lib/modules/nvidia"; do + [ -d "$dir" ] || continue + mkdir -p "${initdir}/${dir%/*}" + cp -ar "$dir" "${initdir}/${dir%/*}" + done + inst_hook pre-udev 10 "${moddir}/hooks/activate-nvidia-drivers.sh" + inst_hook pre-pivot 50 "${moddir}/hooks/copy-nvidia-drivers.sh" +} |