Jump to content











Photo
- - - - -

Switching boot loaders


  • Please log in to reply
9 replies to this topic

#1 generalmx

generalmx

    Newbie

  • Members
  • 14 posts
  •  
    United States

Posted 29 July 2015 - 05:09 AM

Is there a way to tell Grub4dos to just switch which boot loader is in the MBR & PBR? For compatibility reasons I'd like to switch between booting straight to Grub4dos and booting to the Windows Boot Loader (which can then boot to grub.mbr); I've had some myriad BIOS-controlled OEM systems which refuse to boot off of Easy2Boot but do still boot off the Windows Boot Loader (bootmgr).

 

I was also planning on making up a batch file to do it, too.



#2 generalmx

generalmx

    Newbie

  • Members
  • 14 posts
  •  
    United States

Posted 29 July 2015 - 06:28 AM

Here's the batch file (requires BOOTICE):

@echo off
REM Switch between different boot loaders.

SET _PREVMBR=bootice.prev.mbr
SET _PREVPBR=bootice.prev.pbr
SET _DISKINFO=bootice.diskinfo.txt

REM EFI Bootloaders
SET _BOOTEFI=%~dp0efi\boot\BOOTX64.EFI
SET _WINEFI=%~dp0efi\boot\WINX64.EFI
SET _GRUBEFI=%~dp0efi\boot\GRUBX64.EFI
SET _REFEFI=%~dp0efi\boot\REFX64.EFI
SET _OTHEREFI=%~dp0efi\boot\OTHERX64.EFI

cd /d "%~dp0"

IF /I [%PROCESSOR_ARCHITECTURE%]==[x86] (
    set BOOTICE=BOOTICEx86.exe
) ELSE IF NOT EXIST "BOOTICEx64.exe" (
    set BOOTICE=BOOTICEx86.exe
) ELSE (
    set BOOTICE=BOOTICEx64.exe
)

IF NOT EXIST "%_DISKINFO%" (
    "%BOOTICE%" /device=%~d0 /diskinfo /file="%_DISKINFO%"
)
type "%_DISKINFO%"
echo.
echo *************************************
echo * This file switches boot loaders for both the BIOS/CSM and UEFI.
echo *************************************
echo Drive Letter: [%~d0]
echo.

IF EXIST "%_PREVMBR%" (
    echo [BIOS] 1. Restore previous non-Windows boot loader [Press ENTER]
) ELSE (
    echo [BIOS] 1. Switch to Windows Boot Loader [Press ENTER]
)
IF EXIST "%_WINEFI%" (
    echo [UEFI] 2. Switch to Windows UEFI Boot Loader
)
IF EXIST "%_GRUBEFI%" (
    echo [UEFI] 3. Switch to GRUB UEFI Boot Loader
)
IF EXIST "%_REFEFI%" (
    echo [UEFI] 4. Switch to REFIND EFI Boot Loader
)
IF EXIST "%_OTHEREFI%" (
    echo [UEFI] 5. Switch to other/unknown EFI Boot Loader
)
echo.
set /p "choice=Enter your selection: "
IF EXIST "%_WINEFI%" IF [%choice%]==[2] GOTO :winefi
IF EXIST "%_GRUBEFI%" IF [%choice%]==[3] GOTO :grubefi
IF EXIST "%_REFEFI%" IF [%choice%]==[4] GOTO :refindefi
IF EXIST "%_OTHEREFI%" IF [%choice%]==[5] GOTO :otherefi
IF EXIST "%_PREVMBR%" GOTO :restorembr
GOTO :windowsmbr

:windowsmbr
echo ** Installing Windows Boot Loader to MBR and PBR for [%~d0]...
"%BOOTICE%" /device=%~d0 /mbr /backup /file="%_PREVMBR%" /quiet && "%BOOTICE%" /device=%~d0 /pbr /backup /file="%_PREVPBR%" /quiet && "%BOOTICE%" /device=%~d0 /mbr /install /type=nt60 /quiet && "%BOOTICE%" /device=%~d0 /pbr /install /type=bootmgr /quiet
GOTO :done

