Jump to content











Photo
- - - - -

Optimizing boot scripts


  • Please log in to reply
41 replies to this topic

#1 DavidB

DavidB

    Silver Member

  • Developer
  • 611 posts

Posted 01 December 2014 - 08:31 AM

I created this topic to continue the offtopic discussion from http://reboot.pro/to...n-datatraveler/
This way I will be ontopic :D

I modified my Grub4DOS boot scripts so I can save/load the automatic loading of the internal USB 2.0 driver from 0.46a.
Also I implemented a way to detect if the driver is already enabled, using info found at this page: http://www.rmprepusb...s-and-functions (thank you Steve).

menu.lst:

if not "%MAINRAN%"=="1" call /initialize.g4b.gz
default %DefMenu%

title ^U USB 2.0 internal driver (U)
set /a DefMenu=*0x8276&0xff > nul
configfile /usb2load.lst

title
root

title Ultimate BootCD 5.33
set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul
configfile /ubcd/menus/grub4dos/main.lst

title Memtest 5.01
set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul
map /iso/memtest.img (fd0)||map --mem /iso/memtest.img (fd0)
map --hook
chainloader (fd0)+1
rootnoverify (fd0)
map --floppies=1

title Paragon Backup & Recovery CD
set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul
map /iso/Paragon_BootCD.iso (0xFF)||map --mem /iso/Paragon_BootCD.iso (0xFF)
map --hook
root (0xFF)
chainloader (0xFF)

title ^P Paragon Backup & Recovery CD 2nd way (P)
set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul
map /iso/Paragon_BootCD.iso (0xFF)||map --mem /iso/Paragon_BootCD.iso (0xFF)
map --hook
root (0xff)
kernel /VMLINUZP vga=0x314
initrd /INITRD.GZ

title ^M MiniTool Partition Wizard (M)
set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul
map /iso/MiniTool_Partition_Wizard.iso (0xFF)||map --mem /iso/MiniTool_Partition_Wizard.iso (0xFF)
map --hook
root (0xFF)
chainloader (0xFF)

title gparted 0.20.0 live
set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul
map /iso/gparted-live-0.20.0-2-i486.iso (0xff) || map --mem /iso/gparted-live-0.20.0-2-i486.iso (0xff)
map --hook
root (0xff)
kernel /live/vmlinuz boot=live config union=aufs noswap noprompt vga=788 ip=frommedia findiso=/iso/gparted-live-0.20.0-2-i486.iso toram=filesystem.squashfs
initrd /live/initrd.img

title Parted Magic
set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul
map /iso/pmagic_2014_09_29.iso (0xff) || map --mem /iso/pmagic_2014_09_29.iso (0xff)
map --hook
root (0xff)
kernel /pmagic/bzImage edd=off load_ramdisk=1 prompt_ramdisk=0 rw vga=normal sleep=10 loglevel=0 max_loop=256 vmalloc=384MiB keymap=us iso_filename=/iso/pmagic_2014_09_29.iso
initrd /pmagic/initrd.img

title PartitionGuru 462 FreeDOS
set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul
map --mem /iso/PartitionGuru462FreeDOS.img.gz (fd0)
map --hook
root (fd0)
chainloader /kernel.sys

title SystemRescueCd
set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul
kernel /sysrcd/rescue32 subdir=sysrcd setkmap=us
initrd /sysrcd/initram.igz

title
root

title Knoppix LiveCD
set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul
configfile /KNOPPIX/knoppix.lst

title ^F Start installed Fedora 18 on USB drive (F)
set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul
kernel (hd0,1)/boot/vmlinuz-3.9.9-201.fc18.i686 root=UUID=5831c69e-e9fd-4f61-812a-ebb9207c1155 rd.md=0 rd.lvm=0 rd.dm=0 rd.luks=0 rhgb quiet vga=791
initrd (hd0,1)/boot/initramfs-3.9.9-201.fc18.i686.img

