Advocate GRUB for DOS (Grub4Dos) 

So far, seems to me that the GRUB for DOS is still a hidden treasure that most people haven't realized its beauty and power. Please don't be confused by its name, GRUB for DOS, Grub4Dos is actually the best GRUB boot loader so far until GRUB2 is able to catch up with Grub4Dos's features and get mature enough.

In a nutshell, it is advanced GRUB that

GRUB for DOS 

Source 

http://sarovar.org/projects/grub4dos/

http://grub.linuxeden.com/

http://linux.softpedia.com/get/System/Boot/GRUB-for-DOS-3507.shtml

http://www.boot-land.net/forums/index.php?showtopic=14

Description 

GRUB for DOS is a rebuild of the GNU GRUB boot manager for DOS, and can be run under real mode DOS. It also has many new features.

For example, it can be booted through BOOT.INI of Windows (grldr) and kexec of Linux (grub4lin).

The disk emulation feature is another enhancement over GNU GRUB, and can be used to run legacy DOS/Windows9x systems with floppy or hard disk images.

Features 

Releases 

http://sarovar.org/project/showfiles.php?group_id=320

0.4.3          2007-10-15 05:30
0.4.3pre2      2007-07-25 05:30
0.4.3pre1      2007-06-22 05:30
0.4.2          2006-12-31 05:30

Support 

If you get "Service Unavailable", just wait for a few seconds and try again.

GRUB for DOS tutorial 

http://www.znpc.net/forum/viewthread.php?tid=4

bean Post at 12-4-2007

Latest version maintained at: http://grub4dos.sourceforge.net/wiki/index.php/Grub4dos_tutorial

1. Introduction 

1.1 What is GRUB for DOS 

GRUB for DOS is an universal boot loader based on GNU GRUB. It can boot off DOS/LINUX, or via Windows boot manager/syslinux/lilo, or from MBR/CD. It also has builtin BIOS disk emulation, ATAPI CDROM driver, etc.

1.2 Difference between GRUB for DOS and GNU GRUB 

First of all, GRUB for DOS has a flexible boot loader. Unlike GNU GRUB which relies on three stages of files to boot, GRUB for DOS uses a much better solution. The main function of GRUB is placed in a single file grldr, while the boot loader is placed in another file grldr.mbr, which can be installed to MBR or partition boot sector. At startup, boot code in grldr.mbr will dynamically scan the root directory of every local partition for grldr, and load the first one found. Using this scheme, the location of boot file is no longer fixed, users can move it across partition boundary without causing booting problems.

Secondly, GRUB for DOS can be loaded in multiple ways. GRUB for DOS runtime image comes in two forms. One is grldr, which can be loaded by MBR/partition boot sector and the Windows NT/2000/XP/2003/Vista boot manager. It can also act as the eltorito boot file for bootable CDROM. The other is grub.exe, which is a hybrid executable that can be launched from linux console and DOS prompt.

Thirdly, GRUB for DOS extends the function of GNU GRUB. The most significant enhancement is the map command. In GRUB for DOS, the map command can be used to create virtual harddisks and floppies from image files. These virtual devices can be accessed even after DOS starts.

There are other useful features of GRUB for DOS which are not present in GNU GRUB, such as ATAPI CDROM driver, Chinese support, and so on.

2. Installation 

There are many ways to install GRUB for DOS. Some of them requires modifying MBR or partition boot sector, while others requires changing system startup configuration files.

2.1 Install GRUB for DOS boot code to MBR 

You can use bootlace.com or grubinst.exe to install GRUB for DOS boot code to MBR:

bootlace.com can be used in DOS, Windows 95/98/Me and Linux. Examples:

Install GRUB for DOS boot code to the MBR of first hard drive under DOS, Windows 95/98/Me:

bootlace 0x80

Install GRUB for DOS boot code to the MBR of IDE channel 0, primary drive under Linux:

bootlace /dev/hda

Install GRUB for DOS boot code to the MBR of hard drive image file aa.dsk:

bootlace aa.dsk

grubinst.exe can be used in Linux, FreeBSD and Windows NT family OSs (Windows NT/2000/XP/2003/Vista). Examples:

