21 - GRUB4DOS GUIDE (with videos) - how to make a multi-boot drive (+examples)

--Unique hits tumblr hit tracking tool

Contents

  1. 1 Introduction to grub4dos
  2. 2 References
  3. 3 Part 1 - Make a bootable USB pen drive
  4. 4 Part 2 - Testing your USB pen drive
    1. 4.1 Grub4dos 'color' values
      1. 4.1.1 Flashing text
    2. 4.2 Grub4dos commands
  5. 5 Setting a background image
    1. 5.1 Low Resolution 14 colour 640x480 bitmaps
      1. 5.1.1 Make your own splashimage 14-colour background file
      2. 5.1.2 14-Colour SplashImage CONVERSION METHOD 1 (highly recommended for all Windows XP/Vista/7 users - just drag and drop to convert!)
    2. 5.2 High colour and High Resolution backgrounds
    3. 5.3 Make a high resolution splashimage file
    4. 5.4 Changing the screen resolution with 'graphicsmode'
    5. 5.5 Changing the menu position and border
    6. 5.6 Changing the text font
    7. 5.7 The font command
    8. 5.8 Setting a default entry and numbering the menu entries
    9. 5.9 Adding your own menu heading
      1. 5.9.1 Using the echo command
      2. 5.9.2 More about menu entries and numbering
      3. 5.9.3 Numbering menu entries
      4. 5.9.4 Suppress grub4dos startup/bootup messages (silent)
      5. 5.9.5 Password protection
    10. 5.10 Secret menus
  6. 6 Part 3 - Adding a graphical menu using GFXBoot/GFXMenu
    1. 6.1 Using GfxMenu
  7. 7 Part 4 - Understanding grub4dos commands
    1. 7.1 The map command
      1. 7.1.1 The map command continued...
      2. 7.1.2 Booting DOS from a USB Floppy
    2. 7.2 The hook command
    3. 7.3 The root, kernel, chainloader and other commands
      1. 7.3.1 Contiguous files
    4. 7.4 Multiple sub-menus
    5. 7.5 grub4dos memory and ramdrives
    6. 7.6 Using variables in grub4dos menus
    7. 7.7 The cat command
    8. 7.8 Automatically show only valid menu entries using iftitle
  8. 8 Part 5 - Troubleshooting grub4dos menus
    1. 8.1 Debugging
      1. 8.1.1 Booting from CD or accessing a CD
      2. 8.1.2 Booting older OS's
      3. 8.1.3 Single-Stepping
      4. 8.1.4 Screen Capture
    2. 8.2 Checking what devices are present
    3. 8.3 Slow or no USB booting on some systems?
      1. 8.3.1 PLOP
  9. 9 Grub4dos utilities
    1. 9.1 WENV
    2. 9.2 hotkey
    3. 9.3 Using dd to edit sectors
  10. 10 grub4dos internal variables and functions
  11. 11 Over to you!
    1. 11.1 checktime command
    2. 11.2 terminal command
    3. 11.3 setmenu
  12. 12 Part 6 - Tested menu.lst entry examples




















This guide contains many new and previously undocumented features!

Latest grub4dos downloads (GitHub source here) 0.4.5c is latest (a=alpha, b=beta, c=release) I recommend 0.4.6a 2015-06-05 as a good version to use (many versions have bugs!)

