I use the following script (based on code here) to reboot to windows, so I can stop kicking myself every time I start daydreaming and miss the boot menu.

#!/bin/bash
ENTRY=$( grep Windows /boot/grub2/grub.cfg | head -n 1 | cut -d"'" -f2 )
echo Rebooting to \"$ENTRY\"
sudo grub2-reboot "$ENTRY" && reboot

However I need sudo and have to type a password or I get this:

/usr/bin/grub2-editenv: error: cannot open ‘/boot/grub2/grubenv’: Permission denied.

It's a symlink, /boot/grub2/grubenv -> /boot/efi/EFI/fedora/grubenv, and owned by root.

The command reboot works just fine as a regular user in Fedora 23. How can I make grub2-reboot work as well, but in a secure way?

I was thinking something along the lines of a stick bit on grub2-editenv, but that doesn't sound good. A sticky bit on my script won't work (a good thing). Changing permissions on the file /boot/efi/EFI/fedora/grubenv would work but might open up more possibilities than intended.

I see two possibilities:

  • Use sudo, but configure it so that this command will not ask you password (using NOPASSWD option)

  • Set root as the owner of the script and setuid the script: chown root.root script ; chmod u+s script

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.