Install GRUB for DOS boot code to the MBR of first hard drive under Windows NT family OSs:

grubinst (hd0)

Install GRUB for DOS boot code to the MBR of IDE channel 0, primary drive under Linux/FreeBSD:

grubinst "(hd0)"

You can also use device names:

grubinst /dev/hda  (Linux)
grubinst /dev/ad0  (FreeBSD)

Install GRUB for DOS boot code to the MBR of hard drive image file aa.dsk:

grubinst aa.dsk

There are many options you can use with bootlace and grubinst, use the -h option to display help message.

After installing the boot code, you need to copy grldr and menu.lst to the root directory of any FAT16/FAT32/NTFS/EXT2 partition.

2.2 Install GRUB for DOS boot code to partition boot sector 

You can use grubinst to install GRUB for DOS boot code to partition boot sector. Examples:

Install GRUB for DOS boot code to the first primary partition of the first hard drive:

grubinst (hd0,0)

or

grubinst --install-partition=0 (hd0)

or grubinst -p=0 (hd0)

Install GRUB for DOS boot code to the first primary partition of the hard drive image file aa.dsk:

grubinst --install-partition=0 aa.dsk

or

grubinst -p=0 aa.dsk

Just as in GRUB, extended partition starts with (hd0,4).

After installing the boot code, you need to copy grldr and menu.lst to the partition which you install the boot code on.

2.3 Starting GRUB for DOS from DOS 

You can use load GRUB for DOS in config.sys using one of the following lines:

DEVICE=GRUB.EXE
INSTALL=GRUB.EXE
SHELL=GRUB.EXE

grub.exe can also be launched from DOS prompt or batch file such as AUTOEXEC.BAT.

2.4 Starting GRUB for DOS from Linux 

First, you need to apply the kexec patch to the Linux kernel.

Then, you can use the following commands to launch GRUB for DOS from linux:

kexec -l grub.exe
kexec -e

2.5 Booting GRUB for DOS via the Windows NT/2000/XP/2003 boot manager 

Add the following line at the end of boot.ini (this file is hidden):

C:\grldr="Start GRUB4DOS"

Then copy grldr to C:\, and create the GRUB4DOS configuration file at C:\menu.lst.

Next time you start windows, there is a new option "Start GRUB4DOS" which can be used to start GRUB for DOS.

2.6 Booting GRUB for DOS via the Windows Vista boot manager 

Use bcdedit to configure the startup menu:

bcdedit /create /d "Start GRUB4DOS" /application bootsector
bcdedit /set {id} device boot
bcdedit /set {id} path \grldr.mbr
bcdedit /displayorder {id} /addlast

Then copy grldr.mbr to C:\, grldr and menu.lst to the root directory of any FAT16/FAT32/NTFS/EXT2 partition.

grldr.mbr can also be used to start GRUB for DOS in Windows NT/2000/XP/2003 (in fact, grldr.mbr is basicly the first 16 sectors of grldr). To use grldr.mbr as the boot file, use the following line in boot.ini:

C:\grldr.mbr="Start GRUB4DOS"

As in Windows Vista, you need to copy grldr and menu.lst to the root directory of any FAT16/FAT32/NTFS/EXT2 partition.

2.7 Loading GRUB for DOS using other boot loader 

grub.exe can be loaded as a linux kernel.

Load GRUB for DOS using GRUB or another copy of GRUB for DOS, add the following section to menu.lst:

title Load GRUB4DOS
kernel /grub.exe

Load GRUB for DOS using syslinux, add the following section to syslinux.cfg:

label GRUB4DOS
        KERNEL grub.exe

3. Booting DOS/Windows 9X/Windows NT startup files 

In GRUB for DOS, you can load the DOS/Windows 9X/Windows NT startup files directly.

DOS, Windows 95/98/Me:

title Load io.sys
root (hd0,0)
chainloader (hd0,0)/io.sys

Windows NT/2000/XP/2003:

title Load ntldr
root (hd0,0)
chainloader (hd0,0)/ntldr

Windows Vista:

title Load bootmgr
root (hd0,0)
chainloader (hd0,0)/bootmgr

4. Disk emulation 

In GRUB for DOS, disk emulation is implemented using the "map" command.

4.1 Direct mapping 

