blacklist nouveau options nvidia_drm modeset=1 fbdev=1
之后最关键的一步
1
sudo mkinitcpio -P
更新 initramfs
配置 Pacman Hook
新建一个文件比如:nvidia.hook,内容如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[Trigger] Operation=Install Operation=Upgrade Operation=Remove Type=Package Target=nvidia Target=linux # Adjust line(6) above to match your driver, e.g. Target=nvidia-470xx-dkms # Change line(7) above, if you are not using the regular kernel For example, Target=linux-lts
[Action] Description=Update Nvidia module in initcpio Depends=mkinitcpio When=PostTransaction NeedsTargets Exec=/bin/sh -c 'while read -r trg; do case $trg in linux) exit 0; esac; done; /usr/bin/mkinitcpio -P'
backup_file() { local file=$1 sudo cp "$file" "$file.bak" }
update_environment() { local env_file="/etc/environment" backup_file "$env_file"
for var in "${nvidia_variables[@]}"; do if grep -q "^${var%%=*}" "$env_file"; then sudo sed -i "s|^${var%%=*}.*|$var|" "$env_file" else echo "$var" | sudo tee -a "$env_file" > /dev/null fi done
echo "NVIDIA-specific options have been written to $env_file." }
update_mkinitcpio_conf() { local mkinitcpio_conf="/etc/mkinitcpio.conf" backup_file "$mkinitcpio_conf"
sudo sed -i '/^MODULES=/ s/(\(.*\))/(\1 nvidia nvidia_modeset nvidia_uvm nvidia_drm)/' "$mkinitcpio_conf" sudo sed -i '/^HOOKS=/ s/\(\s*kms\s*\)//g' "$mkinitcpio_conf"
echo "mkinitcpio.conf has been updated." }
create_nvidia_conf() { local nvidia_conf="/etc/modprobe.d/nvidia.conf" sudo bash -c "cat > $nvidia_conf" <<EOL blacklist nouveau options nvidia_drm modeset=1 fbdev=1 EOL
echo "$nvidia_conf has been created." }
regenerate_initramfs() { sudo mkinitcpio -P echo "initramfs has been regenerated." }
create_nvidia_hook() { local hook_dir="/etc/pacman.d/hooks" local hook_file="$hook_dir/nvidia.hook"
sudo mkdir -p "$hook_dir"
sudo bash -c "cat > $hook_file" <<EOL [Trigger] Operation=Install Operation=Upgrade Operation=Remove Type=Package Target=nvidia Target=linux # Adjust line(6) above to match your driver, e.g. Target=nvidia-470xx-dkms # Change line(7) above, if you are not using the regular kernel For example, Target=linux-lts
[Action] Description=Update Nvidia module in initcpio Depends=mkinitcpio When=PostTransaction NeedsTargets Exec=/bin/sh -c 'while read -r trg; do case \$trg in linux) exit 0; esac; done; /usr/bin/mkinitcpio -P' EOL