title Switch to GRUB2 core.img for booting Linux (Ubuntu, Fedora etc)
set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul
clear
echo Please wait, searching for GRUB2 core img...
set IMGF=0
find --set-root --ignore-floppies --ignore-cd /boot/grub2/i386-pc/core.img > nul && set IMGF=1 && kernel /boot/grub2/i386-pc/core.img && boot
if "%IMGF%"=="0" find --set-root --ignore-floppies --ignore-cd /boot/grub/i386-pc/core.img > nul && set IMGF=1 && kernel /boot/grub/i386-pc/core.img && boot
if "%IMGF%"=="0" clear && echo GRUB2 core img not found! Returning to main menu... && pause --wait=5
configfile

title
root

title Start an antivirus rescue disk
set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul
configfile /antivirus.lst

title
root

title ^B Find bootable Windows NT/2000/XP/Vista/7/8 partitions (B)
set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul
call /findbwin.g4b.gz
configfile

title
root

title Windows XP SP3 x86 setup
map --unmap=0:0xff
map --unhook && map --rehook
set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul
ls /usbdrive.tag > nul || find --set-root --devices=hf /usbdrive.tag
configfile /winxpsetup.lst

title Windows 7 SP1 setup
map --unmap=0:0xff
map --unhook && map --rehook
set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul
ls /usbdrive.tag > nul || find --set-root --devices=hf /usbdrive.tag
configfile /win7setup.lst

title
root

title ^S Shutdown (S)
halt

title ^R Reboot (R)
reboot

initialize.g4b:

!BAT
timeout 30 && /hotkey > nul
color black/cyan yellow/cyan > nul
set PLOPDRV=False && cat --hex --locate="PoLPu@" --number=1 (md)0x3d0+0x130 > nul && set PLOPDRV=True
set USB2DRV=False
set /a USBDRN=*0x8351 & 0xff > nul
if not "%USBDRN%"=="0" set USB2DRV=True
set LDUSBDRV=False
set MAINRAN=1 && graphicsmode -1 640:800 480:600 24:32 > nul

cat --length=3 --skip=0 --number=1 /menucfg | set NTS=
set /a DefMenu=10*%NTS:~0,1%+%NTS:~1,1% > nul
if not "%NTS:~2,1%"=="1" goto :end
set LDUSBDRV=True
if "%USB2DRV%"=="False" usb --init
set /a USBDRN=*0x8351 & 0xff > nul
if not "%USBDRN%"=="0" set USB2DRV=True
:end

usb2load.lst:

timeout 30
default 2
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu% > nul
if "%NTS%"=="0" set NTS=0%DefMenu% > nul

title ...Back to Main Menu
write --offset=0 (bd)/menucfg %NTS% > nul
configfile /menu.lst

title
root

iftitle [if "%LDUSBDRV%"=="False"] Enable USB 2.0 internal driver automatic loading all sessions
clear
write --offset=0 (bd)/menucfg %NTS%1 > nul
if "%USB2DRV%"=="True" set LDUSBDRV=True && echo -e USB 2.0 internal driver automatic loading enabled
if "%USB2DRV%"=="False" usb --init && set /a USBDRN=*0x8351 & 0xff > nul ;; if "%USB2DRV%"=="False" if not "%USBDRN%"=="0" set USB2DRV=True && set LDUSBDRV=True && echo -e \r\nUSB 2.0 internal driver automatic loading enabled
echo -e Returning to main menu...
pause --wait=5
configfile /menu.lst

iftitle [if "%LDUSBDRV%"=="True"] Disable USB 2.0 internal driver automatic loading all sessions
clear
write --offset=0 (bd)/menucfg %NTS%0 > nul
set LDUSBDRV=False > nul && echo -e USB 2.0 internal driver automatic loading disabled\r\nReturning to main menu...
pause --wait=5
configfile /menu.lst

iftitle [if "%USB2DRV%"=="False"] Just enable USB 2.0 internal driver this session
clear
usb --init
set /a USBDRN=*0x8351 & 0xff > nul
if not "%USBDRN%"=="0" set USB2DRV=True
echo -e \r\nReturning to main menu...
pause --wait=5
configfile /menu.lst

Btw, here I used the slow iftitle's because I rarely use this menu (it's loading the USB driver automatically).

The rest of the files: Attached File  Files.7z   7.59KB   435 downloads

1. As you can see, in menu.lst I'm not using the savedefault function anymore. I made some custom code:

set /a DefMenu=*0x8276&0xff > nul
set /a NTS=%DefMenu%/10 > nul
if not "%NTS%"=="0" set NTS=%DefMenu%
if "%NTS%"=="0" set NTS=0%DefMenu%
if "%PLOPDRV%"=="False" write --offset=0 (bd)/menucfg %NTS% > nul

In the same file (menucdfg) I save 0/1 in the third position to enable/disable the automatic loading of the USB 2.0 internal driver.

If DefMenu is in 0..9, a '0' is added in front so it would always be saved as 2 chars.
Question: is there a simpler way to do this?

2. The USB 2.0 internal driver detection code:

set USB2DRV=False
set /a USBDRN=*0x8351 & 0xff > nul
if not "%USBDRN%"=="0" set USB2DRV=True

Seems to work fine.
But there is a problem: if Grub4DOS is reloaded without restarting the computer, the USB 2.0 driver is still active but this code sets USB2DRV to False.
Is there a way to modify the code to work fine in this situation too?

3. The code for loading configuration from menucfg:

set LDUSBDRV=False
cat --length=3 --skip=0 --number=1 /menucfg | set NTS=
set /a DefMenu=10*%NTS:~0,1%+%NTS:~1,1% > nul
if not "%NTS:~2,1%"=="1" goto :end
set LDUSBDRV=True
if "%USB2DRV%"=="False" usb --init
set /a USBDRN=*0x8351 & 0xff > nul
if not "%USBDRN%"=="0" set USB2DRV=True
:end

Notice the use of "cat" command to read from file into the variable. But this command is slow (about 1 sec on my computer). dd command is a lot faster but when I tried to read from the memory location into the variable it didn't do anything.
Is there a way to use only dd without cat?

Thank you.

Regards,
David

#2 steve6375

steve6375

    Platinum Member

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

Posted 01 December 2014 - 11:09 AM

is this any good?

set /a NTS=*0x8276&0xff > nul ;; if %NTS%<=9 set NTS=0%NTS%

Also not sure if it is any faster but you could save NTS as a batch file

echo -e !BAT\nset NTS=%NTS% > (bd)/menu.cfg

and then retrieve the value using

call (bd)/menu.cfg

You could add on the USBdrive value or any other parameter too

echo -e !BAT\nset NTS=%NTS%\nset USBD=%USBD% > (bd)/menu.cfg


#3 DavidB

DavidB

    Silver Member

  • Developer
  • 611 posts

Posted 01 December 2014 - 12:21 PM

Thank you.

 

is this any good?

 

set /a NTS=*0x8276&0xff > nul ;; if %NTS%<=9 set NTS=0%NTS%

 

Yes, it is :)

But I have to assign the value also to DefMenu (used when menu.lst is reloaded).

But I just got an idea and tested something: "default 07", "default 007" and so on work the same way as "default 7" (good job, chenall :) )

So I can use DefMenu variable directly.

 

Btw, in Grub4DOS 0.46a is there any internal variable or command to get the number of the menu entry you're in (not the selected 0x8276)? Because when you use a key combination created with hotkey the menu entry is started but not selected.

In the current implementation you could save some undesirable menu entries like Shutdown or Reboot :rolleyes:

 

 

 

Also not sure if it is any faster but you could save NTS as a batch file



echo -e !BAT\nset NTS=%NTS% > (bd)/menu.cfg

and then retrieve the value using



call (bd)/menu.cfg

You could add on the USBdrive value or any other parameter too



echo -e !BAT\nset NTS=%NTS%\nset USBD=%USBD% > (bd)/menu.cfg

 

In theory it should not be faster. But, in the few years I'm using Grub4DOS, I learned I should test instead of trusting only the theory   :rolleyes:  :hammer:



#4 DavidB

DavidB

    Silver Member

  • Developer
  • 611 posts

Posted 01 December 2014 - 02:44 PM

I tested and it's about the same time.

But I noticed something else: if I test with a 40 bytes bat file or with a 1000 Bytes it's no difference. It means the problem is not in the reading speed of the file, even with 800 KB/s in USB 1.1 it should be a lot faster.
I think most of the time is spent waiting for informations about the file location or searching for the location of the file on disk.
I wonder where the problem could be: in the USB drive controller, the computer BIOS or in Grub4DOS...



#5 steve6375