0.4.6a has Joliet ISO support, can map non-contiguous files, better debugging and it's own rd/wr USB 2.0 driver and better NTFS file-write support.

  • Grub4dos Commands Primer by Stephenldj (translated from Chinese)
  • Tutorial 71 - Grub4dos utilities (Wenv, hotkey. bios, etc.)
  • Grub4dos internal variables and Functions
  • Grub4dos and Plop!
  • Lots of menu.lst examples.
  • Sample background menus here.
  • Tutorial 57 - Automatic grub4dos menus, using hotkeys, hiding the menu and silent startup
  • Look here for advanced example menus and downloads including unifont to support UTF.8 characters, wallpapers, moving the menu, coloured text, etc.
  • Click here for a complete set of RMPrepUSB and grub4dos tutorials.

    Use the Search box at the top of this page to find a grub4dos menu for your particular ISO/OS/App.
    RMPrepUSB Blog - please leave a comment or feedback on RMPrepUSB or this Tutorial (please mention Tutorial number).

    Introduction to grub4dos

    Please note: some versions of grub4dos have bugs (especially many 201409xx and 201410xx versions are buggy!) - I recommend 0.4.6a 2015-06-05 as a good version to use for testing. 0.4.6a is quite stable now and has more features and bug-fixes than 0.4.5c. The 'latest' version often has bugs too!

    This tutorial is an introduction on how to make a bootable grub4dos USB drive

    If you are a beginner to multibooting USB drives and just want to quickly make and test a multiboot drive, check out the Easy2Boot Tutorial here.
    Grub4dos allows you to make a multiboot (multipass) drive. When you boot from a bootable drive that contains the grub4dos bootloader, you are normally presented with a menu which allows you to boot from any OS or other program such as a memory test program that you have copied to the drive.

    Grub4dos boot code can be installed either onto the MBR (Master Boot Record, on the first sector of the disk) and boot track (first track) of a drive, or the partition boot record. It consists of two parts or stages. The first part is the boot code which is in the first sector and some of the following sectors of the boot drive or partition. Once this code is run by the CPU, the code then looks for a file called grldr. The grldr file needs be in the root and on the same boot partition if the boot code is installed onto the partition boot record (PBR - start of the partition), if the boot code was installed onto the MBR, then the root of all devices will be searched to find the grldr file. See here for more details.

    Grub4dos can boot an OS or executable from a 'flat file' structure or from disk image files or even ISO files. It can even load images into memory (ram drive) and run the OS from there! Grub4dos is used in most of my tutorials and is well worth getting to know it, if you are interested in making your own multi-boot drives. The RMPrepUSB download includes grub4dos. RMPrepUSB will install grub4dos onto a drive at the click of a button either to the MBR (Master Boot Record) or PBR (Partition Boot Record). Tip: If in doubt, always install twice, to both MBR and PBR!

    Most of the tutorials on this website use grub4dos. Grub4dos can be installed onto a USB Flash drive, USB Hard Disk or even your PC's hard disk. It can also be added to a bootable CD or DVD. Using grub4dos, you can make a bootable disk/CD/DVD that can run or install Windows XP, Windows 7/8, various versions of linux, memory tests and do much, much more...

    Grub4dos can run batch files and grub4dos executables and supports environment variables. It can access FAT12, FAT16, FAT32, NTFS, exFAT, ISO 9660 CDFS and ext2/3/4 filesystems. It is a very powerful environment and is under constant development and improvement by chenall, tinybit and many others. There is an active forum on reboot.pro here. Grub4dos programs may have the file extension .g4e, grub4dos batch files may have the extension .g4b. You can make Nov 2013 and later versions of grub4dos run these without needing to specify the file extension, by adding command --set-ext=.g4b;.g4e to a grub4dos menu.lst file.

    If you have never used grub4dos before, I will give you a quick 'How to' introduction so you can make a working USB pen drive with which you can experiment.

    IMPORTANT: Always use the latest RMPrepUSB version which will include a recent version of grub4dos or obtain the very latest grub4dos grldr file from the latest chenall build.

    I recommend that you always use the latest version of RMPrepUSB to install grub4dos rather than using grubinst or bootice for two reasons:

    (1) Only (small) USB drives are listed by default, so you cannot accidentally damage your system or external USB hard disks,
    (2) RMPrepUSB adds special modifications to the grub4dos boot code (using a specially modified version of grubinst.exe) which increase the chances of booting grub4dos on a wider variety of systems.

    Note: The RMPrepUSB version of the grub4dos MBR code is not compatible with BootIce - so don't attempt to tweak the defaults timeout,etc. using BootIce!

    If you are having problems booting to grub4dos on some systems try FlashBoot to prepare your USB drive.

    RMPrepUSB Part 3a - grub4dos

    RMPrepUSB Part 3b - grub4dos



    References

    Documentation:
    Main project page (old):
    Download sites:
    Reboot.pro:
    This site:

    Part 1 - Make a bootable USB pen drive

    1. Download and install RMPrepUSB onto your Windows XP/Vista/Win7 system (always use latest Beta) . There is a portable version if you prefer this (though the full version adds no system drivers and is easy to completely uninstall should you want to).

      Linux users can install grub4dos using BootIce.


    2. Insert a USB Flash memory pen drive (or USB hard disk) into the USB port of your Windows computer and run RMPrepUSB - set the following options:

    3. 1. MAX size
      2. MEMTEST as a label
      3. MS-DOS
      4. FAT16 (or use FAT32 if you have >2GB USB drive) + Boot as HDD (2PTNS)
      5. Leave COPY FILES box unticked
      6. Click Prepare Drive to format the USB pen (Note: you will lose all contents as it reformats the drive!)


      Fig. 1 Notice that the settings are numbered 1 to 6 for you - just set 1-5 as shown and then click on 6 Prepare Drive.

      Note: If you are using a USB HDD, you may need to select Settings - List Large Drives >128GB.


    3. Click on the Install grub4dos button - answer 'Yes' to use the MBR option and hit Enter when prompted to copy the grldr file over - or use PBR option if you prefer. ('No User Prompts' must be unticked to get this option').

    (You can use MBR or PBR with RMPrepUSB as it uses a special version of grubinst which works even when booting MS-DOS from grub4dos) . Make sure that the grldr file has been copied across to the USB drive afterwards (you must hit the Enter key when requested - do not just quit the console window!).

    Tip: Some systems give a 'flashing cursor' when they boot from grub4dos installed to the MBR. If you want your USB drive to boot from a wide variety of different systems, install grub4dos twice - once to the MBR and again to the PBR ('No User Prompts' must be unticked to get this option')!
      4. Now follow Tutorial #20 on how to add MemTest86+ to the USB drive you have just prepared (Memtest86+ is a good one to start with because it is quick to boot and ideal for testing the grub4dos menu with - or if you prefer, try Tutorial #37 to make a FreeDOS USB bootable pen drive).

      Assuming you have added MemTest86+, you should now have a USB drive with the following
      3 files on it (press F2 to check USB drive the contents):

      grldr
      menu.lst
      memtest.img

      Note that grub4dos consists of two parts as explained previously.
      • Part 1 is the boot code which does not actually exist as a file and so cannot be easily seen. It's code can be located either in the Master Boot Record (first sectors on a disk) or in the Partition Boot Record (first sectors at the start of a partition). This is written to the disk when you click on the 'Install grub4dos' button and grubinst.exe is run.
      • Part 2 is the main grub4dos code which is loaded by the Part 1 boot code. Part 2 is just the file grldr which should be located in the root of your bootable drive partition. This grldr file is copied from the RMPrepUSB application folder to the target drive when you click on the 'Install grub4dos' button and after grubinst.exe has run successfully. If you wish to use a different version of grub4dos, simply replace the grldr file on the USB boot drive with your different grldr file (not recommended!).
      Once the main grub4dos code held in the glrdr file loads into memory, grub4dos will look for a menu to display. The menu is in the form of a text file named menu.lst which is normally placed in the root of the drive. The search path that grub4dos uses to find a menu.lst file is:
      1. root / of the boot device, then /boot/grub folder, then /grub folder of boot device
      2. search all volumes except cd and floppies - same paths and in same order as above
      If a menu.lst file is not found, grub4dos will display a command prompt. You can type in most of the grub4dos commands at the grub4dos command prompt (such as help).
      If a menu.lst file is found then the commands inside that file will be run.

      Whatever device the /menu.lst file was found on, will be set to be the 'root' device and partition. So ls / or ls (bd)/ will always list the files on the root of the partition that contained the menu.lst that was found and loaded by grub4dos.

      A menu file consists of two sections - all commands before the first title command are executed, in sequential order, as soon as the menu file is loaded.
      When the first title command is found, any further lines are interpreted as menu entries (each menu entry starts with a title command word followed by one or more command lines).

      Note: If your menu uses iftitle commands, all iftitle lines are evaluated and any commands inside the [...] brackets are executed, before the initial menu commands are run and the menu is displayed

      When a user selects a menu entry and presses [Enter], the commands below the title command are executed by grub4dos until the next title command is found (or the end of file is found). When the next title command is found (or the end of file is reached) grub4dos will automatically issue a boot command and CPU control will be passed to whatever code was loaded by the previous menu instructions.

      Note: The menu.lst file can be saved in ANSI format or UTF-8 format using Windows NotePad.
      If saved in UTF-8 format, then non-ANSI characters can be used (e.g. chinese glyphs) but you must also load a font file such as unifont.hex.gz and be in a graphics mode to display non-ANSI characters - e.g.:

      graphicsmode -1 800
      font /unifont.hex.gz

      title reboot (重启)
      reboot

      title halt (关机)
      halt

      Here is a video on how to make a simple ANSI menu.lst menu file and it explains some of the command words that can be used in the menu.

      Hak5 video on menu.lst entries


      Starts at 0:28
      Tip: run RMPrepUSB and press F4 to create/edit a menu.lst file


      Part 2 - Testing your USB pen drive

      We now need to test your USB pen drive to see if it boots.

      You can either reboot your computer (or use a different computer), change the BIOS boot menu so that the BIOS will boot from the USB pen first and see what happens - OR - you can use an emulator like Qemu (this saves having to reboot your computer or unplug the USB drive and move it to another system) - simply press the F11 keyboard function key when running RMPrepUSB or click on the 'Test using QEMU emulator' button in RMPrepUSB to run QEMU and see if your USB drive will boot!

      Note: Use RMPrepUSB v2.1.706_QEMU or later for testing grub4dos.

      Normally, Qemu does not allow BIOS sector writes (except to the MBR!) to the USB drive when it is mapped as a \\PhysicalDriveX on your computer (though no error will be reported) - i.e. any physical drive mapped by Qemu will be treated as a readonly device because Windows locks the volume. For this reason, if you are emulating DOS USB drives using Qemu, you may find it does not work as expected when writing files to the USB drive under DOS (once booted under Qemu) or even within grub4dos (e.g. the savedefault command does not actually save anything!). If, however, you use the latest version of RMPrepUSB, writes will work as expected! See also Tutorial 4 for how to boot from a USB drive in a VirtualBox VM (much faster than QEMU!).

      Always test on as many different types of real hardware as you can - Qemu may not always work as expected (it will be mentioned in the Tutorial if there is a known issue with any particular setup and QEMU), but booting from real computers should work!

      When you press F11 in RMPrepUSB to run QEMU, you will be asked if you want to create a virtual hard disk drive - answer 0, next you will be asked how much memory to allocate to QEMU - just click on OK. You should now see a BIOS boot screen window appear briefly and then a window like this:


      When you see this grub4dos menu - press the <ENTER> key and memtest86+ should start to run.

      It is possible to spice up this menu and make it look better. Let us change the text and background colour, set a 200 second timeout, set a default menu choice if no key is pressed and add a background wallpaper using a .gz file by using these lines at the top of your menu.lst file (add it now and try it!):

      #Normal text black with cyan background, Highlighted menu=yellow text with cyan background, Help text=red with light=blue background, Heading is yellow text with white background
      color black/cyan yellow/cyan red/light-blue yellow/white
      timeout 200
      default 0
      #If the splash.xmp.gz file is present, the lines below will load a background image - use 14-color image for foreground to work.
      splashimage=/BlueLight.xpm.gz
      # IMPORTANT: There must be no spaces at the end of the colour values (e.g. 0033FF) below or it will not take affect!
      # The foreground and background commands must be AFTER the splashimage is loaded
      # format: RRGGBB - e.g. FF0000 is bright red, 100000 is very light red, FFFFFF is pure white, 008000 is mid-green, C0C000 is red+green
      foreground=0033FF
      background=FF3300

      Note: A line starting with # is a comment line - text which follows a # symbol (or pretty much any character!) will be ignored by grub4dos

      Note: foreground and background commands will only work in old 16 colour graphicsmodes (e.g. graphicsmode -1 800 -1 4 or graphicsmode x - where x= 0, 1, 2, 4, 5, 7, 13, 14, 15, 16, 17, 18, 19 + some others). It is best to avoid these commands and use the color command instead - see below.

      Grub4dos 'color' values

      The color statement has the format color NORMAL HIGHLIGHT HELPTEXT HEADING in pairs consisting of foreground text colour/background colour - valid colours are:
      black, blue, green, cyan, red, magenta, brown, light-gray, dark-gray, light-blue, light-green, light-cyan, light-red, light-magenta, yellow and white.

      black 0

      blue 1

      brown 6

      cyan 3

      dark-gray 8

      green 2

      light-cyan 11

      light-blue 9

      light-green 10

      light-gray 7

      light-magenta 13

      light-red 12

      magenta 5

      red 4

      white 15

      yellow 14


      Tip: A nice colour scheme can be made by using a light colour for the foreground and the same colour but darker for the background - e.g. light-cyan/cyan or light-green/green.

      Note that using
      color black/black
      will result in no menu text or timeout or timer countdown text being displayed (black text on a black background)!

      The 'NORMAL' colour setting also sets the console text colours too, unless you specify a 'standard' colour too.

      With later versions of grub4dos (2012+) you can set individual colours if you are using a high resolution image (256 colours or more) as below:

      splashimage /nice1024x768x24bit.bmp.gz
      #0=black,1=blue, 2=green,3=cyan,4=red,5=magenta,6=brown,7=grey (add 8 for bright color - e.g. 15=white, 14=yellow, 13=pink,12=red,11=cyan,10=l.green, 9=bright blue, 8=grey)
      #multiply by 16 to make the background blue (16x1), 32 to make the background green (16x2), 48 for bkgnd cyan (16x3), etc.
      #set normal menu text color to bright red text (12 = 8+4), background to cyan (48) = 12 + 48 = 60
      color normal=60
      # or same as ...
      color normal=0x3c
      #set selected menu heading text to green
      color highlight=02
      #set helptext at bottom of menu to red
      color helptext=04
      #set menu heading colour to black
      color heading=00
      #set console text colour to white on black background (0x0F)
      color standard=15
      # or can use on one line as below
      # color normal=60 highlight=02 helptext=04 heading=00 standard=0x0F border=0x00

      #Another way to set colours is using hex values - a single hex digit for each colour - 0xbf where b=background=0-F and f=text foreground = 0-F
      # colour bg=blue, text=white for normal menu text
      color 0x1f
      # normal = white text on blue, highlight = white text on green, helptext = grey text on red, heading = black text on light-magenta background
      color 0x1f 0x2f 0x47 0xd0
      # set console to light-red text on cyan background
      color standard 0x3c

      # note that if in graphics hi-res mode, the background colour for normal text and help text will be ignored and will be set to transparent.

      the = sign can be omitted in the color command.

      Flashing text

      You can prefix most colours with 'blink-' to make them flash. Note that blink only works in textmode (e.g. graphicsmode 3) and not in a non-text (hi-res) graphics mode. Also you cannot have light blinking background colours, e.g. color blue/blink-light-blue will report back a parsing error; color blink-light-blue/blue is OK and so is color blue/light-blue. Equally color 0x91 will set blinking blue text on a blue background (i.e. invisible!), whereas color 0x99 will set blinking light-blue text on a blue background.
      color standard=blink-light-blue/green will work, but color standard=blink-light-blue/light-green will not work.

      Another way to set the colours if using a splashimage is shown below (graphicsmode command is required if the splashimage is not exactly 640x480, or 800x600, etc), this way you do not have to remember the numbers!

      graphicsmode -1 640x480
      splashimage /vista.bmp
      set black=0 && set blue=1 && set green=2 && set cyan=3 && set red=4 && set magenta=5 && set brown=6 && set lgray=7 && set lgrey=7
      set dgrey=8 && set dgray=8 && set lblue=9 && set lgreen=A && set lcyan=B && set lred=C && set lmagenta=D && set yellow=E && set white=F
      #colors set in pairs background+foreground (if splashimage then only highlight and standard console text have a background colour - all rest use transparent background)
      color normal=0x%white% highlight=0x%lblue%%blue% helptext=0x%lmagenta% heading=0x%red% standard=0x%black%%lcyan% border=0x%red%

      If you issue the command echo -h at the grub4dos command console, all the possible values from 0x00 to 0xff are listed in a table:


      color 0x03 has a black background (0) and a bright green foreground (3).
      color 0x5F has a pink background (5) and a white foreground (F)

      You can also specify a colour pair as one or two RGB 3-byte hex value if in a hi-res VGA graphics mode (not text mode 3) instead of a foreground/background single byte value - e.g.

      # 0x00-0xFF (a value of 0-255) is treated as a background/foreground color value pair
      # numbers larger than 1 byte (0x100-0xFFFFFF) are treated as an RGB value and sets a black background
      color standard=0x0000F4
      echo This is red on a white background

      color standard=0x0100F4
      echo this is blue on a black background (same as 0x0000000100F4)

      color standard 0xFF00000000FF
      echo this is blue text on a green background

      color border=0x9955cc
      #sets a mauve menu border colour

      Later versions of grub4dos (June 2013 and later) can also understand individual colur settings, e.g. color standard=blink-light-blue/black will set blinking (if in text mode) light blue text on a black background.
      Valid colours are: black, blue, green, cyan, red, magenta, brown, light-gray, dark-gray, light-blue, light-green, light-cyan, light-red, light-magenta, yellow and white.


      You can use a 64-bit value to set both the highlight background colour and the text colour:

      # yellow 00FFFF00 + background will be 00222222 (v. dark grey/black)
      color highlight=0x0022222200FFFF00



      Quick summary of graphics mode colour options
      color standard=cyan/black - sets cyan text on a black background
      color standard=0x00AAAA - sets cyan text on a black background (background always black/transparent)
      color standard=0x03 - sets cyan text on a black background (0x13 would set cyan on blue background)
      echo $[0003] Hello - prints cyan text on current background (0013 would set cyan on blue background)
      echo $[0x03] Hello - prints cyan text on a black background (0x13 would set cyan on blue background)

      When in graphics mode, background = black = transparent.

      color highlight=0x22222200FFFF00 - sets background (0x222222) and text colour (0xFFFF00) using 0x00rrggbb00RRGGBB format

      Grub4dos commands

      Comment lines start with a # in my tutorials (actually for most grub4dos versions, any starting character except A-Z,a-z,0-9,/(%,white space and + are treated as a comment line character - but the 'official' character for a comment is #).
      For commands that are above any menu title command (i.e. before a 'title' line), the commands must start on a new line with no space or other character in front of them.
      For lines which follow after a 'title' line, white space and graphics characters are ignored unless they follow a command word - e.g. echo ## ##.

      Nearly all grub4dos commands are (and must be) lower case (e.g. root (hd0,0) is OK, but Root (hd0,0) or root (HD0,0) will give an error). Grub4dos filenames are not usually CaSe SeNsItIvE, but to be on the safe side always use the same upper and lower case letters to match the files on the USB drive(ext2 and exFAT grub4dos volumes will be case sensitive). It is also recommended to use 8.3 filenames if possible (i.e. not long filenames) as you may get problems when booting OS's that do not cope well with long filenames such as MS-DOS or some ISO filesystems. Also be aware that files within a CD or ISO image may be uppercase when accessed by grub4dos, even if they appear as lowercase when viewed in Explorer.

      Note also that, like linux, grub4dos uses forward slashes for directory path separators(/) and does not use the backslash (\) as used by Windows! The \ character is used for literal characters, e.g. \n can be used as a carriage return character for adding help text on a title line.

      Long filenames that have spaces in them (e.g. A File Name with Spaces.txt) must be 'escaped' using a backslash character (\) before each space character like this:

      ls /A\ File\ Name\ with\ Spaces.txt

      This ls command (equivalent to a dir command) when run, produces the result...

      /A\ File\ Name\ with\ Spaces.txt

      Setting a background image

      Older versions of grub4dos required a 14-colour, 640x480 bitmap to be made, however, new versions (2011+) allow you to specify high-colour graphics modes and use high-resolution bitmaps. If you just want to add a nice background, skip the next bit and jump to the 'High Colour and High Resolution Backgrounds' section below.

      Low Resolution 14 colour 640x480 bitmaps

      Note that the menu example above has a 'splashimage' statement. For older versions of grub4dos this command can only use a 14 colour 640x480pixel image to use as a background image (if you do not change the graphicsmode and leave it set to the default mode). For your 14-colour splashscreen image (if you have used a splashimage command), by default, the foreground colour (all of the menu text and the highlight for the currently selected option) will be