We reboot into another OS without assault

    I constantly work in Linux. But there are times when you need to reboot into Windows. It’s just hard to do this, you need to wait until Grub pops up and select the desired item. Therefore, you will not be able to rest or go somewhere during a reboot, sit in front of the monitor. Let's try to alleviate suffering and do at least something.

    What to do then?

    Well, the first thought is to change the default item selection flag in grub itself. However, grub is on our partition with a line, which means Windows will not be able to modify the config file. Ok, let's put grub on a separate partition with fat32. I allocated 150 MB, but 100 I think should be enough.

    That's it, now we put grub there. I did it from Linux, it makes no sense to reinvent the wheel here.
    I have a / dev / sda6 partition, change to yours.

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

    So, grub is installed, let's create grub.cfg (I stuck it in, and didn’t remember, maybe it is created by default by default during installation).

    sudo grub-mkconfig -o /mnt/GRUB/boot/grub/grub.cfg

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

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

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


    Let's move on. We will deal with Linux reboot. Such a bash script is suitable

    # Путь к разделу с grub
    # Пункт с linux
    # Пункт с windows
    mount $disk /mnt/GRUB
    sed "s/set default=\"${linmenu}\"/set default=\"${winmenu}\"/g" -i /mnt/GRUB/boot/grub/grub.cfg

    Change the section and paragraphs with linguin.

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

    Already, you can even try rebooting into Windows through a script.


    In Windows, without further ado, I set sed , only transferred files from bin to system32.

    The result is a .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 paths and points.
    (sed with the -i switch was garbage, I had to throw it at a pace. Who knows another workaround, write)

    Instead of conclusions

    And that’s it. We have a button on Linux that reloads the computer into Windows automatically and vice versa.

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

    UPD: In the comments, they prompted about grub-reboot, and also learned about grub-set-default, but they didn’t want to change the config file for me (the root directory was also indicated). I read that the setting is also in / etc / default / grub, and there it probably changes.

    Also popular now: