Jump to content











Photo
- - - - -

Grub4Dos - Change Options on boot


  • Please log in to reply
13 replies to this topic

#1 grrrd

grrrd

    Frequent Member

  • Advanced user
  • 132 posts
  •  
    United Kingdom

Posted 27 July 2016 - 11:35 AM

Hi All;

 

I am using Grub4DOS as an automatic recovery option but i was wondering if someone could help with updating the Menu.lst due to peramaenters;

 

The ideal situation is that if Menu Option 1 (saying Windows boot option) fails to load correctly, load option 2 which is a Winpe ISO.

Now i understand that Windows could load successfully, but fail halfway or similar so this isn't really a possibility. So what i would like to be able to do is change the default boot option in the menu.lst when it runs it;

 

For Example:

 

Menu.lst default option to boot WinPE.ISO, before booting it will amend the Menu.lst to say the next time its loaded to default option to boot WindowsXp

 

 

My current code where you have to manually choose your options;

write (md)0x220+1 !BAT\necho -n -P:0000 $[0133]                      --- KFC Rescue my PC ---                                         \0                              
initscript (md)0x220+1

find   --set-root   /PC_Restore/PC.xpm.gz    &&   splashimage   /PC_Restore/PC.xpm.gz
default 0
timeout 5
color white/blue 
color normal=0x0c highlight=0x1e helptext=0x0D standard=0x02 border=0x0c

title Boot to Windows\n
errorcheck off
find --set-root /ntldr || find --set-root /bootmgr
chainloader /ntldr || chainloader /bootmgr

title Rescue my PC!
find --set-root /PC_Restore/GRUB/WinPE.iso
map /PC_Restore/GRUB/WinPE.iso (0xff) || map --mem /PC_Restore/GRUB/WinPE.iso (0xff)
map --hook
chainloader (0xff)


#2 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 27 July 2016 - 12:41 PM

Check the default and savedefault command.

