grub2-filemanager icon indicating copy to clipboard operation
grub2-filemanager copied to clipboard

Legacy boot of .img files doesnt work.

Open steve6375 opened this issue 3 years ago • 13 comments

The rules/img/hdd.sh tries to call grub4dos grub.exe but hangs. I found that the --config-file= string is fussy. http://reboot.pro/index.php?showtopic=15422 Also the version of grub.exe you are using has a bug when loading from command line I changed to the latest version of grub.exe and used this code.

source ${prefix}/func.sh;

if [ "$grub_platform" = "efi" ];
then
  map "${grubfm_file}";
else
  to_g4d_path "${grubfm_file}";
  if [ -n "${g4d_path}" ];
  then
	set opts="set file=${g4d_path} ;; map --heads=0 --sectors-per-track=0 %file% (hd) ;; map --hook ;; rootnoverify (hd-1,0) ;; chainloader (hd-1)+1 ;; boot"
	linux (${user})/boot/grubfm/grub.exe --config-file=${opts}
  else
    set enable_progress_indicator=1;
    linux16 ${prefix}/memdisk harddisk raw;
    initrd16 "${grubfm_file}";
  fi;
  boot;
fi;

Now it will boot a 32GB .img of Medicat (two partitions) OK.

Note: I removed --mem. I will test with --mem and add amended code later.

steve6375 avatar Aug 01 '22 10:08 steve6375

P.S. adding || is causing a problem! set opts="set file=${g4d_path} ;; map --heads=0 --sectors-per-track=0 %file% (hd) || map --heads=0 --sectors-per-track=0 --mem %file% (hd) ;; map --hook ;; rootnoverify (hd-1,0) ;; chainloader (hd-1)+1 ;; boot"

trying to find a way round it...

steve6375 avatar Aug 01 '22 10:08 steve6375

image Its a line length issue!

only change is in echo command....

#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"

So if long path for .img file then can fail.

steve6375 avatar Aug 01 '22 11:08 steve6375

Using your menu.lst + (rd) original code

using recent grub.exe works.

#WORKS
    set g4d_cmd="map --mem (rd)+1 (fd0);;map --hook;;configfile (fd0)/menu.lst";
    to_g4d_menu "set file=${g4d_path}\x0amap %file% (hd-1) || map --mem %file% (hd-1)\x0amap --hook\x0arootnoverify (hd-1)\x0achainloader +1\x0aboot";
    linux (${user})/boot/grubfm/grub.exe --config-file=${g4d_cmd};
    initrd (rd);

#HANGS	
    set g4d_cmd="map --mem (rd)+1 (fd0);;map --hook;;configfile (fd0)/menu.lst";
    to_g4d_menu "set file=${g4d_path}\x0amap %file% (hd-1) || map --mem %file% (hd-1)\x0amap --hook\x0arootnoverify (hd-1)\x0achainloader +1\x0aboot";
    linux ${prefix}/grub.exe --config-file=${g4d_cmd};
    initrd (rd);

steve6375 avatar Aug 01 '22 11:08 steve6375

Here is final code which I think is OK!

    set g4d_cmd="map --mem (rd)+1 (fd0);;map --hook;;configfile (fd0)/menu.lst";
    to_g4d_menu "set file=${g4d_path}\x0amap --heads=0 --sectors-per-track=0 %file% (hd) || map --heads=0 --sectors-per-track=0 --mem %file% (hd)\x0amap --hook\x0arootnoverify (hd-1)\x0achainloader +1\x0aboot";
    linux (${user})/boot/grubfm/grub.exe --config-file=${g4d_cmd};
    initrd (rd);

so changes are using ;; in g4d_cmd map to (hd) not hd-1 (in case there is no hard disk in system or do not want to map out last hdd) use --heads=0 --sectors-per-track=0 to make map command detect correct geometry use new grub.exe

steve6375 avatar Aug 01 '22 11:08 steve6375

This also works using ;; instead of \x0a:

    set g4d_cmd="map --mem (rd)+1 (fd0) ;; map --hook ;; configfile (fd0)/menu.lst";
    to_g4d_menu "set file=${g4d_path} ;; map --heads=0 --sectors-per-track=0 %file% (hd) || map --heads=0 --sectors-per-track=0 --mem %file% (hd) ;; map --hook ;; rootnoverify (hd-1) ;; chainloader +1 ;; boot";