steve6375

    Platinum Member

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

Posted 01 December 2014 - 03:07 PM

yes, the test I included in E2B - Utilities menu, measures the time for 100 loops  of just using the ls command on a file.

The time this takes to execute varies considerable with different systems.

I also noticed that  running it on an NTFS system took twice as long as when run on a FAT32 system.

It should be a LOT faster with the grub4dos USB driver.

 

I think that maybe the BIOS code uses polling rather than interrupts - some seem to be incredibly slow.



#6 DavidB

DavidB

    Silver Member

  • Developer
  • 611 posts

Posted 01 December 2014 - 04:22 PM

Yes, the BIOS seems to be the most probable cause.

I'm thinking of loading the menu.lst into RAM using the preset-menu and starting it from there.
I noticed that it doesn't cache the menu.lst, it reads it directly from the drive when you start a menu entry.
From RAM it should be processed faster. For example it could be loaded at (md)0x19000 and started with "configfile (md)0x19000".



#7 DavidB

DavidB

    Silver Member

  • Developer
  • 611 posts

Posted 02 December 2014 - 08:49 AM

I loaded and started menu.lst into/from RAM + more.
Now it's loading faster :)

preset-menu.lst from grldr:
 



cat --length=8192 /mainmenu > (md)0x19000+16
configfile (md)0x19000+16

Now I'm not using any *default file + I'm not using menucfg also. All settings are saved and loaded directly into menu.lst file (now renamed "mainmenu").

mainmenu:
 



;02103050502
if not "%MAINRAN%"=="1" call /initialize.g4b
default %MNDEFMNU%

title ^U USB 2.0 internal driver (U)
set MNDEFMNU=00
configfile /usb2load.lst

title
root

title Ultimate BootCD 5.33
set MNDEFMNU=02
if "%PLOPDRV%"=="False" write --offset=1 (bd)/mainmenu %MNDEFMNU% > nul
configfile /ubcd/menus/grub4dos/main.lst

title Memtest 5.01
set MNDEFMNU=03
if "%PLOPDRV%"=="False" write --offset=1 (bd)/mainmenu %MNDEFMNU% > nul
map /iso/memtest.img (fd0)||map --mem /iso/memtest.img (fd0)
map --hook
chainloader (fd0)+1
rootnoverify (fd0)
map --floppies=1

title Paragon Backup & Recovery CD
set MNDEFMNU=04
if "%PLOPDRV%"=="False" write --offset=1 (bd)/mainmenu %MNDEFMNU% > nul
map /iso/Paragon_BootCD.iso (0xFF)||map --mem /iso/Paragon_BootCD.iso (0xFF)
map --hook
root (0xFF)
chainloader (0xFF)

title ^P Paragon Backup & Recovery CD 2nd way (P)
set MNDEFMNU=05
if "%PLOPDRV%"=="False" write --offset=1 (bd)/mainmenu %MNDEFMNU% > nul
map /iso/Paragon_BootCD.iso (0xFF)||map --mem /iso/Paragon_BootCD.iso (0xFF)
map --hook
root (0xff)
kernel /VMLINUZP vga=0x314
initrd /INITRD.GZ

title ^M MiniTool Partition Wizard (M)
set MNDEFMNU=06
if "%PLOPDRV%"=="False" write --offset=1 (bd)/mainmenu %MNDEFMNU% > nul
map /iso/MiniTool_Partition_Wizard.iso (0xFF)||map --mem /iso/MiniTool_Partition_Wizard.iso (0xFF)
map --hook
root (0xFF)
chainloader (0xFF)

title gparted 0.20.0 live
set MNDEFMNU=07
if "%PLOPDRV%"=="False" write --offset=1 (bd)/mainmenu %MNDEFMNU% > nul
map /iso/gparted-live-0.20.0-2-i486.iso (0xff) || map --mem /iso/gparted-live-0.20.0-2-i486.iso (0xff)
map --hook
root (0xff)
kernel /live/vmlinuz boot=live config union=aufs noswap noprompt vga=788 ip=frommedia findiso=/iso/gparted-live-0.20.0-2-i486.iso toram=filesystem.squashfs
initrd /live/initrd.img