Guide is offline :(, mirror here:
http://www.owl.homei...os/Grub4dos.htm

http://www.owl.homei...enu.htm#default

See also:
http://www.rmprepusb...he-menu-entries

 

The issue here may be the "conditional" find and chainloader commands you have :unsure:

 

Loosely:

default (hd0,0)/default

...

title 0 boot XP

...

savedefault

chainloader /ntldr || savedefault=2

 

title 1 boot 7

...

savedefault

chainloader /bootmgr || savedefault=2

 

 

title 2 boot iso

chainloader (0xff) || savedefault=0

 

Cannot say if something *like*:

 

default (hd0,0)/default

...

title 0 boot windows

...

savedefault=1

chainloader /ntldr &; savedefault=0 ||  chainloader /bootmgr &; savedefault=0

 

 

title 1 boot iso

 

chainloader (0xff) || savedefault=0

 

or similar might work with the specific version of grub4dos you are using.

 

:duff:

Wonko 


  • grrrd likes this

#3 grrrd

grrrd

    Frequent Member

  • Advanced user
  • 132 posts
  •  
    United Kingdom

Posted 01 August 2016 - 10:16 AM

perfect - Thanks Wonko, Just had to make sure i had a default file already on the drive - it doesn't seem to create a file for the default if it isn't present.



#4 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 01 August 2016 - 10:32 AM

perfect - Thanks Wonko, Just had to make sure i had a default file already on the drive - it doesn't seem to create a file for the default if it isn't present.

Yes, a pre-made one is needed and it needs to be bigger than 704 (or so) bytes to be non-resident in NTFS (the provided one is 2048 bytes, which is good).

 

What commands did you test and are using? (so that other people with the same or similar issue can find a tested working solution)

 

:duff:

Wonko



#5 grrrd

grrrd

    Frequent Member

  • Advanced user
  • 132 posts
  •  
    United Kingdom

Posted 01 August 2016 - 11:24 AM

write (md)0x220+1 !BAT\necho -n -P:0000 $[0133]                      --- Rescue my PC ---                                         \0                              
initscript (md)0x220+1

find   --set-root   /PC_Restore/PC.xpm.gz    &&   splashimage   /PC_Restore/PC.xpm.gz
default /default
timeout 5
color white/blue 
color normal=0x0c highlight=0x1e helptext=0x0D standard=0x02 border=0x0c

title 2 Rescue my PC!
savedefault=1
find --set-root /PC_Restore/GRUB/WinPE.iso
map /PC_Restore/GRUB/WinPE.iso (0xff) || map --mem /PC_Restore/GRUB/WinPE.iso (0xff)
map --hook
chainloader (0xff)

title 1 Boot to Windows\n
errorcheck off
Savedefault
find --set-root /ntldr || find --set-root /bootmgr
chainloader /ntldr || chainloader /bootmgr

So first boot option 2 is selected, but then makes option 1 default for next boot



#6 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 01 August 2016 - 11:39 AM

  

So first boot option 2 is selected, but then makes option 1 default for next boot

 

Boot option 2 is "title 2" and  actually item 0, but I don' t understand the logic :w00t: (at least initially you asked something different).

 

Those entries don't do anything if the chainloading of ntldr or bootmgr fails. :dubbio:, the only thing that is done seemingly  is that the pre-selected entry is ALWAYS #1, no matter if you previously booted the "rescue" or the "main OS" (or if any of them failed to boot) exception made for - maybe - first run.

Also Savedefault is not a valid command (savedefault is).

 

:duff:

Wonko


  • grrrd likes this

#7 grrrd

grrrd

    Frequent Member

  • Advanced user
  • 132 posts
  •  
    United Kingdom

Posted 01 August 2016 - 02:12 PM

I didn't realize i could do 'something' if ntldr or bootmgr fails? What am i able to do if these failures?



#8 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 01 August 2016 - 03:10 PM

I didn't realize i could do 'something' if ntldr or bootmgr fails? What am i able to do if these failures?

I don't know, this is what you asked:

The ideal situation is that if Menu Option 1 (saying Windows boot option) fails to load correctly, load option 2 which is a Winpe ISO.

The answer to this is using some conditional execution, i.e. using the logical operators between grub4dos commands to change default at next boot or using the special fallback command to attempt booting another entry in the same "session".

What you posted as a solution seemingly does NOT change pre-selected menu entry (default).
If you (manually) choose "title 2 Rescue my PC!" at next boot the default will be item #1, i.e. "title 1 Boot to Windows", since in it you have a command "savedefault=1".
If you (manually) choose "title 1 Boot to Windows" at next boot the default will as well be item #1, i.e. "title 1 Boot to Windows", since the entry is #1 and you have a "savedefault" command in it.

So, whatever you chose, at next boot default will be "title 1 Boot to Windows", there is nothing "conditional" in this, you could have a "default 1" command in the first part of the menu.lst and you would have the exact same effect, this is what I don't understand.

:duff:
Wonko

#9 grrrd

grrrd

    Frequent Member

  • Advanced user
  • 132 posts
  •  
    United Kingdom

Posted 02 August 2016 - 07:48 AM

So the idea here is:

 

99% of the time i want to boot windows, if windows fails i would like to boot into the rescue option.

 

I want to also use this rescue option if the windows boot has issues (virus/corruption etc) so i would like to select this option even when windows is working fine - this calls some scripts that check to see if all the files required are there and present - if not i want it to reboot straight back to windows (windows with issues is better than no windows at all)

 

 

You hinted that there is a possibility of saying choose the Rescue option IF booting to windows fails - can you elaborate on this please?



#10 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 02 August 2016 - 11:07 AM

Re-read the given link on Steve's RMPREPUSB site:

http://www.rmprepusb...he-menu-entries

 

the other relevant part is inside the "Map Command" section:
http://www.rmprepusb...The-map-command

 

There is  fallback command, loosely:

default 0

title 0 Boot to Windows\n
fallback 1
errorcheck off
find --set-root /ntldr || find --set-root /bootmgr
chainloader /ntldr || chainloader /bootmgr

title 1 Rescue my PC!
find --set-root /PC_Restore/GRUB/WinPE.iso
map /PC_Restore/GRUB/WinPE.iso (0xff) || map --mem /PC_Restore/GRUB/WinPE.iso (0xff)
map --hook
chainloader (0xff)

will attempt to boot item 1 if item 0 (which is default) fails to boot (of course this only works if the failure happens in the grub4dos part, i.e. before ntldr or bootmgr are running).

 

Additionally Grub4dos has a number of conditional and non conditional execution "connectors", you are already using "||" in you menu.lst.

There are also:
"&&", ";&",";;", "|;" 

 

You need to check if the grub4dos version you are using is recent enough to support these operators, then experiment with them to follow your logic, since you are using (why?) a "vague" menu.lst entry that attempts to boot either ntldr or bootmgr, giving a priority to ntldr, it is your own problem to see how they can be combined in your case.

 

"Normally" you actually choose what you want to boot and/or have just one entry for the specific bootloader of the OS, in those case it is easier.

 

The menu entry that you have right now, if it finds a NTLDR it boots it, no matter if BOOTMGR exists or not.

There are three cases:
1) you have only a NT 4/5 OS (and ONLY a NTLDR)

2) you have both a NT 4/5 OS and a 6+ one (and BOTH a NTLDR and a BOOTMGR)

3) you have only a NT 6+ (and ONLY a BOOTMGR)

Case #1 will boot NTLDR.

Case #2 will boot NTLDR as well

Case #3 will boot BOOTMGR

 

To me it would make more sense to make an entry for NT 4/5 and one for NT 6+ and have either the "proper" one or both (as separate entries).

 

:duff:

Wonko


  • grrrd likes this

#11 grrrd

grrrd

    Frequent Member

  • Advanced user
  • 132 posts
  •  
    United Kingdom

Posted 02 August 2016 - 02:16 PM

OK so roughly, if Grub4Dos fails to locate the boot files on any given option the fallback will then try and boot a different pre-defined option?



#12 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 02 August 2016 - 03:21 PM

grrrd, on 02 Aug 2016 - 4:16 PM, said:
OK so roughly, if Grub4Dos fails to locate the boot files on any given option the fallback will then try and boot a different pre-defined option?

Roughly yes, more properly if the "whole entry" fails i.e. actually the last, implied, "boot" command fails, then the "fallback" entry is executed.

If you could just check a "current" example/sample of a grub4dos menu, you would see how it works, snippet:

color blue/green yellow/red white/magenta white/magenta
timeout 30
## menu border color
color border=0xEEFFEE
## set vbe mode
graphicsmode -1 640:800 480:600 24:32 || graphicsmode -1 -1 -1 24:32
## loading splashimage
splashimage /boot/grub/splashimage.xpm || splashimage /boot/grub/splashimage.bmp
default /default
## Menu AutoNumber
write 0x8274 0x2001

title find and load NTLDR of Windows NT/2K/XP\n find and load NTLDR of Windows NT/2K/XP
fallback +1
find --set-root --ignore-floppies --ignore-cd /ntldr
map () (hd0)
map (hd0) ()
map --rehook
find --set-root --ignore-floppies --ignore-cd /ntldr
chainloader /ntldr
savedefault --wait=2

#iftitle only show when command in [] returns true
# set a variable named bootmgr where /bootmgr is found.
iftitle [find --set-root --devices=h /bootmgr && call set bootmgr=%@root^%] load BOOTMGR of Windows VISTA/WIN7/WIN2008 on %bootmgr%
fallback +1
chainloader %bootmgr%/bootmgr
savedefault --wait=2

...
title Switch to GRUB2 core.img for booting Linux (Ubuntu, etc)
fallback +1
find --set-root --ignore-floppies --ignore-cd /boot/grub/i386-pc/core.img
...

Here the fallback +1 means "if this entry fails, try next one".

You might also appreciate how the example for BOOTMGR solves the issue in a (IMHO) much more elegant way by using iftitle.

:duff:
Wonko
  • grrrd likes this

#13 grrrd

grrrd

    Frequent Member

  • Advanced user
  • 132 posts
  •  
    United Kingdom

Posted 03 August 2016 - 10:06 AM

Thank you wonko - i will have a little play with this!



#14 steve6375

steve6375

    Platinum Member

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

Posted 04 August 2016 - 11:41 AM

You can also use   goto n   in menus where n is the menu entry number.

 

There was a small bug to do with errorcheck but this is now fixed.


  • grrrd likes this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users