Jump to content











Photo
- - - - -

Problem in chainloading Grub4DOS from Grub2


  • Please log in to reply
14 replies to this topic

#1 Holmes.Sherlock

Holmes.Sherlock

    Gold Member

  • Team Reboot
  • 1444 posts
  • Location:Santa Barbara, California
  •  
    United States

Posted 12 September 2011 - 07:19 PM

I've the following OSes/items present/installed on my system which used to come up in the boot menu till a couple of days back:
  • Windows XP
  • Windows 7
  • Ubuntu 10.10 Netbook edition
  • Acronis 2011 recovery ISO
  • LENOVO preinstalled recovery environment
  • Grub4DOS command line shell
Here is a screenshot of my HD layout for better understanding:


Posted Image

I built this setup using Ubuntu's Grub2 & Grub4DOS 0.4.5b. What I did was, I installed Grub2 on the MBR. So, it used to take over the control of the booting process from the system startup. I modified it's /boot/grub/grub.cfg file with the entries below:


menuentry "Windows XP Professional"{

set root=(hd0,11)

linux16 /Rescue/grub4dos-0.4.5b/grub.exe --config-file="root (hd0,0);chainloader /ntldr"

}

menuentry "Windows 7 Ultimate"{

set root=(hd0,11)

linux16 /Rescue/grub4dos-0.4.5b/grub.exe --config-file="root (hd0,0);chainloader /bootmgr"

}

menuentry "Acronis TrueImage 2011 Home Edition"{

set root=(hd0,11)

linux16 /Rescue/grub4dos-0.4.5b/grub.exe --config-file="root (hd0,10);map --mem /Rescue/Acronis-2011.iso (0xff);map --hook;chainloader (0xff)"

}

menuentry "Grub4DOS"{

set root=(hd0,11)

linux16 /Rescue/grub4dos-0.4.5b/grub.exe --config-file="(hd0,10)/Rescue/grub4dos-0.4.5b/menu.lst"

}


So, basically you can see that it's a mere chainloading of Grub4DOS from Grub2 & every single option used to work fine. Here is a relevant text extracted from the README of the Grub4DOS version I'm using:


Update: FILE can be the contents of a menu. Use semi-colon
to delimitate the embedded commands here in FILE. The FILE
can be enclosed with a pair of double-quotes. For example:

GRUB --config-file="root (hd0,0);chainloader +1"

This command will boot the system in (hd0,0).

Another example:

GRUB --config-file="reboot"

This command will reboot the machine.

One more example:

GRUB --config-file="halt"

This command will halt the machine.


But alas, since yesterday, the setup stopped working. Naturally what comes up in mind that what has this guy done with the setup? The small amount of fiddling I've done with my system is to just overwrite the Ubuntu 10.10 installation with Zorin OS, an Ubuntu derivative which also employs Grub2 as it's bootloader. I added the same entries as mentioned above to the grub.cfg file, but this time choosing any of my "custom" options is dropping me to the Grub4DOS commandline shell itself. The behavior is the sane when "no" --config-file parameter is passed to Grub4DOS via Grub2. This has made me believe that for *some* the arguments are not being passed properly. But what has made me astonished that the menu entries are well tested & fully working since last eight months at lest. Still I'm scratching my head. You'll feel pity on me if you hear that I'm booting into my Windows by typing

chainloader (hd0,0)/ntldr
boot

from the Grub4DOS commandline every time. BTW, it is not my aim to boot my system by any means but to get it working by chainloading Grub4DOS from Grub2. Any ideas?

#2 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 12 September 2011 - 07:32 PM

Wouldn't checking the EXACT GRUB2 version used by Zorin OS and compare it with the one used by UBUNTU 10.10 first thing to check?
Or simply re-install the grub2 that comes with Ubuntu?

:cheers:
Wonko

#3 nando4

nando4

    Frequent Member

  • Advanced user
  • 112 posts
  •  
    Australia

Posted 12 September 2011 - 08:59 PM

The latest version of grub2 seems to omit the quotes, so ignores the params after config-file=. The workaround is to do two double-quotes. In my example below I'm also adding a second configfile in that param so grub4dos can find my menu.lst file. Strange, but this works for me.

# Load grub.exe from (hd0,2), passing params in --config-file to use /menu.lst

# config file on NTFS partition. grub2/grub4dos have different (hd0,1)..(hd0,n)

# and (hd0,0)..(hd0,n-1) partition labels explaining why the configfile entry

# has (hd0,1) instead of (hd0,2). grub.exe directly maps the image so can r-w

# it exactly like a disk.

 

menuentry 'DIY eGPU Setup 1.x'{

  linux16 (hd0,2)/eGPU/grub.exe --config-file=""configfile (hd0,1)/eGPU/menu.lst""

}

Edited by nando4, 12 September 2011 - 08:59 PM.


#4 Holmes.Sherlock

