I'm looking for a one-click shortcut to log out, restart, and boot in the opposite operating system. The only information I've found online is between Windows and Windows and I'm not sure if it's different.
1 Answers
NOTE: This answer has been a work in progress.
This can be done. I am not sure what Desktop Environment you are running, but the steps should be relatively close to the same. These steps will create a script that you can run from the command line and also a desktop launcher that can be launched by clicking on it. Either way, it is best to have it asking for a password before the reboot happens.
First thing is to create a script that will contain the commands based from my other answer here using grub-reboot as it sets the default boot entry for GRUB, for the next boot only. The reason for this is so there is no editing of the /etc/default/grub file or the /boot/grub/grub.cfg file.
I called my script win_reboot.bsh, but before adding the contents to the script, run sudo os-prober to get a more precise name of the Windows 10 just in case there are multiple entries like could be found in OEM systems with recovery, etc.
I don't use GPT or run on an OEM system so I only have one entry.
$ sudo os-prober
/dev/sdh1:Windows 10 (loader):Windows:chain
Take note of the Windows name between the colons :. We are going to use the Windows 10 (loader). awk will actually have a problem with special characters like ()/ so we will have to escape those with a \ like Windows 10 \(loader\). We are going to use this line because it will be more precise if there are multiple entries in the os-prober that is run before grub-update writes a new /boot/grub/grub.cfg file.
For this, we are also going to use the pkexec command which should already be installed. gksu is deprecated.
Script contents:
#!/bin/bash
if [ ${UID} != 0 ]; then
echo "Please run as 'sudo $0'"
exit 1
fi
grub-reboot "$(awk -F"'" '/Windows 10 (loader)/ {print $2}' /boot/grub/grub.cfg)"
reboot
If you only have 1 Windows entry from the os-prober command you can set the grub-reboot line to:
grub-reboot "$(awk -F"'" '/Windows/ {print $2}' /boot/grub/grub.cfg)"
That script will search through the grub.cfg file and get the full name of the Windows 10 (loader) boot. I did the line to handle changes if a grub-update is performed in the future and changes the name of that line. The reason for this is that if you add a hard drive or leave a USB drive in the system that is not bootable during a boot up, the drive designation can change. You could see a line that reads like Windows 10 (loader) (on /dev/sdh1) then on another grub-update it changes to Windows 10 (loader) (on /dev/sdg1). Good thing that these entries actually rely on the UUID of the partition and not the name in the grub entry.
Next, make the script executable:
sudo chmod +x win_reboot.bsh
Now if you run it from the command line without sudo it should look like this:
$ ./win_reboot.bsh
Please run as 'sudo ./win_reboot.bsh'
Create a shortcut to the new script. I hope that when you right-click on your desktop that Create Launcher is one of the options. I am running Xfce4 as my desktop. I guess you could create a launcher based on the comment posted by Andrew Shum as it should still work as long as it points to the win_reboot.bsh script.
Edit: I changed the launcher here based on the comments I received below. sudo -H does not work in the command of a launcher, unless you have set the option to Run in Terminal. One other thing to note here that this launcher is calling a CLI script and not a GUI application.
You can create a file in your ~/Desktop folder named Boot to Windows 10.desktop and add the following to it:
[Desktop Entry]
Version=1.0
Type=Application
Name=Boot to Windows 10
Comment=Reboot System to Windows 10
Exec=pkexec /home/terrance/scripts/win_reboot.bsh
Icon=web-microsoft
Path=
Terminal=false
StartupNotify=false
Remember to change the Exec= line to match your file location.
Then when you launch the shortcut you will see something similar to enter your password as the Super User:
Hope this helps!
- 43,712