Here is an example of mapping a image file as virtual floppy, and boot from it:

title Boot from floppy image
map (hd0,0)/aa.img (fd0)
map --hook
chainloader (fd0)+1
rootnoverify (fd0)

map —hook is used to make the mapping created by first map command take effect immediately.

Here is an example of booting from the virtual hard disk:

title Boot from hard disk image
map (hd0,0)/aa.dsk (hd0)
map (hd0) (hd1)
map --hook
chainloader (hd0,0)+1
rootnoverify (hd0,0)

Map the image file as virtual hard disk, but boot from the original disk:

title Create virtual hard disk
map (hd0,0)/aa.dsk (hd1)
map --hook
chainloader (hd0,0)+1
rootnoverify (hd0,0)

CDROM emulation is not implemented.

In direct mapping, the image file must be contiguous.

The virtual disk is implemented using INT 13. Therefore, it can be accessed in system that still uses INT 13, such as all kinds of DOS and Windows 9X (compatible mode disk access), and it can't be accessed in system that uses protected mode drivers, such as Linux, FreeBSD and Windows NT family OSs.

4.2 Indirect mapping 

Indirect mapping is very similar to direct mapping, here is an example:

title Boot from floppy image
map --mem (hd0,0)/aa.img (fd0)
map --hook
chainloader (fd0)+1
rootnoverify (fd0)

The —mem option indicates indirect mapping.

In indirect mapping, the image file is copy to memory before the mapping is applies, therefore, the image file need not to be contiguous, however, you must have enough memory to hole the image file.

4.3 Auto MBR creation 

To create virtual hard disk, you need an image file that resemble a real hard disk, which consist of MBR and partition data. If the image file only contains partition data, you need to patch it with MBR to create disk image.

GRUB for DOS has taken this into consideration. When mapping disk image file, it will test the presence of MBR, if not found, it will create MBR automatically using the partition data. For example:

title Boot from hard disk image
map --mem (hd0,0)/aa.dsk (hd0)
map (hd0) (hd1)
map --hook
chainloader (hd0,0)+1
rootnoverify (hd0,0)

aa.dsk can be either disk image or partition image, in the later case, GRUB for DOS will create the MBR in the air.

4.4 memdisk 

The indirect mapping of GRUB for DOS is similar to the function of external tool memdisk from syslinux. In fact, the following two menu entries do roughly the same thing:

title Boot from virtual disk using internal map command
map --mem (hd0,0)/aa.dsk (hd0)
map (hd0) (hd1)
map --hook
chainloader (hd0,0)+1
rootnoverify (hd0,0)
title Boot from virtual disk using external memdisk
kernel (hd0,0)/memdisk
initrd (hd0,0)/aa.dsk

However, memdisk does not support direct mapping or auto MBR creation.

5.1 Using ATAPI CDROM in GRUB for DOS 

Use the following command to initialize ATAPI CDROM:

cdrom --init

Then, use the following command to start using ATATPI CDROM:

cdrom --hook

After cdrom —hook, the CDROM device can be accessed using (cd0), (cd1), etc.

To boot from the first CDROM, use the following commands:

chainloader (cd0)
boot

To stop using CDROM:

map --unhook
cdrom --stop

The first command removes the (cdN) device mapping, while the second one stops the CDROM driver.

Note If you boot GRUB for DOS from CDROM, the booting device will be (cd). This device is always accessible.

However, if you want to access file from other CDROMs, you still need to initialize them using the above commands.

Examples:

To boot from the first CDROM:

title Boot From First CDROM
cdrom --init
map --hook
chainloader (cd0)
boot

5.2 Create a bootable CDROM 

In GRUB for DOS, you can use grldr to create bootable CDROM:

mkisofs -R -b grldr -no-emul-boot -boot-load-seg 0x1000 -o bootable.iso iso_root
mkisofs -R -b grldr -no-emul-boot -boot-load-size 4 -o grldr.iso iso_root

grldr and menu.lst should be placed at the root directory of CDROM image.

The above two commands can both create a bootable CDROM, but they are not totally the same.

The first one tells BIOS to load the whole grldr. However, some buggy BIOS might ignore it and load only a portion of the file, typically one sector (2048 bytes). This will cause the program to fail.

