1

I want to automate switching between Linux and windows,

as the default, the approach is to restart the pc then select the windows from the bois

I want to write a command to do this instead

KroKing
  • 11
  • 1
    We need more details. Why did you tag WSL? Are you using WSL? If you're using Ubuntu on WSL, why are you rebooting? What version of Ubuntu do you have installed? What exact actions do you want to perform? If you just want to reboot Ubuntu, why can't you use sudo reboot? When asking, please provide enough detail so that your question can be answered. – Nmath Jun 29 '22 at 21:02
  • "restart the pc then select the windows from the bios" No you select from GRUB. If BIOS could it be you installed one using UEFI and the other as Legacy? Besides that: what you want is not possible with commands. – Rinzwind Jun 29 '22 at 21:11
  • The best you can do is to boot the last booted OS, which may be Windows or Ubuntu. This helps with Ubuntu not booting by default while Windows needing to reboot during updates. See How to make GRUB remembers what I boot last time? – user68186 Jun 29 '22 at 21:19

1 Answers1

0

No. Not possible.

The best you can do is create a setup where you have a

/etc/default/grub.linux
/etc/default/grub.windows

as a copy of /etc/default/grub with each a GRUB_DEFAULT pointing to the OS to boot found from this command fgrep menuentry /boot/grub/grub.cfg.

In Linux you can then do:

sudo cp -f /etc/default/grub.windows /etc/default/grub
sudo update-grub
reboot

and it will boot into Windows. But there is no way to do this from within Windows so this is not worth it.


The really only working method when using a dual boot is to ...

  • boot into one OS
  • boot into the last booted OS

... where you need to pick the other one from GRUB each time you want to start that one.


My preference would be to have them both active at the same time. And the one you use the most to be the host and the other one to be a guest:

Install virtualbox/vmware in Ubuntu/Windows (host), then install Windows/Ubuntu (guest) in virtualbox/vmware and you can have both operating systems active at the same time. Needs a bit of memory and tinkering to find an optimal memory usage.

Rinzwind
  • 299,756
  • Someone long ago posted an apparent method to do it from Windows: https://stackoverflow.com/questions/838651/programmatic-way-to-select-boot-os – raj Jun 29 '22 at 21:10
  • That does not work anymore. @raj I think it did not work anymore when we started using either ext3 or grub2. – Rinzwind Jun 29 '22 at 21:12
  • I didn't work, and it doesn't worth thanks for claryfing – KroKing Jun 29 '22 at 22:05