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!

- 41,612
- 7
- 124
- 183
-
It probably won't be an issue for Largobone, but it seems like that particular solution would run into trouble if there are multiple entries for a "Windows 10". For instance, my computer at work was setup with Windows 7 by IT and somehow ended up with 3 (maybe 4) separate images; all detected by Grub yet only one is actually setup. Also, if one is going to make a launcher, shouldn't "gksudo" be used instead? – Andrew Shum Mar 21 '18 at 09:37
-
-
I thought gksudo was depreciated for launching gui apps. And you should not just use sudo either, current recommended method is
sudo -H
# which keeps /home as location of files. see https://askubuntu.com/questions/11760/what-is-the-difference-between-gksudo-nautilus-and-sudo-nautilus – oldfred Mar 21 '18 at 13:54 -
@oldfred You are right. However, this is only a call to a script not a GUI application. I need to change my image and edit this answer one more time to use
pkexec
instead. Thesudo -H
at this point is moot because I have tested both ways and they work fine. – Terrance Mar 21 '18 at 14:15 -
@oldfred Thanks for sharing that information. Is it the same with
su
vsgksu
and does it necessarily impact older OSs? The specific post that mentioned it was specifically about 17 and up. – Andrew Shum Mar 21 '18 at 17:45 -
Not sure. I know before we did use gksudo. And for a while they were recommended pkexec, but that required some configuration. I know for several installs I had to add gksu/gksudo to my install to use it, so not standard. But now I just use sudo -H. – oldfred Mar 21 '18 at 17:53
reboot
command. The trick is making GRUB boot another OS next time. This is explained here and especially here. – PerlDuck Mar 19 '18 at 17:12