However, there is a way to automatically show only valid menu entries in a grub4dos menu. We can make grub4dos look for the 'payload' file and only list the menu entry if the payload file exists. Once you have set up your grub4dos menu, you can simply add or delete any ISO/IMG/IMA/WIM file from the USB drive and the menu entry for that file will automatically appear or disappear the next time you boot from the USB drive. Any grub4dos bootable USB drive you make in future can simply have your full menu copied to it, but it will only list menu entries for the files that exist on the USB drive. The way to do this is to use the iftitle command (2012 grub4dos versions or later, or use latest version of RMPrepUSB to install grub4dos) which can be used to check for the existence of the payload file, for example: iftitle [if exist (bd)/test.img] find /test.img on any drive and boot to it map --mem (bd)/test.img (fd0) map --hook chainloader (fd0)+1 The latest chenall build of grub4dos (in latest RMPrepUSB) has the new command iftitle. Now you can make your menu.lst easily without needing any extra lines of code. Use RMPrepUSB and the Install grub4dos button. Here are some examples for the new iftitle command and also a patch to make the grub4dos menu automatically number itself:
iftitle [if exist (hd0,0)/test.img] boot to (hd0,0)/test.img Beware: the syntax if very fussy - you must not have any white space immediately after the [ or before the ] brackets! If a command returns <false> you can check the results using checkrange iftitle [checkrange 0x01:0xff hiddenflag (hd0,0)] ptn 0 is hidden root () iftitle [checkrange 0x0 hiddenflag (hd0,0)] ptn 0 is unhidden root () iftitle [checkrange 0x01:0xff hiddenflag (hd0,1)] ptn 1 is hidden root () iftitle [checkrange 0x0 hiddenflag (hd0,1)] ptn 1 is unhidden root () The auto-number patch (write 0x8274 aabb line), can be used to auto-number all menu entries, however, all title commands will be numbered, even blank ones - e.g.
will appear when you boot to grub4dos as
The latest chenall build of grub4dos can be used with a new 'hotkey' executable to enable the user to use hotkeys such as F1 or CTRL+F1 to pick a menu entry. Then download the file 'hotkey.zip' from the grubutils download page here and extract the file hotkey and place it on the USB drive also. Now you can add hotkeys to your menu as follows: ## run the hotkey command
The menu presented to the user will look like this (if bootmgr is present on a hard disk device):
Press F2 to Boot Windows from hard disk Note that the ^F1 portion of the menu text is not displayed if 'hotkey' has been loaded (but it will be displayed if hotkey has not been loaded and hotkeys will not work).
If the user presses F1 the first menu entry will immediately run. If you use hotkey -nc then pressing F1 will only select the first menu entry but will not run it until the user hits {Enter}. Note: GFXMenu does not support hotkeys and so will display the complete title entry - e.g. ^R Reboot AutobootIf you want to automatically boot from a USB drive depending on what boot file you have on your USB key, you can do it like this (you must have the file default in the root of the drive - this special file can be downloaded from the Beta Downloads page)
Suppress grub4dos startup/bootup messages (silent)grub4dos (grldr) echoes some debug messages to the screen on startup as it boots, which you may not want the user to see. They can be patched out by using a grub4dos batch file. Run this patchg4d.g4b batch file at the start of your menu.lst - it will automatically make the code patches to blank out the messages the first time it is run. It only needs to be run once (on a real system, not QEMU) for the patch to take affect. e.g.
Splash Screen Only (no menu on boot)The user will just see the wallpaper image with no text or highlight line at all - if he presses F4 or F5 then the menu entry chosen will be executed immediately. Cut and paste the lines so that you get the correct number of spaces!
Only boot grub4dos if hotkey pressedYou can install grub4dos using grubinst.exe so that grldr and the grub4dos menu will only be loaded if a hotkey is pressed by the used. A (modified) copy of grubinst.exe is used by RMPrepUSB and can be found in the RMPrepUSB installation folder (press F3 to view the installation folder in Explorer). Here is what the user will see when grub4dos is installed in this way: 1. Reboot or Switch on the computer 2. Normal PC startup screen appears 3. grub4dos stage 1 bootloader will run and this message will be displayed on the screen:
4. The timeout will count down to 0 seconds (unless F10 is pressed) and then will boot from the boot disk as normal (using the bootloader that was on the drive before grub4dos was installed). If F10 is pressed, then the grldr stage 2 file is loaded which will look for your menu.lst file and load it and display the grub4dos menu. The command line to install grub4dos in this way to your drive (assuming your drive is hd2 and you want a 3 second timeout) is:
Some Scan codes you can use are:
Note: It is best to avoid using F12 or F11 as these often do not work on some models of Notebooks due to non-standard notebook keyboards. All the command line switches for grubinst.exe can be found here. To change the message, boot from the disk to grub4dos and use the following grub4dos patch command from the grub4dos command shell.
Note that the --replace string must not be longer than 53 characters or you will corrupt the boot code! If you want to entirely suppress the 'Press F10 to start...' message and the Timeout message and just have the 3..2..1..0 countdown displayed, the following grub4dos commands will patch the disk that grub4dos is installed on, to suppress these messages (omit !BAT if you are typing this into the console):
You can make this into a text batch file - e.g. nomsg.g4b, by keeping the first line of text "!BAT" , and then run the batch file from the command line by typing /nomsg.g4b. NOTE: THE CONTENT BELOW IS OUTDATED! The Methods below are deprecated. The new grub4dos iftitle command makes these workarounds no longer necessary! They are included for the interested reader only! NOTE: PLEASE USE THE LATEST CHENALL BUILD GRUB4DOS VERSION (also included with the latest RMPrepUSB download)
Note: Method 2 uses two menu files (menu.lst and main.lst) and allows you to expand the scheme so that you could modify more than one menu file (e.g. you can have main.lst which would load either main1.lst, main2.lst, main3.lst, etc.). This is useful if your menu system uses multiple menu files. If you only use one menu.lst file (probably 90% of users!) then you can use just a single self-modifying file (i.e. one menu.lst) as in Method 1.
(OLD) Method 1 - Method using a single MENU.LST file1. Cut and paste the lines in the template example below (up to the # YOUR NORMAL GRUB4DOS MENU GOES HERE position) into your existing menu.lst file (insert at the very top of your menu.lst). The --replace=" " text should have EXACTLY 3 SPACES between the double-quotes.
2. Modify your existing menu entries by adding four-character identifiers (#XX<space>) to the beginning of each of your menu lines as detailed above and as shown in the example menu below.
3. Modify the 'if exist' lines (just below the #PLACE ALL YOUR TEST ENTRIES HERE text) so that they match the identifiers you used in step 2 and match the iso or 'payload' file used by each menu entry.
Alternatively, just use the utility to convert your existing menu.lst
Download the GrubAuto utility to convert your current menu.lst to an 'automated' one!
1. Click on the Load Menu button and select your current menu.lst file
2. Click on Copy To ClipBoard
3. Paste the contents into a new menu.lst file and save it.
Menu.lst template (green text is the original menu text):
How it worksThis menu.lst is self-modifying. It loads itself into memory (1st line) and then comments out the lines that loaded it into memory in the next two lines (otherwise it would loop and continuously keep loading itself into memory!). The self-modification is done by looking for two command lines and then commenting those lines out.
The 'if exist' lines are not commented out, so they will actually run twice and the second time menu.lst is loaded from memory, it will change itself - but it does not matter (except it will take slightly longer to run) because the menu lines will have already been modified when the 'if exist' lines ran the first time!
|