The second one tells BIOS to load only the first sector (2048 bytes), and the program loads the rest from CDROM. This method is safer, it should work for most BIOS.

Note you can optionally use the -boot-info-table option, but the info table will be ignored by the program.

5.3 Load GRUB for DOS from BCDW 

To load GRUB for DOS from BCDW, first copy grldr and menu.lst to the root directory of CDROM image, then add a new

line to the [MenuItems] section of BCDW configuration file bcdw.ini:

\grldr   ; Grub4Dos
[ Last edited by  bean at 12-4-2007 19:00 ]

documented on: 2007-10-21

where is latest grubinst 

http://www.znpc.net/forum/viewthread.php?tid=13

> where is latest grubinst?
>
> The  File Releases at sf.net is only grubinst 1.0.1 @2006-12-30.

http://download.gna.org/grubutil/

Every version and the source code you can find from the upper link..

barton

Post at 2007-10-31

Grub For Dos Concise User Manual for Linux Users 

Abstract 

Focus on how to use the latest (v0.4.2) grub4dos with SYSLINUX. No historic, or DOS/Windows specific information included.

Synopsis 

GRUB [--bypass] [--time-out=T] [--hot-key=K] [--config-file=FILE]

The FILE, for example, can be (hd0,0)/menu.lst

If no options present, GRUB.EXE simply uses

(hd0,0)/menu.lst

as the configure file, if it exists.

The partition (hd0,0) can be of a Windows partition or a Linux partition, or any other partition type supported by GRUB.

Options 

The FILE can be the contents of a menu. Use semi-colon to delimitate the embedded commands here in FILE. The FILE can be enclosed with a pair of double-quotes. For example:

GRUB --config-file="root (hd0,0);chainloader +1"

This command will boot the system in (hd0,0).

Another example, to reboot the machine:

GRUB --config-file="reboot"

One more example, to halt the machine:

GRUB --config-file="halt"

if —bypass is specified, GRUB will exit to DOS when timeout reached.

The option `—time-out=T' specifies the timeout value in seconds. T defaults to 5 if —bypass is specified and defaults to 0 if —bypass is not specified.

The default hot key value is 0x3920(for space bar). If this key is pressed, GRUB will boot normally. If another key is pressed, GRUB will terminate immediately and return back to DOS. See "int 16 keyboard scan codes" below.

Each option can be specified only once at most.

Boot 

You can boot grub using a linux loader KEXEC, LILO, SYSLINUX or another GRUB. (GRUB4LIN has merged into GRUB.EXE)

To boot GRUB off Linux, use this pair of commands:

kexec -l grub.exe
kexec -e

To boot GRUB via GRUB, use commands like the following:

kernel (hd0,0)/grub.exe
boot

To boot GRUB via LILO, use these lines in lilo.conf:

image=/boot/grub.exe
label=grub.exe

To boot GRUB via SYSLINUX, use these lines in syslinux.cfg:

label grub.exe
        kernel grub.exe

Using Memdrives 

Examples 

Example:

# boot into a floppy image
map --mem (hd0,0)/floppy.img (fd0)
map --hook
chainloader (fd0)+1
rootnoverify (fd0)
map --floppies=1
boot

Because the image will be copied to a memory area, the image itself can be non-contiguous and even gzipped.

Another Example:

map --mem=-2880 (hd0,0)/floppy.img (fd0)

This memdrive (fd0) will occupy at least 1440 KB of memory. This is useful when the size of a 1.44M-floppy image is less than 1440 KB.

One more example:

map --mem --read-only (hd0,0)/hd.img (hd1)

This memdrive is a hard drive, and read-only. That means you will not be able to write data to the memdrive (hd1).

Note the hd.img can be created by 'mkdiskimage' from the syslinux package.

You can use many memdrives and many ordinary virtual emulated disk-based drives at the same time.

If the BIOS does not support int15/EAX=e820h, you will not be able to use any memdrives.

Memdrive emulation 

For memdrive emulation, a single-partition image can be used instead of a whole-harddrive image. Example:

map --mem (hd0,7)/win98.img (hd0)
map --hook
chainloader (hd0)+1
rootnoverify (hd0)
map --harddrives=1
boot

Here win98.img is a partition image without the leading MBR and partition table in it. Surely GRUB for DOS will build an MBR and partition table for the memdrive (hd0).

Disk emulation 

Floppies/harddisks of any size can be emulated with GRUB for DOS.

Image file must be contiguous, or else GRUB for DOS will refuse it.

The `blocklist' command can list fragments or pieces of a file.