:restorembr
echo ** Restoring previous boot loader to MBR and PBR for [%~d0]...
"%BOOTICE%" /device=%~d0 /mbr /restore /file="%_PREVMBR%" /quiet && "%BOOTICE%" /device=%~d0 /pbr /restore /file="%_PREVPBR%" /quiet && del /f "%_PREVMBR%" && del /f "%_PREVPBR%"
GOTO :done

:winefi
echo ** Switching to Windows UEFI Boot Loader...
REM Figure out which boot loader is boot.efi by missing files
IF NOT EXIST "%_GRUBEFI%" (
    echo ** ...from Windows UEFI Boot Loader...
    move /y "%_BOOTEFI%" "%_GRUBEFI%"
) ELSE IF NOT EXIST "%_REFEFI%" (
    echo ** ...from reFIND EFI Boot Loader...
    move /y "%_BOOTEFI%" "%_REFEFI%"
) ELSE (
    echo ** ...from unknown/other EFI Boot Loader...
    move /y "%_BOOTEFI%" "%_OTHEREFI%"
)
move /y "%_WINEFI%" "%_BOOTEFI%"
GOTO :done

:grubefi
echo ** Switching to GRUB2 UEFI Boot Loader for [%~d0]...
REM Figure out which boot loader is boot.efi by missing files
IF NOT EXIST "%_WINEFI%" (
    echo ** ...from Windows UEFI Boot Loader...
    move /y "%_BOOTEFI%" "%_WINEFI%"
) ELSE IF NOT EXIST "%_REFEFI%" (
    echo ** ...from reFIND EFI Boot Loader...
    move /y "%_BOOTEFI%" "%_REFEFI%"
) ELSE (
    echo ** ...from unknown/other EFI Boot Loader...
    move /y "%_BOOTEFI%" "%_OTHEREFI%"
)
move /y "%_GRUBEFI%" "%_BOOTEFI%"
GOTO :done

:refefi
echo ** Switching to REFIND EFI Boot Loader for [%~d0]...
REM Figure out which boot loader is boot.efi by missing files
IF NOT EXIST "%_WINEFI%" (
    echo ** ...from Windows UEFI Boot Loader...
    move /y "%_BOOTEFI%" "%_WINEFI%"
) ELSE IF NOT EXIST "%_GRUBEFI%" (
    echo ** ...from GRUB2 UEFI Boot Loader...
    move /y "%_BOOTEFI%" "%_GRUBEFI%"
) ELSE (
    echo ** ...from unknown/other EFI Boot Loader...
    move /y "%_BOOTEFI%" "%_OTHEREFI%"
)
move /y "%_REFEFI%" "%_BOOTEFI%"
GOTO :done

:otherefi
echo ** Switching to other/unknown EFI Boot Loader for [%~d0]...
REM Figure out which boot loader is boot.efi by missing files
IF NOT EXIST "%_WINEFI%" (
    echo ** ...from Windows UEFI Boot Loader...
    move /y "%_BOOTEFI%" "%_WINEFI%"
) ELSE IF NOT EXIST "%_GRUBEFI%" (
    echo ** ...from GRUB2 UEFI Boot Loader...
    move /y "%_BOOTEFI%" "%_GRUBEFI%"
) ELSE IF NOT EXIST "%_REFEFI%" (
    echo ** ...from reFIND EFI Boot Loader...
    move /y "%_BOOTEFI%" "%_REFEFI%"
)
move /y "%_OTHEREFI%" "%_BOOTEFI%"
GOTO :done

:done
echo ** Done.
pause

Edited by generalmx, 29 July 2015 - 06:29 AM.


#3 steve6375

steve6375

    Platinum Member

  • Developer
  • 6629 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 29 July 2015 - 06:54 AM

It would be better to find out why it cannot boot to grub4dos.

What symptoms do you get? What versions of grub4dos have you tried?

What boot media are you using and how was it partitioned/formatted?



#4 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13752 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 29 July 2015 - 03:36 PM

With all due respect :), it is the "base reason" that might be if not "false" an "assumption".

 

