(I usually try to avoid using Google Translate as much as possible for learning purposes, but please forgive me for using its trash in this article. I am still not good at composing long sentences.)
here i created my dev.to account, and writing tech blog for my few friends, just letting to write
What if, instead of running Dual-boot Windows via Grub(bios), you could switch to a Windows system with two clicks from the taskbar, complete with a confirmation dialog? The answer is very simple: just use some efibootmgr command directly.
(This article was originally written for my native language, but I was too lazy to translate it, so I ran it directly through a translator, sorry.)
I got inspiration from this video.
so yeah lets try to doing that!
✅ What it does:
Enhance the convenience of dual booting by pinning a shell script with a confirmation dialog to the Linux taskbar.
✅ Required Modules
This uses the Zenity module, so install it in your Linux system from the terminal beforehand.
Ubuntu/debian
sudo apt install zenity
fedora
https://discussion.fedoraproject.org/t/hdfssk-zenity/40674
arch
https://man.archlinux.org/man/zenity.1.en
✅ What you need to know beforehand:
Execute the following to note the Windows Boot Manager's number.
For example, if the number 0001 is assigned to Windows Boot Manager, make a quick note of it somewhere.
sudo efibootmgr
You can also use the Which command to check the folder locations of efibootmgr and reboot, so use the following commands to find their locations beforehand. Depending on the OS, these locations may vary slightly and may not work properly, so be sure to do thorough research beforehand.
which efibootmgr
which reboot
❌ What it doesn't do:
It is not possible to create a shell script that invokes Efibootmgr from Windows to switch to a Linux system in the same way. This is possible because it is Linux.
Let's get started.
■ first, set up
Create a shell script and a .desktop destination in Terminal.
Remove YOURUSERNAME and replace it with your PC's username.
mkdir -p /home/YOURUSERNAME/ShellScripts
Create a shell script called switch-to-windows.sh in the Shellscripts folder using the following command. (You can also create a text file in Notepad and change the extension to .sh.)
nano /home/YOURUSERNAME/ShellScripts/switch-to-windows.sh
This will open the Nano editing screen in a new file, so copy and paste the following:
#!/bin/bash
zenity --question \
--title="Switch to Windows" \
--text="Do you really want to reboot into Windows?"
if [ $? -eq 0 ]; then
sudo /usr/bin/efibootmgr -n 0001
sudo /sbin/reboot
else
exit 0
fi
Once you've finished copying and pasting, press Ctrl+X to open the save dialog, enter Y for Yes, and then press Enter to save the switch-to-windows.sh file.
Please type sudo efibootmgr in your PC's terminal and execute the command 0001, then check and correct it.
Then, grant execution permission with the following command to make the shell script executable. (Replace YOURUSERNAME with your Linux username.)
chmod +x /home/YOURUSERNAME/ShellScripts/switch-to-windows.sh
🟥Caution
The locations of /usr/bin/efibootmgr and /sbin/reboot vary slightly depending on your operating system, so you may encounter a command error. So… type the following commands into Terminal to check their locations and make any necessary adjustments.
which efibootmgr
When you run it, it will display something like /usr/bin/efibootmgr.
It will differ depending on your OS.
which reboot
Similarly, this will also be displayed as /sbin/reboot.
■ SUDO password is not required under certain conditions
Enter the following into the terminal:
*how to use visudo?
https://www.linuxquestions.org/questions/linux-general-1/save-visudo-and-exit-214219/
sudo visudo -f /etc/sudoers.d/switch-to-windows
Copy and paste the contents below.
(Replace YOURUSERNAME with your Linux username.)
YOURUSERNAME ALL=(ALL) NOPASSWD: /usr/bin/efibootmgr, /sbin/reboot
Save and close (Ctrl+X, Y, Enter).
The reason why you need to specify a username is for security reasons. It would be a bit risky if any user were able to reboot unconditionally, so the process will be a password-less reboot command that only YOURUSERNAME can execute, followed by Windows switching.
■ Create a .desktop file to use as a GUI launcher
Create a file called .desktop in the shellscripts folder.
Enter the following command into Terminal.
(Replace YOURUSERNAME with your Linux username.)
nano /home/YOURUSERNAME/ShellScripts/SwitchToWindows.desktop
Copy and paste the following content:
[Desktop Entry]
Version=1.0
Type=Application
Name=Switch to Windows
Exec=/home/YOURUSERNAME/ShellScripts/switch-to-windows.sh
Icon=system-reboot
Terminal=false
Categories=Utility;
Press Ctrl+X, Y, and Enter to save.
After saving, grant execution permissions to the .desktop file with the following command.
(Replace YOURUSERNAME with your Linux username.)
chmod +x /home/YOURUSERNAME/ShellScripts/SwitchToWindows.desktop
Finally, type the following command into Terminal to display it in the menu for taskbar pinning:
(Replace YOURUSERNAME with your Linux username.)
cp /home/YOURUSERNAME/ShellScripts/SwitchToWindows.desktop ~/.local/share/applications/
When you do, Switch to Windows (containing SwitchToWindows.desktop) will appear in the Linux start menu; right-click it and pin it to the taskbar to complete the process.
Click the Switch To Windows icon pinned to the taskbar and a confirmation dialog will appear. Pressing NO will abort the process, while pressing YES will switch you to Windows. (The confirmation dialog is included as a precaution to prevent tragedies from occurring if you forget to save your work and click on it.)
Thank you for reading this article. bye!
As long as you include my name in the credits, you are free to use it in an automated shell script. I'm just a passerby who was inspired by the video.
Top comments (0)