Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

Legacy boot of .img files doesnt work. #351

Open
steve6375 opened this issue Aug 1, 2022 · 13 comments
Open

Legacy boot of .img files doesnt work. #351

steve6375 opened this issue Aug 1, 2022 · 13 comments

Comments

@steve6375
Copy link

steve6375 commented Aug 1, 2022

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
Copy link
Author

steve6375 commented Aug 1, 2022

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
Copy link
Author

steve6375 commented Aug 1, 2022

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
Copy link
Author

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
Copy link
Author

steve6375 commented Aug 1, 2022

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
Copy link
Author

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
Copy link
Author

steve6375 commented Aug 1, 2022

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
Copy link
Author

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

@a1ive
Copy link
Owner

a1ive commented Aug 8, 2022

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.

if string.match (device, "^hd[%d]+,[%w]+") ~= nil then
-- (hdx,y)
devnum = string.match (device, "^hd%d+,%a*(%d+)$")
devnum = devnum - 1
g4d_file = "(" .. string.match (device, "^(hd%d+,)%a*%d+$") .. devnum .. ")"
.. string.match (file, "^%([%w,]+%)(.*)$")
elseif string.match (device, "^[hcf]d[%d]*") ~= nil then
-- (hdx) (cdx) (fdx) (cd)
g4d_file = file
else
-- (loop) (memdisk) (proc) etc.
g4d_file = ""
end

@a1ive
Copy link
Owner

a1ive commented Aug 8, 2022

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
Copy link
Owner

a1ive commented Aug 8, 2022

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.

@steve6375
Copy link
Author

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.

@a1ive
Copy link
Owner

a1ive commented Aug 8, 2022

(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) ?

@steve6375
Copy link
Author

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?)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants