Skip to content

Instantly share code, notes, and snippets.

@jflemer-ndp
Created October 20, 2019 22:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jflemer-ndp/d47d2a27ba505f1ba3df974479e4a3c8 to your computer and use it in GitHub Desktop.
Save jflemer-ndp/d47d2a27ba505f1ba3df974479e4a3c8 to your computer and use it in GitHub Desktop.
Unload the nouveau driver
#!/bin/sh
#
# Try very hard to unload Nouveau driver. Tested on RHEL 7.7 in a
# systemd context. Run this before trying to install the NVIDIA
# driver.
#
# Inspired by https://gist.github.com/davispuh/84674924dff1db3e7844
#
# ---
#
# Copyright 2019 NDP, LLC
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set -x
is_module_loaded() {
lsmod | grep -q "^$1 "
}
# return success if nouveau is not loaded
is_module_loaded nouveau || exit 0
# try for easy win
rmmod nouveau
is_module_loaded nouveau || exit 0
# wait 15 sec for plymouth to exit
plymouth --quit
for i in `seq 15`; do
pgrep -c plymouth >/dev/null || break
sleep 1
done
if pgrep -c plymouth >/dev/null; then
echo "WARNING: plymouth is running"
fi
# unbind all frame buffers
for vtc in /sys/class/vtconsole/vtcon*; do
grep -q 'frame buffer' "$vtc/name" 2>/dev/null || continue
for i in `seq 15`; do
grep -q '0' "$vtc/name" && break
echo "Unbinding $vtc"
echo 0 > "$vtc/bind"
sleep 1
done
if grep -q '1' "$vtc/name"; then
echo "WARNING: $vtc is still bound"
fi
done
# unload modules
for i in `seq 15`; do
is_module_loaded nouveau || exit 0
rmmod nouveau
sleep 1
done
if is_module_loaded nouveau; then
echo "ERROR: nouveau is still loaded"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment