📜 ⬆️ ⬇️

Reboot to another OS without a battering

image
I am constantly working in Linux. But there are times when you need to reboot into Windows. It's just so hard to do, you need to wait for the Grub to pop up and select the desired item. Therefore, to relax or go somewhere during the reboot you do not succeed, sit in front of the monitor. Let's try to alleviate suffering and do anything.

What to do?


Well, the first thought is to change the default selection flag in the grub itself. However, we have grub on the line section, which means that Windows will not be able to change the config file. Okay, let's take grub to a separate section with fat32. I allocated 150 MB, however, and 100, I think it should be enough.

Everything, now we put grub there. I did it from Linux, there is no sense to reinvent the wheel here.
I have a partition / dev / sda6, change to your.

sudo mkdir /mnt/GRUB sudo mount /dev/sda6 /mnt/GRUB sudo grub-install --force --no-floppy --root-directory=/mnt/GRUB /dev/sda6 

So, grub was installed, let's create grub.cfg (I checked and did not remember, maybe by default it can be created during installation).
')
 sudo grub-mkconfig -o /mnt/GRUB/boot/grub/grub.cfg 

Okay, not enough to know the order of the items in the menu. We carry out and consider:

 grep menuentry /mnt/GRUB/boot/grub/grub.cfg 

The countdown comes from 0, by the way. I selected two items, one with linux (0), the second with windows (4)

Linux

Let's move on. We will deal with the Linux reboot. This bash script will do.

 #!/bin/bash #     grub disk=/dev/sda6 #   linux linmenu=0 #   windows winmenu=4 mount $disk /mnt/GRUB sed "s/set default=\"${linmenu}\"/set default=\"${winmenu}\"/g" -i /mnt/GRUB/boot/grub/grub.cfg reboot 

Change the section and points with the linux.

To restart, I created the gksu sh ./path script button. And then who will allow you to mount and reboot without root rights.
In this script, the default is simply replaced by the desired default.

You can even try to reboot into Windows through the script.

Windows

In Windows, without further ado, I set sed , just dropped the files from bin to system32.

It turned out such .bat file:

 ::   grub.cfg set grubfile=e:\boot\grub\grub.cfg ::   linux set linmenu=0 ::   windows set winmenu=4 sed -e "s/set default=\"%winmenu%\"/set default=\"%linmenu%\"/g" %grubfile% > %grubfile%.tmp del %grubfile% ren %grubfile%.tmp grub.cfg shutdown -f -t 0 -r 

Change the way and points.
(Sed with the key -i litter, I had to throw at the pace. Who knows the other bypass, write)

Instead of conclusions


And that's all, sort of. We have, a button on Linux, which reboots the computer in Windows automatically and vice versa.

Literate people will correct me, where I am wrong and where I can change something. I know how I can.
Experiment.

UPD: In the comments, they suggested grub-reboot, and also found out about grub-set-default, but I didn’t want to change the config file (the root directory also indicated). I read that the configuration is still in / etc / default / grub, it probably changes there.

Source: https://habr.com/ru/post/152597/


All Articles