#!/usr/bin/sh # EL8 (grub2 with BootLoaderSpec patches) # # kernel options: grub.cfg + grubenv # kernel options in /boot/loader/entries/*.conf use kernelopts from /boot/grub2/grubenv # grubby # - updates kernelopts in /boot/grub2/grubenv # - does not update /etc/default/grub # - does not update kernelopts in grub.cfg # grub.cfg: # - UEFI: /etc/grub2-efi.cfg -> /boot/efi/EFI//grub.cfg # - BIOS: /etc/grub2.cfg -> /boot/grub2/grub.cfg # EL9 + EL10 (grub2 with BootLoaderSpec patches) # # kernel options: grub.cfg + /etc/kernel/cmdline + /boot/loader/entries/*.conf # manually update: /etc/default/grub + /etc/kernel/cmdline # /etc/kernel/cmdline is not really used # grub2-mkconfig does not update /boot/loader/entries/*.conf # grub.cfg: # - UEFI: /etc/grub2-efi.cfg -> /boot/efi/EFI//grub.cfg # - BIOS: /etc/grub2.cfg -> /boot/grub2/grub.cfg # Fedora (grub2 with BootLoaderSpec patches) # # kernel options: grub.cfg + /etc/kernel/cmdline + /boot/loader/entries/*.conf # manually update: /etc/default/grub # grub2-mkconfig: # - updates /boot/loader/entries/*.conf # - updates /etc/kernel/cmdline # grub.cfg: # - UEFI/BIOS: /boot/grub2/grub.cfg # Fedora (systemd-boot) # # kernel options: grub.cfg + /boot/efi/loader/entries/*.conf (UEFI only) # grubby as an updateloaderentries alias: # - updates all entries in /boot/efi/loader/entries/*.conf # - does not work with multiple parameters at once # - does not update /etc/kernel/cmdline # Complete use case coverage, regardless of boot loaders: # # - update options in /etc/default/grub # - regenerate grub.cfg/grubenv # - update options in /boot/{efi/}loader/entries/*.conf entries # - update options in /etc/kernel/cmdline # - cover both UEFI and BIOS case CMDLINE_ARGS_NVIDIA="rd.driver.blacklist=nouveau rd.driver.blacklist=nova-core" CMDLINE_ARGS_ALWAYS_REMOVE="nomodeset gfxpayload=vga=normal nouveau.modeset=0 nvidia-drm.modeset=1 nvidia-drm.fbdev=1 modprobe.blacklist=nouveau initcall_blacklist=simpledrm_platform_driver_init" print_usage() { cat <> /etc/default/grub else for param in $CMDLINE_ARGS_NVIDIA; do echo ${GRUB_CMDLINE_LINUX} | grep -q $param [ $? -eq 1 ] && GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} ${param}" done for param in $CMDLINE_ARGS_ALWAYS_REMOVE; do echo ${GRUB_CMDLINE_LINUX} | grep -q $param [ $? -eq 0 ] && GRUB_CMDLINE_LINUX="$(echo ${GRUB_CMDLINE_LINUX} | sed -e "s/ $param//g")" done sed -i -e "s|^GRUB_CMDLINE_LINUX=.*|GRUB_CMDLINE_LINUX=\"${GRUB_CMDLINE_LINUX}\"|g" /etc/default/grub fi grub2-mkconfig -o $GRUB_CFG &>/dev/null fi # Edit BootLoaderSpec entries if [ -v BLS_ENTRIES ]; then for config_file in $BLS_ENTRIES/*.conf; do for param in $CMDLINE_ARGS_NVIDIA; do grep -q $param $config_file [ $? -eq 1 ] && sed -i -e "s|^options.*|& $param|" $config_file done for param in $CMDLINE_ARGS_ALWAYS_REMOVE; do grep -q $param $config_file [ $? -eq 0 ] && sed -i -e "s| $param||" $config_file done done fi # Edit /etc/kernel/cmdline if [ -f /etc/kernel/cmdline ]; then for param in $CMDLINE_ARGS_NVIDIA; do grep -q $param /etc/kernel/cmdline [ $? -eq 1 ] && sed -i -e "s|^.*|& $param|" /etc/kernel/cmdline done for param in $CMDLINE_ARGS_ALWAYS_REMOVE; do grep -q $param /etc/kernel/cmdline [ $? -eq 0 ] && sed -i -e "s| $param||" /etc/kernel/cmdline done fi } preun() { # Edit GRUB configuration file if [ -v GRUB_CFG ]; then for param in $CMDLINE_ARGS_NVIDIA; do echo ${GRUB_CMDLINE_LINUX} | grep -q $param [ $? -eq 0 ] && GRUB_CMDLINE_LINUX="$(echo ${GRUB_CMDLINE_LINUX} | sed -e "s/ $param//g")" done sed -i -e "s|^GRUB_CMDLINE_LINUX=.*|GRUB_CMDLINE_LINUX=\"${GRUB_CMDLINE_LINUX}\"|g" /etc/default/grub grub2-mkconfig -o $GRUB_CFG &>/dev/null fi # Edit BootLoaderSpec entries if [ -v BLS_ENTRIES ]; then for config_file in $BLS_ENTRIES/*.conf; do for param in $CMDLINE_ARGS_NVIDIA; do grep -q $param $config_file [ $? -eq 0 ] && sed -i -e "s| $param||" $config_file done done fi # Edit /etc/kernel/cmdline if [ -f /etc/kernel/cmdline ]; then for param in $CMDLINE_ARGS_NVIDIA; do grep -q $param /etc/kernel/cmdline [ $? -eq 0 ] && sed -i -e "s| $param||" /etc/kernel/cmdline done fi } case "$1" in post) check post exit 0 ;; preun) check preun exit 0 ;; *) print_usage exit 0 ;; esac