title Parted Magic
set MNDEFMNU=08
if "%PLOPDRV%"=="False" write --offset=1 (bd)/mainmenu %MNDEFMNU% > nul
map /iso/pmagic_2014_09_29.iso (0xff) || map --mem /iso/pmagic_2014_09_29.iso (0xff)
map --hook
root (0xff)
kernel /pmagic/bzImage edd=off load_ramdisk=1 prompt_ramdisk=0 rw vga=normal sleep=10 loglevel=0 max_loop=256 vmalloc=384MiB keymap=us iso_filename=/iso/pmagic_2014_09_29.iso
initrd /pmagic/initrd.img

title PartitionGuru 462 FreeDOS
set MNDEFMNU=09
if "%PLOPDRV%"=="False" write --offset=1 (bd)/mainmenu %MNDEFMNU% > nul
map --mem /iso/PartitionGuru462FreeDOS.img.gz (fd0)
map --hook
root (fd0)
chainloader /kernel.sys

title SystemRescueCd
set MNDEFMNU=10
if "%PLOPDRV%"=="False" write --offset=1 (bd)/mainmenu %MNDEFMNU% > nul
kernel /sysrcd/rescue32 subdir=sysrcd setkmap=us
initrd /sysrcd/initram.igz

title
root

title Knoppix LiveCD
set MNDEFMNU=12
configfile /KNOPPIX/knoppix.lst

title ^F Start installed Fedora 18 on USB drive (F)
set MNDEFMNU=13
if "%PLOPDRV%"=="False" write --offset=1 (bd)/mainmenu %MNDEFMNU% > nul
kernel (hd0,1)/boot/vmlinuz-3.9.9-201.fc18.i686 root=UUID=5831c69e-e9fd-4f61-812a-ebb9207c1155 rd.md=0 rd.lvm=0 rd.dm=0 rd.luks=0 rhgb quiet vga=791
initrd (hd0,1)/boot/initramfs-3.9.9-201.fc18.i686.img

title Switch to GRUB2 core.img for booting Linux (Ubuntu, Fedora etc)
set MNDEFMNU=14
if "%PLOPDRV%"=="False" write --offset=1 (bd)/mainmenu %MNDEFMNU% > nul
clear
echo Please wait, searching for GRUB2 core img...
set IMGF=0
find --set-root --ignore-floppies --ignore-cd /boot/grub2/i386-pc/core.img > nul && set IMGF=1 && kernel /boot/grub2/i386-pc/core.img && boot
if "%IMGF%"=="0" find --set-root --ignore-floppies --ignore-cd /boot/grub/i386-pc/core.img > nul && set IMGF=1 && kernel /boot/grub/i386-pc/core.img && boot
if "%IMGF%"=="0" clear && echo GRUB2 core img not found! Returning to main menu... && pause --wait=5
configfile %MAINMENU%

title
root

title Start an antivirus rescue disk
set MNDEFMNU=16
if "%PLOPDRV%"=="False" write --offset=1 (bd)/mainmenu %MNDEFMNU% > nul
configfile /antivirus.lst

title
root

title ^B Find bootable Windows NT/2000/XP/Vista/7/8 partitions (B)
set MNDEFMNU=18
if "%PLOPDRV%"=="False" write --offset=1 (bd)/mainmenu %MNDEFMNU% > nul
call /findbwin.g4b
configfile %MAINMENU%

title
root

title Windows XP SP3 x86 setup
map --unmap=0:0xff
map --unhook && map --rehook
set MNDEFMNU=20
if "%PLOPDRV%"=="False" write --offset=1 (bd)/mainmenu %MNDEFMNU% > nul
ls /usbdrive.tag > nul || find --set-root --devices=hf /usbdrive.tag
configfile /winxpsetup.lst

title Windows 7 SP1 setup
map --unmap=0:0xff
map --unhook && map --rehook
set MNDEFMNU=21
if "%PLOPDRV%"=="False" write --offset=1 (bd)/mainmenu %MNDEFMNU% > nul
ls /usbdrive.tag > nul || find --set-root --devices=hf /usbdrive.tag
configfile /win7setup.lst

title
root

title ^S Shutdown (S)
halt

title ^R Reboot (R)
reboot

As you can see in the beginning of the file there is ";02103050502". 02 = position in main menu, 1 = load USB internal driver, 03/05/05/02 = positions in other menu files.