Type "help map" at the GRUB prompt to get a brief description of the command.

The form

map ... (fd?)

is a floppy emulation, and the form

map ... (hd?)

is a hard disk emulation.

When —mem is used, it seems rather safe even after entering Windows. Win98 can operate the memdrive normally.

Windows NT/2000/XP does not recognize the emulated drives no matter whether the —mem option is present.

Disk emulation examples 

  1. Emulates HD partition C: as floppy drive A: and boot win98 from C:

    map --read-only (hd0,0)+1 (fd0)
    chainloader (hd0,0)+1
    rootnoverify (hd0)
    boot

    In the above example, (hd0,0) is drive C: with win98 on it. After win98 boot complete, you will find that A: contains all files of C:, and if you delete files in A:, the files in C: will also disappear.

    At the map command line, the notation (hdm,n)+1 is interpreted to represent the whole partition (hdm,n), not just the first sector of the partition.

  2. Emulates HD partition C: as floppy drive A: and boot win98 from A:

    map --read-only (hd0,0)+1 (fd0)
    map --hook
    chainloader (fd0)+1
    rootnoverify (fd0)
    map --floppies=1
    boot

    After the "map —hook" command, the emulation takes effect instantly even in the GRUB command line.

    Note that the (fd0) in "chainloader (fd0)+1" is the emulated virtual floppy A:, not the real floppy diskette(because map is hooked now).

  3. Emulates an image file as floppy drive A: and boot win98 from C:

    map --read-only (hd0,0)/floppy.img (fd0)
    chainloader (hd0,0)+1
    rootnoverify (hd0)
    map --floppies=1
    map --harddrives=1
    boot
  4. Emulates an HD partition as the first hard disk and boot DOS from it:

    map --read-only (hd2,6)+1 (hd0)
    map --hook
    chainloader (hd0,0)+1
    rootnoverify (hd0)
    map --harddrives=1
    boot

    In this example, (hd2,6)+1 represents an extended logical DOS partition of the third BIOS hard disk (hd2).

    If a DOS partition is used to emulate a hard disk, GRUB for DOS will first try to locate the partition table, usually 63 sectors ahead of the DOS partition. GRUB for DOS will refuse the emulation if the partition table is not there.

  5. Emulates an image file as the first hard disk and boot DOS from it:

    map --read-only (hd0,0)/harddisk.img (hd0)
    chainloader --load-length=512 (hd0,0)/harddisk.img
    rootnoverify (hd0)
    map --harddrives=1
    boot

    If an image file is used to emulate a hard disk, the image file must contain an MBR. In other word, the first sector of HARDDISK.IMG must contain the partition table of the emulated virtual hard disk.

Note

Counters for floppies and harddrives in the BIOS Data Area remain unchanged during the mapping. You should manually set them to proper values with `map —floppies=' and/or `map —harddrives=', especially, e.g., when there is no real floppy drive attached to the mother board. If not doing so, DOS might fail to start.

`map —status' can report the values. Note also that `map —floppies=' and `map —harddrives=' can be used independently without the appearance of mappings.

0.4.2 has introduced a new variable, memdisk_raw, to simulate the memdisk-like raw mode. If the BIOS has no int15/87h, or if it has buggy int15/87h support, you should set this variable before any memdrives are used. Here is an example:

map --memdisk-raw=1
map --mem (hd0,0)/floppy.img (fd0)
map --hook
chainloader (fd0)+1
rootnoverify (fd0)
boot