There is no doubt that there are some motherboard BIOSes that may have issues with one (or the other or all) versions of grub4dos when it is installed to the MBR (+a few hidden sectors), i.e. the boot chain is:

BIOS->grub4dos MBR (grldr.mbr)->grldr->whatever

 

But the normal boot chain from NT 6.x is:

BIOS->MBR->PBR->BOOTMGR

 

It is years that I go around saying that the good ol' Windows 2000/XP MBR (or maybe nowadays the NT 6 MBR from Windows 7) is the one that most probably the manufacturer of the BIOS have actually tested (not because they are "good" or "better", only because they are the "most common").

Most people do not experience these issues, but if you do, you can use alternate methods to boot grub4os, I don't really see the issue - when making a stick which includes a BOOTMGR - to have the "normal" NT6 boot chain:

BIOS->MBR->PBR->BOOTMGR

adding to it a BOOT.INI linked to grldr and thus have the possibility of:

BIOS->MBR->PBR->BOOTMGR->BOOT.INI->grldr

 

Sure, you have an added selection to make, but in a multiboot thingy you have anyway the need to make a choice.

 

Just for the record, in newer versions of grub4dos (but since a lot of time) you can directly use grldr instead of grldr.mbr for BOOTMGR chainloading.

 

In any case, second sector of the grldr.mbr has a "hole" in which it can be optionally copied the "previous" MBR (which can actually be *any* MBR, as long as it is a plain MBR one sector long), so you can do the switching from grub4dos, using (say) sector 62 to hold a copy of the first sector of the grub4dos MBR, :

root (hd0)

dd if=()0+1 of=()62+1

dd if=()1+1 of=()0+1

 

and then:

dd if=()62+1 of=()0+1

to return "as before", of course depending on the setup you need to provide a way to boot anyway to grub4dos or use a "dd-like" program from the booted OS to perform the same restore.

 

 

 

:duff:

Wonko



#5 steve6375

steve6375

    Platinum Member

  • Developer
  • 6629 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 03 August 2015 - 11:12 AM

I would like to try to investigate and issue where you cannot boot from a correctly prepared USB E2B drive.

If you can provide details of a system which will not boot from an E2B USB drive but will boot via bootmgr, I would be interested in trying to find out why and how to fix it.

If you installed E2B using the recommended way (using MAKE_E2B_USB_DRIVE.cmd or RMPrepUSB) , then both MBR and PBR should contain grub4dos boot code. Also the MBR boot code starting bytes should be the same as a standard MS MBR + other compatibility features.

bootice does not install a compatible grub4dos MBR, the latest grubinst.exe will (as used by E2B and RMPrepUSB).



#6 Zoso

Zoso

    Silver Member

  • Advanced user
  • 640 posts
  •  
    Isle of Man

Posted 03 August 2015 - 11:57 AM

hi generalmx, Wonko, steve6375,

I really like what Wonko suggests here. steve6375, could his suggestion be an option with easy2boot or does it interfere or break something in easy2boot's functioning? this is also the main reason I dont use E2B, bootice or others that must be "installed" because I like to have the option to use other custom mbrs when needed.

thanks

#7 steve6375

steve6375

    Platinum Member

  • Developer
  • 6629 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 03 August 2015 - 12:04 PM

Not sure which particular suggestion you are referring to.

E2B uses sectors 30 and 60 for .imgPTN files.

How do you know that just changing the MBR will fix the problem?



#8 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13752 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 03 August 2015 - 01:04 PM

Well there is only one suggestion provided here, the idea  :idea:  that any BIOS programmer with more than one neuron :w00t: (while it may possibly have introduced one or more direct or indirect, voluntarily or involuntary limitation for any given byte sequence in the MBR code :ph34r:) quite certainly has tested the stupid BIOS against "common" MBR codes.

 

For obvious reasons this - depending on the year when the BIOS was written (i.e. when the motherboard came out) means in practice:

  1. the DOS 6.22 or 7/7.1/8.0 MBR code
  2. the Windows NT/2K/XP MBR code
  3. the Vista/7/8/8.1 MBR code

This has nothing to do with the "quality" of the code or with "anything else", the observation is merely a statement of probability that something has been actually tested successfully.

 