#approx 200 character limit for grub.exe params (including the --config-file=)
    linux (${user})/boot/grubfm/grub.exe --config-file=${g4d_cmd};
    initrd (rd);

steve6375 avatar Aug 01 '22 12:08 steve6375

using my new grub.exe ...

source ${prefix}/func.sh;

if [ "$grub_platform" = "efi" ];
then
  map "${grubfm_file}";
else
  to_g4d_path "${grubfm_file}";
  if [ -n "${g4d_path}" ];
  then
    set g4d_cmd="map --mem (rd)+1 (fd0) ;; map --hook ;; configfile (fd0)/menu.lst";
    to_g4d_menu "set file=${g4d_path} ;; map --heads=0 --sectors-per-track=0 %file% (hd) || map --heads=0 --sectors-per-track=0 --mem %file% (hd) ;; map --hook ;; rootnoverify (hd-1) ;; chainloader +1 ;; boot";
#approx 200 character limit for grub.exe params (including the --config-file=)
    linux (${user})/boot/grubfm/grub.exe --config-file=${g4d_cmd};
    initrd (rd);
  else
    set enable_progress_indicator=1;
    linux16 ${prefix}/memdisk harddisk raw;
    initrd16 "${grubfm_file}";
  fi;
  boot;
fi;

P.S. When is the

    set enable_progress_indicator=1;
    linux16 ${prefix}/memdisk harddisk raw;
    initrd16 "${grubfm_file}";

code used?

steve6375 avatar Aug 01 '22 12:08 steve6375

P.S. rules/vhd/map.sh code has similar issue.

steve6375 avatar Aug 01 '22 14:08 steve6375

P.S. When is the

    set enable_progress_indicator=1;
    linux16 ${prefix}/memdisk harddisk raw;
    initrd16 "${grubfm_file}";

code used?

If the img file is not on a real hard drive (e.g. (loop)/xxx.img), grub4dos cannot read it. https://github.com/a1ive/grub2-filemanager/blob/918524dc18f08eba1ade421282b54a7b2787fa15/boot/grubfm/g4d_path.lua#L24-L36

a1ive avatar Aug 08 '22 06:08 a1ive

This also works using ;; instead of \x0a

What are the advantages of using ';;'? Does GRUB4DOS treat it as multi-line or one-line statements? (to avoid exceeding the maximum single line character limit)

map to (hd) not hd-1 (in case there is no hard disk in system or do not want to map out last hdd) use --heads=0 --sectors-per-track=0 to make map command detect correct geometry

What does (hd) mean?

a1ive avatar Aug 08 '22 06:08 a1ive

I found that the --config-file= string is fussy.

According to Linux/x86 boot protocol, the max length of v2.05 cmdline is 255. GRUB2 adds BOOT_IMAGE=/path/to/kernel and other info (vga, memory) to cmdline, so max length is about 200.

a1ive avatar Aug 08 '22 06:08 a1ive

I just tried ;; (use for multiple statements on one grub4dos line) and it worked. I did not then go back and change it to ; so I cannot say that using just ; instead would not work.

(hd) means the NEXT FREE hd device number in grub4dos. So if we have hd0 and hd1, using map xxx (hd) would map xxx as hd2. From then on, we can reference the xxx file as device (hd-1). If you use map xxx (hd-1) then you would replace hd1 (the last hd device) with xxx so the true BIOS device hd1 would not be accessible.

steve6375 avatar Aug 08 '22 09:08 steve6375

(hd) means the NEXT FREE hd device number in grub4dos. So if we have hd0 and hd1, using map xxx (hd) would map xxx as hd2. From then on, we can reference the xxx file as device (hd-1). If you use map xxx (hd-1) then you would replace hd1 (the last hd device) with xxx so the true BIOS device hd1 would not be accessible.

If the OS installed on the img is DOS (Win 9x), then it must be mapped to (hd0). Maybe (hd0) -> (hd), img -> (hd0) ?

a1ive avatar Aug 08 '22 11:08 a1ive

Maybe extra options in the Secondary menu ?

Boot floppy image Boot hard drive as disk 0 Boot hard drive as last disk

image

a .img file could boot as hd0, or hdn, from chainloader +1 or from PBR of first partition or second ptn or boot.wim (or .EFI file if UEFI?)

steve6375 avatar Aug 08 '22 12:08 steve6375