initialize.g4b:
 



!BAT
timeout 30 && /hotkey > nul
color black/cyan yellow/cyan > nul
set MAINMENU=(md)0x19000+16
set PLOPDRV=False && cat --hex --locate="PoLPu@" --number=1 (md)0x3d0+0x130 > nul && set PLOPDRV=True
set USB2DRV=False
set /a USBDRN=*0x8351 & 0xff > nul
if not "%USBDRN%"=="0" set USB2DRV=True
set LDUSBDRV=0
set MAINRAN=1 && graphicsmode -1 640:800 480:600 24:32 > nul

cat --length=11 --skip=1 --number=1 %MAINMENU% | set NTS=
set MNDEFMNU=%NTS:~0,2%
set LDUSBDRV=%NTS:~2,1%
set KNDEFMNU=%NTS:~3,2%
set AVDEFMNU=%NTS:~5,2%
set XPDEFMNU=%NTS:~7,2%
set W7DEFMNU=%NTS:~9,2%
if not "%LDUSBDRV%"=="1" goto :end
if "%USB2DRV%"=="False" usb --init
set /a USBDRN=*0x8351&0xff > nul
if not "%USBDRN%"=="0" set USB2DRV=True
:end

The rest of the files: Attached File  files.7z   151.8KB   427 downloads

Questions:

