分享一个屏蔽nouveau的脚本

#!/bin/bash
if [ $(id -u) -ne 0 ]; then
        echo "This script must be run as root"
        exit 1
fi
sed -i "s/blacklist nvidiafb/#blacklist nvidiafb/g" /lib/modprobe.d/dist-blacklist.conf && echo -e "Configure #blacklist nvidiaf :\t[\033[32;1mOK\033[0m]" || echo -e "Configure #blacklist nvidiaf :\t[\033[31;1mfailed\033[0m]"

cat >>/lib/modprobe.d/dist-blacklist.conf <<EOF
#disable nouveau
blacklist nouveau
options nouveau modeset=0
EOF

mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak && echo -e "Copy initramfs-$(uname -r).img.bak:\t[\033[32;1mOK\033[0m]" || echo -e "Copy initramfs-$(uname -r).img.bak:\t[\033[31;1mfailed\033[0m]"
dracut /boot/initramfs-$(uname -r).img $(uname -r) && echo -e "Dracut initramfs-$(uname -r).img:\t[\033[32;1mOK\033[0m], please reboot system" || echo -e "Dracut initramfs-$(uname -r).img:\t[\033[31;1mfailed\033[0m]"
sync
echo -e "\033[32;1m next start os whil in cmdline \033[0m"