The GrubUtils utilites can be downloaded from Chenalls site here (this includes wenv, fat, chkpci and other utilities). When running an external grub4dos batch file or utility executable, you need to copy the file to your boot drive and make sure that the path is specified correctly in the menu.lst file, e.g.
will run the file menuset which must exist on the root of the boot drive. menuset is contained in the grubutils package. Note: The default command path for grub4dos is the /boot/grub folder - it is recommended to place all your utilities in /boot/grub on your boot drive so that grub4dos can find them. menuset 0 0 0 0 0 0 10 50 5 29 35 will run the file menuset which must exist in the /boot/grub folder. The alternative is to path each command - e.g. use /bin/wenv instead of just wenv and place the wenv file at /bin. Grub4dos Batch filesGrub4dos can execute a batch file (usually given a .g4b file extension, but sometime it has a .bat extension or no extension - whereas a grub4dos executable file has a .g4e extension or no extension). The grub4dos batch file must begin with !BAT. The syntax to use in the batch file is similar to that in a menu.lst file but not quite the same. For instance when using two variables together, you must use three % signs in a batch file because any two consecutive % signs will be treated as a single % sign in a batch file: test.bat file contents:
in a grub4dos commandline shell, type /test.bat
Note that in a menu.lst file, echo %a%%b% will work and you don't need the extra % sign! So will echo I got 100% tip: If you place all utility and batch files in the /boot/grub folder then grub4dos will find them without needing to specify a path. Also, if you call a grub4dos utility a lot in a batch file (for instance, in a loop or subroutine), then load it into memory first using the command insmod - e.g.
will load wenv into memory so that whenever it is called later (with no path specified) it will run from memory instead of being loaded from the disk each time. Thus using insmod at the start of your batch file to load any utilities into memory will greatly improve the speed of execution! Insmod can also be called from within a menu.lst file and this will increase the speed of execution of grub4dos menus if you call a grub4dos utility within the menu.lst file, as well as any batch files you call afterwards. Use delmod <filename) to unload a file or :
You can also call internal Function calls in a batch file using call Fn.x where x is a number and can be followed by one or more parameters - e.g.:
Here is a batch file to get lines from a text file, one at a time (redirecting bold blue lines will give a perfect copy of the file):
Tip: to get more lines on the console screen, type graphicsmode 179 first. Here is a batch file to search for and list BIOS strings. Save the file to your grub4dos bootable disk as ShowBiosStrings.bat, boot to a grub4dos command prompt and then type:
and see what you get (tip: add insmod %~0 to load the whole batch file into memory and speed it up a lot)!
Another Batch file example - use checkdate.g4b to check an Expiry DateSuppose we release a bootable CD or USB drive which has software on it that should be regularly updated. We want to warn the user when it has expired. We can use a grub4dos batch file to do this and call it from a menu.lst file like this:
This will show the following text when the grub4dos menu runs...
OR
The checkdate.g4b file can be found at the bottom of this page or click here. Note: If you are burning this to a CD or DVD, use an 8.3 filename like chkdate.g4b as checkdate.g4b is too long! Set the System DateUsing the grub4dos Function 53 we can set the Real Time Clock date. The Date.g4b grub4dos batch file can be run to set the date - this might be useful for expiry date sensitive DOS utilities that check the date of the system. run the batchfile from your menu.lst like this
Note that this will permanently change the date of the system Real Time Clock until you set back the correct time. grub4dos variables and setlocal/endlocalCurrently there is a maximum limit of 60 variables and each can be up to 512 bytes each. The batch file VarsLeft.g4b will tell you how many variables remain out of the 60 allowed. It is quite easy to run out if you are not careful! If you reset them (e.g. set A= will remove the variable A from the environment) then you will free up a 'slot for another variable'. You can use setlocal to make a copy of the current environment (e.g. variables, root path, current filespec, etc.). When the endlocal command is run these values are restored and any variables set during the setlocal portion are lost (a copy of the current environment is made when you use setlocal and that copy is restored when you use endlocal). e.g.
If you want to use setlocal, but pass back a variable, you can do it by placing an && set x=y statement on the end of the same line as endlocal - like this:
If you have 30 or so variables already set, then when you use setlocal, you will already have 30 variables set - this uses up the variable space (max. 60 variables can be defined). You can clear the local variables using set * : e.g.
Global variablesgrub4dos currently supports up to two user-definable global variables.?_xxxx and ?_yyyy where xxxx and yyyy can be any user defined name - the first two that are set by the user become global, any more are ignored.
will produce the result: test y Note: set does not list these global variables, nor does set ?_ - you can only see their values if you reference them by name. Note that set * will also delete the global variables setlocal @You can also use the special parameter @ with setlocal, this will preserve all variables after an endlocal is executed, e.g. Note: I am not quite sure why this is useful instead of just not using setlocal?
Produces the output: Another example when mixing setlocal @ with setlocal
Batch files that search sub-foldersFFFName.g4b - FindFullFileName - finds the first file matching a full filename, searches all disk - e.g. /grub/FFName.g4b / explorer.exeFFName.g4b - FindFileName - finds the first file matching a filename (without extension), searches all disk - e.g. /grub/FFName.g4b / explorer FFExt.g4b - FindFileExtension - finds the first file matching a file extension - returns variables - e.g. /grub/FFExt.g4b /_ISO .iso DirFile.g4b - lists all files in a single directory (does not list directories) (e.g. /grub/DirFil.g4b /_ISO DIR (to just list dir names omit DIR)) LstDir.g4b - Lists directory names in a directory (e.g. /grub/LstDir.g4b /_ISO DIR (to just list dir names omit DIR)) LstFExt.g4b - Lists all files in a single folder that match a file extension The names must be kept to 11 characters - otherwise insmod refuses to load it (says filename too long!). Make sure there are no spaces at the end of the line after the filename or this will be counted too! Please download FindFile.zip to obtain these batch files. The batch file LFExt.g4b lists all files in a single speciified folder (and not below - this has been suppressed in the batch file) that match a specified extension, e.g. /LFExt.g4b /_ISO/Linux .iso will list all ISO files e.g.:
Wenv (available on Beta downloads page) is a grub4dos utility (a program - see grubutils section below) that you can run under the grub4dos environment. It is just like an executable that you would run under DOS (e.g. find.exe) but it runs under grub4dos. It allows you to use environment variables in your menu.lst files or to run a script file which can execute grub4dos commands. Note: The Wenv download zip file in the Beta Downloads section of this site also includes an English translation of the Chinese text help file for wenv which I have added for you to study.
For instance....
Note that line 2 sets the grub4dos environment variable 'iso' to the path of the ISO file by running the wenv executable with parameters. In line 6 and line 7 we can use this variable value by substituting it with ${iso}. Note that wenv needs to have a full path as grub4dos needs to find the wenv file which is in the /ImDisk folder in this example. Also note that to use environment variables and wenv with grub4dos commands, we need to 'call' the grub4dos command, this why lines 6 and 7 start with '/ImDisk/wenv call' If you copy the grub4dos executable file wenv (latest version available on grubutils download page) to the USB drive /ImDisk folder, you can make the menu.lst easier to edit and add more ISO files. SET to set/change/add/delete/display variables - for a substring use :~start,length - e.g. set a = %xyz:~10,2%%%xyz:~13,2% (note you need to add another % when two %% signs are used together!) GET display variable/variables and get length of the variable in ?_GET internal variable FOR similar to the windows shell FOR cmd instruction CALC simple calculator (priority from left to right, does not support brackets) ECHO Display a message or variable to the screen READ a file and run the commands inside - similar to a .cmd batch file (must use WENV supported commands) also supports parameters. CHECK check if an equation is true or false, if it returns true a command can be executed RESET clear/reset a variable CALL call the grub4dos shell to execute a grub4dos command Note: SET, GET, FOR, RESET, CALC and ECHO are largely redundant now as similar functions are built into the latest grub4dos versions from chenall (included in RMPrepUSB). For instance, if you type /wenv set in the grub4dos command console window, then wenv will display all current grub4dos environment variables. Here is another example of how you can use wenv (note: this time wenv is located in the root of the drive and not in the ImDisk folder):
chainloader (0xff)
For an example of how to make a script file which can run under grub4dos (which must begin with the text !BAT), see the file RUN.BAT example included with the wenv.zip download. For an example of a grub4dos batch file that uses wenv to display the MBR partition table of a drive - see jaclaz's/Wonko the Sane's mbrview.g4b batch file on reboot.pro here.
hotkeyAnother grub4dos utility you can run is the 'hotkey' utility which allows the user to use hotkeys (e.g. F1, F2, etc.) to select a menu item and run it (use the latest chenall build of grub4dos) - see Tutorial #57 for details. grubutils'grubutils' is just a name for a collection of individual executable utilities that can run within the grub4dos environment. Grub4dos can call these utilities or execute them from a grub4dos batch file or from within a grub4dos menu.lst. Some of these will list usage syntax if you use -h switch. C sources are here
chkpci - lists PCI devices, use -cc:06 (scan class codes that match PCI class 06) [FILE] PCI database file
diskid (hd0,1) will report Ghost style disk id 1:2
echo - echo's chars, variables, etc. = echo -h will display a colour chart of background/foreground
fat - see below...
fatmini - similar to fat but small size, only supports mkfile, copy and del functions
fontfile - specify a fontfile to load
g4d_off - quit grub4dos!
inifile - see below
mbrcheck (hd1)+1 - checks for a valid mbr (checks a single active ptn table entry, magic bytes, non-overlapping ptns,
menuset - changes menu size and position - useful if using a high resolution background
snake - snake game - use cursor keys to eat the small square
unifont - load a unifont file
unitest - test a fontfile for validity
vbmp - vbmp /small.bmp - displays a small monochrome bmp file (must be mono bmp) see here
vfont - loads a font file??
wenv - work with environment variables - many functions now in grub4dos anyway - see grub4dos tutorial for details
wenv-readme.txt - readme file for wenv usage
fatNote: for obvious reasons, this does not work on NTFS volumes! fat mkfile size=xx filename - create a new file of a certain size (size=* will get size from memory address 0x8290
fat copy file1 file2 - copy contents of file1 to file2
fat ren oldname newname - rename a file or directory
fat dir - list directory contents - e.g. fat dir /iso/app/ or fat dir /a-d /grubut~1/ (lists files but not directories, note shortfilenames 8.3 must be used! d,s,r,h valid attributes)
fat info (disk) - e.g, fat info (hd1,0) - displays info such as FAT start, sectors per cluster, sectors per FAT, free clusters, total clusters, drive free space and size
fat del file or directory (dir must be empty)
fat mkdir newdir
fat mkfs [/A:UNIT-SIZE] DRIVE - creates fat volume on drive, UNIT_SIZE = cluster size in bytes
For fat mkfs to work, the size of the device must be approx greater than 66,000 bytes (depending on if mounted using --mem or not). For example, the following two menu entries fail after echo 0 with FAT Error (1) message...
You can only copy the contents of a file to an existing file, so you must create the target file first (must be same size or bigger).
ExampleHere is a batch file called copyff.bat and a menu.lst which uses the fat utility. It creates a large virtual floppy disk in memory and copies the entire contents from a mapped ISO file into it. It can cope with several 100's of files per folder but will not work on very large folders such as the XP CD's /I386 folder in an XP ISO (unfortunately!). menusetsets the border characters that grub4dos uses to surround a menu and position of menu box and help text.
arguments:
upper left corner border char, upper right corner bordr char, lower left corner char, lower right corner char, horizontal char, vertical char, menubox left pos, menubox width, first line no., height of menu, row position for help text
ul ur ll lr hor ver ml mw 1st hgt hlprow
menuset 218 191 192 217 196 179 2 76 2 21 22
menuset 0 0 0 0 - I sets the horizontal top/bottom char to - and vertical sides to I
menuset 0 0 0 0 0 0 8 60 10 makes a small 9 entry high menu at x,y 8,10
menuset 0 0 0 0 0 0 8 60 10 6 as above but only 6 rows in the menu
menuset 0 0 0 0 0 0 8 60 10 6 1 as above but puts the help text at the top of the menu
menuset resets all back to normal menu chars and position
Example: menuset 0 0 0 0 - I 8 60 10 6 1
Example
sets menu left position to 10, menu width to 50, the first menu item at row 5, 29 items per menu and help text starts at row 35. 1024x768 background with smaller menu In this example the grub4dos version text is not blanked out and there is no menu heading. menusettingIf you require the menu to be past column 78 then menuset will not work correctly. In this case use the menusetting utility as follows:
Note that there is a problem with help text with grub4dos - the help text will only appear up to text column 79 - if you have a menu box after column 79 then no help text will appear at all. The default grub4dos help text will always start a column 0, but any menu help text in your titles can only occupy from the left-hand side of your menu box up to column 79. biosThis utility allows you to make any BIOS call you like. You can setup the registers and which interrupt you want to use, it then makes the BIOS call and prints out the CPU register contents after the call returns, like this:
EAX=00008600 EBX=00000000 ECX=00000000 EDX=00000000 ESI=00000000
EDI=00000000 EBP=00000000 ESP=00006284 EIP=00000000 eFLAG=00000A83
DS=0000 ES=0000 FS=0000 GS=0000 SS=0000 CS=0000 OV UP EI NG NZ NA PO CY
The flag registers are displayed so you can test for the Carry Flag (NC or CY) or Zero flag (NZ or ZR).
This allows you to make any BIOS call (for instance write characters to a certain position on the screen, read a disk sector, etc.).
You can then check these registers by redirecting the output to memory and using cat - e.g. a single line in a grub4dos menu ...
/plpbt/bios int=0x13 eax=0x504c6f50 ebp=0x43484b44 > (md)0x300+1 && cat --locate="EAX=79657320" (md)0x300+1 || pause --wait=3 loading Plop! && kernel /plpbt/plpbt.bin hiddenusb && boot Do not experiment with int13h calls unless you are careful and know what you are doing as they can be dangerous (e.g. could trash your hard disk!). Here is an example to calculate available memory size and use the value in your menus:
To use this in an iftitle [if %MEMSIZE%>=600] to run iso that requires more than 600MB - see reboot.pro here. You must load the menu.lst twice - the first time it runs it calculates MEMSIZE, the next time it runs, the iftitle statements will be able to use the MEMSIZE variable and only display the appropriate menus. Note: The menu line below will also fetch the memory size from an internal grub4dos storage location and put the value into a variable in units of MBs without needing to call the bios utility:
Test for SHIFT key using bios utilityHere is an example of how you can test to see if the SHIFT key is pressed when the user hits Enter to select a menu item. Using these two lines, you can modify the menu commands - for instance, if SHIFT+ENTER is pressed when a menu item is selected, safemode parameters could be used to boot linux rather than normal parameters.
inifileDisplays or modifies a section of an ini file e.g. inifile /dir/dir/oemsetup.inf [AAA] - displays contents of section [AAA]
inifile /dir/dir/oemsetup.inf [AAA] bbbbb=cccccc - adds new entry under section [AAA]
More Examplesinsmod FAT load fat as a module into memory for faster operation - future uses of fat will execute the fat code from memory instead of loading it from disk each time.
insmod INIFILE load inifile as a module into memory
map --floppies=2 set BIOS to recognise 2 floppies
map --mem (md)+5760 (8) map memory as device 8
map --hook hook the mapping so it is active
fat mkfs (8) > nul make a fat filesystem
write --offset=0x18 (8) \x24\0\2 write to the 18th/19th/20th bytes the values 24h 00h and 02h respectively
fat mkfile size=4096 (8)/chkpci.pci make a 4096 byte file on the filesystem and name it chkpci.pci
CHKPCI -u /DRIVERPACK.INI > (8)/chkpci.pci run chkpci and send the matching description of a pci device to the file chkpci.pci
Example of chenalll's grub4dos batch file which autocreates the correct txtsetup.oem for whatever mass storage driver can be found - taken from chenall's DPMS project.
For an example batch script file that dynamically creates a grub4dos menu for Ghost, see QGHO.zip in the attached zip file below. This batch file is taken from chenalls MODBOOT project here (download the ISO) Demo Download: File Name: modboot.iso File Size: 12.05 MB (12,636,160 bytes) Modified: May 3, 2011, 16:18:50 the MD5: E5AE83BF5D517506DED80BA4D2FB12D7 the SHA1: B5879F7C78F772ECFE985EAF1C6302BAD2E96309 Address 1: http://u .115.com/file/f0f3bc7143 Here is the QGHO.bat file contents:
|