If you encountered a memdrive failure without using map —memdisk-raw=1, you should have a try with `map —memdisk-raw=1'.

If you `map —memdisk-raw=0' later, you should afterwards do a `map —unhook'(and followed by a `map —hook' if needed).

memdisk_raw defaults to 1. You should `map —memdisk-raw=0' if you want to use int15/87h to access memdrives.

bootable images 

By using kexec, we can easily boot into DOS/Win9x from a running Linux system.

If WIN98.IMG is a bootable hard-disk image, do as follows:

kexec -l grub.exe --initrd=WIN98.IMG --command-line="--config-file=map (rd) (hd0); map --hook; chainloader (hd0)+1; rootnoverify (hd0)"
kexec -e

If DOS.IMG is a bootable floppy image, do this way:

kexec -l grub.exe --initrd=DOS.IMG --command-line="--config-file=map (rd) (fd0); map --hook; chainloader (fd0)+1; rootnoverify (fd0)"
kexec -e

Note that in this manner, we can boot DOS/Win9x without using a real DOS/Win9x disk. We need no FAT partition but an image file.

We have noticed that Linux itself can act as a big boot manager by using kexec and grub.exe. This may be convenient to developers who write installation or bootstrap or initialization programs.

Certainly, grub.exe and the bootable disk image can also be loaded by a running GRUB or LILO or syslinux. Examples:

  1. Loaded by GRUB:

    kernel (hd0,0)/grub.exe --config-file="map (rd) (fd0); map --hook; chainloader (fd0)+1; rootnoverify (fd0)"
    initrd (hd0,0)/DOS.IMG
    boot
  2. Loaded by LILO:

    image=/boot/grub.exe
            label=grub.exe
            initrd=/boot/DOS.IMG
            append="--config-file=map (rd) (fd0); map --hook; chainloader (fd0)+1; rootnoverify (fd0)"
  3. Loaded by SYSLINUX:

    label grub.exe
            kernel grub.exe
            append initrd=DOS.IMG --config-file="map (rd) (fd0); map --hook; chainloader (fd0)+1; rootnoverify (fd0)"
Note If the above `map (rd) (…)' failed, you may use `map (rd)+1 (…)' instead and try again.

more on map options 

Along with 0.4.2 final, there are two new options for the map command. They are —safe-mbr-hook=SMH and —int13-scheme=SCH. Both are related with disk emulation for use(as smoothly as possible) in the Win9x environment.

SMH can take either of the two values 0 and 1. By default, SMH is 1. If you encountered problems of disk emulation under Win9x, you may insert a line of

map --safe-mbr-hook=0

before the `boot' command and try again.

Also SCH may take either 0 or 1 at present. By default, SCH is 1. If you encountered disk emulation problems under Win9x, you may insert a line of

map --int13-scheme=0

before the `boot' command and try again.

Note by the way. Like —safe-mbr-hook and —int13-scheme, the MAP command has a few other options that are used for setting global variables. They are here:

map --floppies=M

M can be 0, 1, or 2. MAP will set a proper value at 0040:0010 by using M.

map --harddrives=N

N can be between 0 and 127(inclusive). MAP will set 0040:0075 to N.

map --memdisk-raw=RAW

RAW default to 1. If RAW=0, `int15/ah=87h' will be used to access memdrives.

map --ram-drive=RD

RD default to 0x7F which is a floppy. If the RAM DRIVE is a hard drive image (with partition table in the first sector), you should set RD >= 0x80 and RD < 0xFF.

map --rd-base=ADDR
map --rd-size=SIZE

ADDR specifies the physical base address of the ramdisk image. SIZE specifies the size in bytes of the ramdisk image. ADDR default to 0. SIZE is also default to 0, but a size of 0 means 4GB, not a zero-long disk. The RAM DRIVE can be accessed in the GRUB environment using the (rd) device.

The enhanced cat command 

The cat command now has a few new options: —hex for hexdump, and —locate=STRING for string search in file.

Typical examples:

cat --hex (hd0)+1

It will display the MBR sector in hex form.

cat --hex (md)+2

It will display 1KB of your memory(in fact, it is the real-mode IDT table), also in hexdump form.

cat --hex (md)0x800+1

It will display 1 sector of your extended memory.

cat --hex (hd0,0)+1

It will display the first sector of partition (hd0,0). Usually this sector contains the boot record of an operating system.

Compile 

You should unzip the package under Linux in this way:

unzip grub_for_dos-*.zip

then cd into the grub_for_dos-* dir and do a make.

documented on: 2007.01.20