📜 ⬆️ ⬇️

How I learned to directly reboot into the correct OS via UEFI

Good evening, Habrahabr!


Today we will learn to reboot from Linux straight to Windows and back in just one (double) click.


image


Given:



It is necessary:



Notes:



Linux:


Linux is your bro
Linux is an excellent base for working with computers, so everything that we need is already in the repositories, and the collective intelligence of the community knows everything and is always ready to help. Therefore, after a brief study of the Internet, put efibootmgr :


I had it so
sudo pacman -S efibootmgr 

Ok, now we run:


 sudo efibootmgr 

See something like this
 Timeout: 1 seconds BootOrder: 0001,0000 Boot0000* Windows Boot Manager Boot0001* rEFInd Boot Manager 

Attentive readers probably already noticed that something was wrong in the output, but then I was inspired by the idea that in 15 minutes I would fly between operating systems without problems, and did not pay enough attention to it.
Ok, 3 minutes for the documentation, and we find the necessary parameter " -n ", which sets the custom boot order exactly at one time. We try to execute this command:
Decision


 sudo efibootmgr -n 0000 && sync && reboot 

And we find ourselves in Windows, just like that and wanted. Now we write this command to the script / alias / *. Desktop-file and enjoy how everything turned out great.


Windows:


Typical Windows
It all began with the search for an analogue of efibootmgr for Windows, which, of course, is not in its pure form. To calm my conscience, I even tried to use Linux Subsystem, but this, of course, did not work.
A quick search on the Internet showed that the bcdedit utility has similar functionality for modifying NVRAM. Great, I think, I launch PowerShell from under the Administrator and write


 bcdedit /enum firmware 

Here is what I saw
 Firmware Boot Manager --------------------- identifier {fwbootmgr} displayorder {6893bb38-946b-11e7-b175-9301bd8a88f4} {bootmgr} timeout 1 Windows Boot Manager -------------------- identifier {bootmgr} device partition=\Device\HarddiskVolume2 path \EFI\Microsoft\Boot\bootmgfw.efi description Windows Boot Manager locale ru-RU inherit {globalsettings} default {current} resumeobject {6893bb40-946b-11e7-b175-9301bd8a88f4} toolsdisplayorder {memdiag} timeout 30 Firmware Application (101fffff) ------------------------------- identifier {6893bb38-946b-11e7-b175-9301bd8a88f4} device partition=\Device\HarddiskVolume2 path \EFI\REFIND\REFIND_X64.EFI description rEFInd Boot Manager 

Where is Linux? Where to boot? Hate windows
In fact, it turned out that it was not Windows that was to blame, but I (yes, that very moment for attentive users), and here's why: rEFInd is an excellent utility that usually requires you to install yourself to work correctly. She is able to pick up all .efi files, different distributions with different kernels, she herself inserts icons. Charm, not a tool. But this played a cruel joke on me, as it turned out that UEFI did not know anything about Linux, since the corresponding .efi file was missing.
Therefore, we reboot back to Linux, configure systemd-boot (bootctl). Now it looks like this:


 Timeout: 1 seconds BootOrder: 0001,0003,0000,0002 Boot0000* Windows Boot Manager Boot0001* rEFInd Boot Manager Boot0002* Linux Boot Manager Boot0003* Manjaro 

Go back and run again.


 bcdedit /enum firmware 

Here is what I saw now
 Firmware Boot Manager --------------------- identifier {fwbootmgr} displayorder {6893bb38-946b-11e7-b175-9301bd8a88f4} {bootmgr} {ff0bc716-c088-11e7-bf74-000acd2dac7d} {ff0bc716-c088-11e7-bf74-000acd2dac7d} timeout 1 Windows Boot Manager -------------------- identifier {bootmgr} device partition=\Device\HarddiskVolume2 path \EFI\Microsoft\Boot\bootmgfw.efi description Windows Boot Manager locale ru-RU inherit {globalsettings} default {current} resumeobject {6893bb40-946b-11e7-b175-9301bd8a88f4} toolsdisplayorder {memdiag} timeout 30 Firmware Application (101fffff) ------------------------------- identifier {6893bb38-946b-11e7-b175-9301bd8a88f4} device partition=\Device\HarddiskVolume2 path \EFI\REFIND\REFIND_X64.EFI description rEFInd Boot Manager Firmware Application (101fffff) ------------------------------- identifier {ff0bc716-c088-11e7-bf74-000acd2dac7d} device partition=\Device\HarddiskVolume2 path \EFI\SYSTEMD\SYSTEMD-BOOTX64.EFI description Linux Boot Manager Firmware Application (101fffff) ------------------------------- identifier {ff0bc717-c088-11e7-bf74-000acd2dac7d} device partition=\Device\HarddiskVolume1 path \EFI\manjaro\vmlinuz-4.13-x86_64 description Manjaro 

It is worth mentioning here that reddit users helped me solve the problem. Thanks to them we have the following step:


 bcdedit /bootsequence {ff0bc716-c088-11e7-bf74-000acd2dac7d} 

Where the argument is the identifier of the required option - Linux Boot Manager.


Troubleshooting

Powershell does not allow to execute this command normally, cursing at


 The entry list data is not valid as specified. 

All because of the fact that Microsoft periodically likes to break something. The solution is simple and elegant - we call the classic CMD and work in it. This can be done with the command


 cmd 

Reboot and see that the boot order has not changed, and we found ourselves in the first element in BootOrder (I had it rEFInd), select Windows and see a terrible hello from DOS times, which tells us that \ EFI \ SYSTEMD \ SYSTEMD-BOOTX64. EFI not found. Yes, we changed the Windows bootloader settings, but not UEFI.
The struggle with this mistake took me all the holidays, but nothing good could be done. I already thought of writing a small program for C ++ for this (that this is possible, follows from the existence of such software as EasyUEFI).
But here on the next site I found this design


  bcdedit /set {bootmgr} path .... 

And then it dawned on me that you can directly tell bcdedit what to write and where. Further it was worth only to check the guess:
Decision


 bcdedit.exe /set {fwbootmgr} bootsequence {ff0bc716-c088-11e7-bf74-000acd2dac7d} /addfirst 

Here it is important that we explicitly told to write not in {bootmgr} (as he apparently does by default), but in {fwbootmgr}, which is our UEFI settings.
Reboot, and everything works as we wanted. We save this business in bat / lnk, we add


 shutdown /r /t 0 

We expose start from under the administrator and it is ready!
Thanks for attention! I would be very happy to comment on the technical part in the comments, comments on the design - in drugs.


')

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


All Articles