In my experience the Syslinux (or makebootFAT which has more or less the same origin) and the MBLDR one are also very "compatible", but of course YMMV.

 

I would add (and I am saying this since the dawn of time) that unless there are valid reasons (i.e. actual requirements or needs) to install a multi-sector MBR code (not particularly grub4dos, the reasoning is exactly the same for *anything* that is not exactly 512 bytes in size) the probability that a plain, self-contained in the LBA 0, 512 bytes long code will work on *any* BIOS/motherboard is higher.

 

Grub4dos (I understand with even higher probability in your forked version) has anyway a very high level of compatibility, surely more than 90 or 95%, but while there is obviously no guarantee that any code will ever be 100% compatible, the "standard" MS one is the one that is likely to be reaching  99% or so.

 

As a side note, generically speaking (not necessarily this being the case) reports of actual grub4dos (or RMPREPUSB/E2B) code failing during boot are often not detailed enough (or the user is not actually interested in actually troubleshooting the problem till the actual reason cause is found) with the result that IMHO at least some of these reports of grub4dos code (plain or RMPREPUSB/E2B) failing are caused by *something* else.

 

:duff:

Wonko



#9 Zoso

Zoso

    Silver Member

  • Advanced user
  • 640 posts
  •  
    Isle of Man

Posted 03 August 2015 - 02:50 PM

Not sure which particular suggestion you are referring to.
E2B uses sectors 30 and 60 for .imgPTN files.
How do you know that just changing the MBR will fix the problem?


using MS mbr to invoke grub4dos through boot.ini entry but not because of potential boot failure, rather so that other custom mbrs can be used that still retain ability to invoke grub4dos.

you may not recall but I mentioned to you a while back (years now) that due to lacking knowledge on how to get certain things working when booting multiple OS from extended partitions that I found a way to keep the several different MS OS's from seeing each other and therefor conflicting and corrupting each other that I found that if I used diskcryptor the conflicts went away because each OS (each having its own partition) I used a different password so the one that boots has its own pasword and when booted only sees the others as raw unformated partitions

so I got a set up now where I use one password (7) to boot into a 7 BCD store that has multiple Vista and upwards OS's and another password (X) to boot into a boot.ini with grub4dos entry and several other versions of XP.

I hope that makes sense! there is probably a way to do it without the diskcryptor mbr but thats how I do it so I havnt had a need to learn another way but I would like to incorporate E2B into my setup somehow because of all the advances you have made with it but I dont know how and would have to spend alot of trial and error time to learn how.

I was planning to try it (E2B) soon anyway on a separate stick just to get familiar with it to see if I can figure out how to incorporate my current setup but I dont have alot of time or equipment for experimenting/learning these thing and if you had the option like wonko mentions then I know I could use E2B on my current setup.

anyway, thanks for all the incredible work youve been doing steve6375! cant wait to get into it more eitherway but since wonko brought it up..

thanks

#10 generalmx

generalmx

    Newbie

  • Members
  • 14 posts
  •  
    United States

Posted 03 August 2015 - 08:32 PM

It would be better to find out why it cannot boot to grub4dos.

What symptoms do you get? What versions of grub4dos have you tried?

What boot media are you using and how was it partitioned/formatted?

 

From recollection --- it happens so rarely and I'm sometimes in a rush --- it appears to be a select few systems with early UEFI implementations trying to use CSM or Hybrid UEFI. Basically newer systems; generally older systems have no trouble. We also deal with so many UEFI systems now that's why I worry so much about UEFI compatibility, too. We also get about one system per week that UEFI/EFI can't even be turned off on, including Macs. All Easy2Boot flash drives were made through the official batch file, latest version from a few months ago. I did not change the partitioning scheme E2B sets up.

 

Anyway I decided to just keep it as a batch file, since if Easy2Boot isn't booting then they wouldn't be able to use it to switch boot loaders anyway. Bootmgr still can boot into the Easy2Boot environment through its reference in both BCD and BOOT.INI.


Edited by generalmx, 03 August 2015 - 08:34 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users