wildtruc / nvidia-prime-select

This a fork of FedoraPrime enhanced for all linux distributions
GNU General Public License v3.0
132 stars 15 forks source link

UEFI Support #9

Closed LukeShortCloud closed 5 years ago

LukeShortCloud commented 5 years ago

Currently nvidia-prime-select is hard-coded to use the legacy/BIOS boot GRUB 2 configuration at /boot/grub2/grub.cfg.

$ sudo nvidia-prime-select nvidia
cat: /boot/grub2/grub.cfg: No such file or directory

These are the locations of the UEFI GRUB 2 configurations based on the Red Hat family of operating systems:

Perhaps a check against lsb_release could be added to determine the operating system? Example below:

if [ ! -f /boot/grub2/grub.cfg ]; then
    operating_system=$(lsb_release --id --short)

    if [ "Fedora" == "${operating_system}" ]; then
        grub_cfg="/boot/efi/EFI/fedora/grub.cfg"
...

On a related note, the Arch Linux and Debian families of operating systems also use a different path (/boot/grub/grub.cfg) for the BIOS boot GRUB 2 configuration (and their own UEF directories). Another, more portable, example below:

if [ -f /boot/grub2/grub.cfg ]; then
    grub_cfg="/boot/grub2/grub.cfg"
elif [ -f /boot/grub/grub.cfg ]; then
    grub_cfg="/boot/grub/grub.cfg"
else
    grub_cfg="/boot/efi/EFI/$(lsb_release --id --short | awk '{print tolower($0)}')/grub.cfg"
fi
wildtruc commented 5 years ago

Thanks for the advice and comment. I will look into this to fix as appropriate. My test laptop need to be upgrade and I need to go back to nvidia-prime-select code first (long time). I was already looking into lsb-release to get and set distros correctly on an other code. I will apply the same for nvidia-prime-select.

If you have others suggestions, don't hesitate.

joeg1484 commented 5 years ago

Any issue with this? I dont have allot of distros to test on, so this will need to be tested, but thought it might work as it does test for UEFI and BIOS:

` grub_config(){ [[ -e /sys/firmware/efi ]] && grub_conf_path="/boot/efi/EFI/*/grub.cfg" || grub_conf_path="/boot/grub2/grub.cfg"

    if [ $cfg_grub -gt 0 ]; then
            ## look at /proc/version to detect distro variant.
            boot_key='/boot/vmlinuz-'$(uname -r)
            modeset_check=$(cat $grub_conf_path| egrep -c "^.*$boot_key.*nvidia-drm.modeset=.*$")
            if [ $(cat $grub_conf_path| egrep -c "^.*$boot_key.*nvidia-drm.modeset=$nv_modeset.*$") -eq 0 ]; then
                    if [ $(cat $grub_conf_path| egrep -c "^.*$boot_key.*blacklist=nouveau.*$") -eq 0 ]; then
                            blacklist=' nouveau.modeset=0 rd.driver.blacklist=nouveau'
                    fi
                    if [ $cfg_modeset -gt 0 ]; then
                            modset='nvidia-drm.modeset='$nv_modeset$blacklist
                    else
                            modset=$blacklist
                    fi
                    ## add nouveau blacklist to modeproe.d configs list.
                    if ! [[ -s /etc/modprobe.d/blacklist-nouveau.conf ]]; then
                            echo "blacklist nouveau" > /etc/modprobe.d/blacklist-nouveau.conf
                    fi
                    if [ $modeset_check -gt 0 ]; then
                            sed -Eni -e "s|(linux.*$boot_key.*ro) (nvidia-drm.modeset=[0-9])(.*)$|\1 $modset\3|g;p" $grub_conf_path
                    else
                            sed -Eni -e "s|(linux.*$boot_key.*ro)(.*)$|\1 $modset \2|g;p" $grub_conf_path
                    fi
                    reboot_text='Grub has been modified for Nvidia Prime modesetting.\nPLease reboot the system for changes to take effect.'
            fi
    fi

} `

joeg1484 commented 5 years ago

Actually, would you want to mess with the actual grub file at all but rather /etc/default/grub then grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg where it would make sense?

wildtruc commented 5 years ago

Sorry,about that. I've severe health issue for last weeks and no brain to work on any code. I will fix as soon as possible. My apologies.

joeg1484 commented 5 years ago

Sorry,about that. I've severe health issue for last weeks and no brain to work on any code. I will fix as soon as possible. My apologies.

Oh no worries! You take care of whats important. Just wanted to offer some suggestions. I have modified the code already and it seems to work for me, but was looking at some other ways to do it.

When you have the time let me know what you think :).

Hope all goes well with you! Joe

wildtruc commented 5 years ago

Done. My laptop is no more support or nvidia hardware defect, can't tell. so this comes with not live test. The simpliest way was to just find grub.cfg. Tell if there's more than one grub.cfg in path (case of a standard install turned into UEFI). So, it's a possibility.

LukeShortCloud commented 5 years ago

Thank you guys for your wonderful suggestions and help!

@wildtruc I wish you the best and hope your health gets better! Your life and well-being should definitely take priority over side projects.

wildtruc commented 5 years ago

Thanks. For info; line was : grub_cfg=$(find /boot -wholename "*/grub.cfg") and changing query vars accordingly.

joeg1484 commented 5 years ago

That works great!

However, getting a

[: !=: unary operator expected

On line 157:

if [ $prim != '' ]; then prim_display=$connected_output; fi I fixed it by using double brackets:

if [[ $prim != '' ]]; then prim_display=$connected_output; fi

Can you confirm and fix with this issue tracker, or would you like me to open a new issue request for this for record keeping?

Thanks! Joe

wildtruc commented 5 years ago

You're right :s I merge it.

joeg1484 commented 5 years ago

Thanks so much :)

obreo commented 5 years ago

I think there is still an issue in UEFI support. I use Deepin 15.9 . When I select nvidia the system doesn't boot and it gives me this error:

problem loading uefi db x.509 certificate (-65)

My secure boot is disabled.

wildtruc commented 5 years ago

hum, looks like you have a UEFI grub and and classic grub in you path. Could you list the content of your /boot/grubX, especially files dedicated to UEFI (if any). (also, the content of the command line lsb_release -a) Thanks.

wildtruc commented 5 years ago

I had a look to deepin live-cd. It appears that deepin have no /boot directory. It usually means that a boot partition is loaded apart, and this case a boot loader like smartphone or raspberry pi. I'm sorry about that, but you have join the deepin community page to dive into and hopefully solve.

obreo commented 5 years ago

After some attempts, I messed up loading the grub, I ended up installing Pop os, it works well with prime drivers! Thanks man!

wildtruc commented 5 years ago

UEFI is normally fix with new update. Please, report new issues in other topic thread. Thanks.