1. Is there a simpler and/or faster way to get those 6 variables from (md)190000+16 (instead of "cat --length=11 --skip=1 --number=1 %MAINMENU% | set NTS=")?
2. I used a batch file for initialization (initialize.g4b) because the code was simpler and better (in lst I had to use a lot of if's + goto's don't work).
Is there a way to get the code back into the menu.lst (mainmenu file) but without losing the simplicity or functionality...?



#8 DavidB

DavidB

    Silver Member

  • Developer
  • 611 posts

Posted 02 December 2014 - 01:14 PM

Just noticed something: the modifications made to memory seems to be local on each menu entry.
For example, if I use this code in a menu entry:
cat --length=2048 /usb2load.lst > (md)0x19010+4
configfile (md)0x19010+4
The menu is loaded but when I load again the main menu and try again "configfile (md)0x19010+4", it's not loading. I looked at the memory location, only 0's.
However, if I use "cat --length=2048 /usb2load.lst > (md)0x19010+4" into the code before menu entries, it works.

Is there a way, beside using "cat --length=2048 /usb2load.lst > (md)0x19010+4" into the code before menu entries, to make the changes to memory permanent?



#9 steve6375

steve6375

    Platinum Member

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

Posted 02 December 2014 - 01:26 PM

Your mainmenu is loaded into (md)19000+16

You other menu is at 19010+4

 

So if you main menu is larger than 0x10*512bytes = 8K then it will overwrite (md)0x19010.

 

Could this be something to do with it?



#10 DavidB

DavidB

    Silver Member

  • Developer
  • 611 posts

Posted 02 December 2014 - 01:30 PM

No, because the main menu is actually smaller than 10 (x512).

But I tried with 19050 in the menu entry, even with 20000, same problem.



#11 steve6375

steve6375

    Platinum Member

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

Posted 02 December 2014 - 01:38 PM

cat --length=1  /mainmenu > (md)0x1900+20  will zero all 20 sectors.

but using 19000 and 20000 should work???



#12 DavidB

DavidB

    Silver Member

  • Developer
  • 611 posts

Posted 02 December 2014 - 01:43 PM

cat --length=1  /mainmenu > (md)0x1900+20  will zero all 20 sectors.

 

Yes, but I'm not using this command when I load again the main menu. I just use "configfile (md)0x19000+16". So the sectors will not be zeroed.

 

but using 19000 and 20000 should work???

 

Yes, it should, but it doesn't...



#13 steve6375

steve6375

    Platinum Member

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

Posted 02 December 2014 - 02:03 PM

Can you provide simplified example?

Are you using latest grub4dos 0.4.5c?



#14 DavidB

DavidB

    Silver Member

  • Developer
  • 611 posts

Posted 02 December 2014 - 02:15 PM

I'm using 0.46a.

I'll try to make a simplified example...

 

LE:

 

menu.lst:



if not "%MAINRAN%"=="1" set TESTMNU=False && set MAINRAN=1

title Test menu
if "%TESTMNU%"=="False" cat --length=2048 /testmenu.lst > (md)0x19030+4 && set TESTMNU=True
configfile (md)0x19030+4

testmenu.lst:





title ...Back to Main Menu
configfile /menu.lst

title
root


Btw, it does the same with 0.45c.



#15 steve6375

steve6375

    Platinum Member

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

Posted 02 December 2014 - 02:48 PM

try

 

if "%TESTMNU%"=="False" && cat --length=2048 /testmenu.lst > (md)0x19030+4 && set TESTMNU=True



#16 DavidB

DavidB

    Silver Member

  • Developer
  • 611 posts

Posted 02 December 2014 - 03:03 PM

It works now, but I don't know WHY it works... :frusty:

That && shouldn't be there...  :confused1:



#17 steve6375

steve6375

    Platinum Member

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

Posted 02 December 2014 - 03:27 PM

I think is a similar situation in a Windows shell

 

e.g.

 

set F=0

if "%F%"=="1" echo fred > x.txt

 

this either clears x.txt or puts fred in it

 

The redirection symbol is evaluated first and a pipe/handle opened even though the logic will never execute the preceding statement.



#18 DavidB

DavidB

    Silver Member

  • Developer
  • 611 posts

Posted 02 December 2014 - 03:50 PM

A sort of if/then/else  :dubbio:



#19 steve6375

steve6375

    Platinum Member

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

Posted 02 December 2014 - 03:55 PM

I think it is a parsing thing

 

e.g.

 

if (something) then myfile.exe > nul

 

To parse this the shell needs to know where to redirect any output from any command, so it looks for > and >>  (and probably | and & and (  ) first.

Once it knows where to redirect output to, it can start to execute the command(s).

 

so 

if (1=2) echo fred > 1.txt

will always open a handle to 1.txt, if the line fails to execute, the handle will be closed and the file will be empty.



#20 DavidB

DavidB

    Silver Member

  • Developer
  • 611 posts

Posted 02 December 2014 - 04:04 PM

I understand.

Thank you for help :)

 

With this code the additional menus will be loaded faster like the main menu.



#21 Wonko the Sane

Wonko the Sane

    The Finder

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

Posted 02 December 2014 - 05:04 PM

Just for the record.
Try (on NT system):
set F=0
if "%F%"=="1" echo fred > x.txt
and:
set F=0
>x.txt if "%F%"=="1" echo fred
the latter is THE SAME, but written differently, sometimes it is more clear to use this latter syntax.
See note (3) here:
http://www.robvander...redirection.php
Redirection is a "strange beast" :w00t:

:duff:
Wonko

#22 DavidB

DavidB

    Silver Member

  • Developer
  • 611 posts

Posted 02 December 2014 - 06:20 PM

Thank you, Wonko.



#23 DavidB

DavidB

    Silver Member

  • Developer
  • 611 posts

Posted 18 December 2014 - 04:40 PM

As you know, when remapping the (bd) partition or the drive with the (bd) partition, (bd) will not point to the "boot device" anymore.
http://code.google.c...es/detail?id=30
There is a way to find it: copy usbdrive.tag file in the root of (bd) and use "ls /usbdrive.tag || find --set-root --devices=hf /usbdrive.tag".
But it's slow and it's not exactly what I need: an absolute path to any file/folder from (bd). For example, if I'm on another partition and want to read/write from/in a file on (bd), with an absolute path I can do it without setting root to (bd).

Is there a better way...?



#24 steve6375

steve6375

    Platinum Member

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

Posted 18 December 2014 - 06:12 PM

If the initial boot device is say (hd0,0) and then you map hd0 to hd1 and map hd1 to hd0 and then map --hook, (bd) will still be remembered as hd0,0 - so if you know that hd0 is now hd1, why not just access (hd1,0)/file.xxx instead of (bd).?



#25 DavidB

DavidB

    Silver Member

  • Developer
  • 611 posts

Posted 18 December 2014 - 06:30 PM

In a simple situation like you described, yes, it's logical to use (hd1,0) instead of (bd).
But after using much complex code on an unknown computer configuration, it's not always easy to know which is the boot device.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users