Holmes.Sherlock

    Gold Member

  • Team Reboot
  • 1444 posts
  • Location:Santa Barbara, California
  •  
    United States

Posted 13 September 2011 - 03:07 AM

The latest version of grub2 seems to omit the quotes, so ignores the params after config-file=. The workaround is to do two double-quotes. In my example below I'm also adding a second configfile in that param so grub4dos can find my menu.lst file. Strange, but this works for me.

Your solution did not work. I get a "File not found" error prompt. :(

#5 Holmes.Sherlock

Holmes.Sherlock

    Gold Member

  • Team Reboot
  • 1444 posts
  • Location:Santa Barbara, California
  •  
    United States

Posted 15 September 2011 - 12:21 AM

I checked that my version of Ubuntu uses Grub v1.98 where as Zorin OS employs Grub v1.99rc1 as its bootloader.

#6 Holmes.Sherlock

Holmes.Sherlock

    Gold Member

  • Team Reboot
  • 1444 posts
  • Location:Santa Barbara, California
  •  
    United States

Posted 15 September 2011 - 03:30 AM

Apart from the techniques described here, can anyone point to some other page instructing how to install Grub2(GRUB 1.98) from ubuntu-10.10-netbook-i386? The Linux installation which is there currently in my system is Zorin OS, an Ubuntu derivative.

#7 Holmes.Sherlock

Holmes.Sherlock

    Gold Member

  • Team Reboot
  • 1444 posts
  • Location:Santa Barbara, California
  •  
    United States

Posted 17 September 2011 - 03:04 AM

I booted the system using Super GRUB2 disk (it still uses GRUB 1.98, i.e. the same version as my previous Ubuntu installation). Selecting option #2, i.e. "Detect any GRUB2 configuration file (grub.cfg)" resulted in a blinking cursor on a blank, black background. Later I found that the issue was clearly mentioned here:

.............there may be issues loading the config file if it uses features from a newer version of GRUB2 than the one used in Super GRUB2 Disk........................


Then I entered into the command line of GRUB 1.98 (i.e one which is on Super Grub2 disk) & issued the following commands in sequence:

set root=(hd0,11)

linux16 /Rescue/grub4dos-0.4.5b/grub.exe --config-file="chainloader (hd0,0)/ntldr"

boot

At last my Windows installation booted like a charm.!!!! :cheerleader: :cheerleader: :cheerleader:

So, the conclusion is, "GRUB 1.98 is partially incompatible with GRUB 1.99rc1 & possibly, those good GRUB developers have inadvertently broken the ability to pass command line arguments at least with linux16 command in the newer version of GRUB2".

#8 Holmes.Sherlock

Holmes.Sherlock

    Gold Member

  • Team Reboot
  • 1444 posts
  • Location:Santa Barbara, California
  •  
    United States

Posted 17 September 2011 - 07:46 AM

Just for the record:
This page says:

Q: Why we need a GNU/Linux live CD to fix mbr with grub 2 ?
A: Grub1 could fix it's own grub on mbr with the root, install or setup commands. Grub2 does not have neither these commands nor equivalents. You need to boot into an installed or live GNU/Linux system to be able to use grub-install in order to install it.


So, I did the following;
  • Booted ubuntu-10.10-netbook-i386 in Live mode.
  • Checked the partition-to-device mapping with
    
    	sudo fdisk -l
    
    
  • Mounted the Zorin root partition with the following command
    
    	sudo mount /dev/sda5 /mnt
    
    
  • Installed GRUB2 (v 1.98)
    
    	sudo grub-install --root-directory=/mnt /dev/sda
    
    
The above sequence of commands installed GRUB2 successfully on the MBR of my first hard disk. Now it's working fine with the grub.cfg I mentioned above.

#9 Max Shonichev

Max Shonichev
  • Members
  • 8 posts

Posted 30 November 2011 - 11:43 PM

So, the conclusion is, "GRUB 1.98 is partially incompatible with GRUB 1.99rc1 & possibly, those good GRUB developers have inadvertently broken the ability to pass command line arguments at least with linux16 command in the newer version of GRUB2".

I found simple workaround for this issue :

# GRUB 1.99~rc1-13ubuntu3 sample code follows
set opt='chainloader (hd0,1)+1; boot'
linux16 ($root)/grub4dos/grub.exe --config-file=$opt


In other words, enclose all your grub4dos code in single quotes and assign to GRUB2 variable which you later pass as --config-file param.

Edited by Max Shonichev, 30 November 2011 - 11:46 PM.


#10 cyrusza

cyrusza
  • Members
  • 8 posts
  •  
    Italy

Posted 03 January 2017 - 03:48 PM

Didn't want to bring up this old thread, but this is among the first Google results when searching for "chainloading grub4dos from grub2".

 

All the information in the thread didn't solve my issue, so I want to add my 2 cents.

 

Using Max Sonichev workaround my configuration didn't work. Looks like the problem is related the parameters expansion. Enclosing the variable between {} fixed the problem. This is what worked for me:

menuentry "Test" {
  set root='(hd0,1)'
  set opts='map /test/mycd.iso (0xff);
            map --hook;
            chainloader (0xff);'
  linux /boot/grub/grub4dos.exe --config-file=${opts}
}

Edited by cyrusza, 03 January 2017 - 03:49 PM.


#11 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 03 January 2017 - 08:19 PM

Well, the suggestion by Max Shonichev was for command line.

 

The menuentry command in GRUB2 requires arguments enclosed in curly brackets:

https://www.gnu.org/....html#menuentry

 

As a side note, some versions/builds of GRUB2 can read directly entries inmenu.lst files, whilst some have a module that can convert them to grub.cfg-like entries.

 

Of course this is only good for menu.lst entries "compatible" with GRUB (a number of grub4dos specific commands won't work) but the above could work. :unsure:

 

:duff:

Wonko



#12 steve6375

steve6375

    Platinum Member

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

Posted 04 January 2017 - 09:45 AM

 

Didn't want to bring up this old thread, but this is among the first Google results when searching for "chainloading grub4dos from grub2".

 

All the information in the thread didn't solve my issue, so I want to add my 2 cents.

 

Using Max Sonichev workaround my configuration didn't work. Looks like the problem is related the parameters expansion. Enclosing the variable between {} fixed the problem. This is what worked for me:

menuentry "Test" {
  set root='(hd0,1)'
  set opts='map /test/mycd.iso (0xff);
            map --hook;
            chainloader (0xff);'
  linux /boot/grub/grub4dos.exe --config-file=${opts}
}

What does

set root='(hd0,1)'

do ???



#13 nguyentu

nguyentu

    Frequent Member

  • Advanced user
  • 102 posts
  •  
    Vietnam

Posted 04 January 2017 - 10:14 AM

What does

set root='(hd0,1)'

do ???

set root='(hd0,1)'
linux /boot/grub/grub4dos.exe --config-file=${opts}

It is equivalent to:

linux (hd0,1)/boot/grub/grub4dos.exe --config-file=${opts}

In Windows:

cd /d D:\
eg.exe

It is equivalent to:

D:\eg.exe

(hd0,1) means the first partition of the disk 0.

If the file not included partition like (hd0,1), (hd0,msdos1), (hd0,gpt1)... it will be used the value of root variable.


Edited by nguyentu, 04 January 2017 - 10:29 AM.


#14 steve6375

steve6375

    Platinum Member

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

Posted 01 August 2022 - 12:21 PM

Just hit this issue when testing a1ive's grubfm

I found that he was using a buggy grub.exe and the latest grub4dos grub.exe works better.

But also there is a  grub.exe parameter length limitation

 

e.g. if the value of  $g4d_path is approx 50 characters long, then I get these results:

#WORKS
set opts="set file=${g4d_path} ;; map --heads=0 --sectors-per-track=0 %file% (hd) || echo map 123456789 ;; map --hook ;; rootnoverify (hd-1,0) ;; chainloader (hd-1)+1 ;; boot"
#FAILS
set opts="set file=${g4d_path} ;; map --heads=0 --sectors-per-track=0 %file% (hd) || echo map 123456789012345 ;; map --hook ;; rootnoverify (hd-1,0) ;; chainloader (hd-1)+1 ;; boot"

only difference is the length of the echo command!

 

Not sure if limit is in grub.exe or grub2.

Limit seems to be approx. 180 chars after the --config-file=  characters?



#15 a1ive

a1ive

    Member

  • Developer
  • 58 posts
  •  
    China

Posted 03 August 2022 - 09:29 AM

Just hit this issue when testing a1ive's grubfm
I found that he was using a buggy grub.exe and the latest grub4dos grub.exe works better.
But also there is a  grub.exe parameter length limitation
 
e.g. if the value of  $g4d_path is approx 50 characters long, then I get these results:

#WORKS
set opts="set file=${g4d_path} ;; map --heads=0 --sectors-per-track=0 %file% (hd) || echo map 123456789 ;; map --hook ;; rootnoverify (hd-1,0) ;; chainloader (hd-1)+1 ;; boot"
#FAILS
set opts="set file=${g4d_path} ;; map --heads=0 --sectors-per-track=0 %file% (hd) || echo map 123456789012345 ;; map --hook ;; rootnoverify (hd-1,0) ;; chainloader (hd-1)+1 ;; boot"
only difference is the length of the echo command!
 
Not sure if limit is in grub.exe or grub2.
Limit seems to be approx. 180 chars after the --config-file=  characters?

https://www.kernel.o...t/x86/boot.html

The maximum size of the command line without the terminating zero. This means that the command line can contain at most cmdline_size characters. With protocol version 2.05 and earlier, the maximum size was 255.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users