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
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.
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.
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.
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.
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.
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.
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
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.
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.
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
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
In GRUB for DOS, disk emulation is implemented using the "map" command.
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.
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.
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.
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.
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.
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
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.
you can optionally use the -boot-info-table option, but the info table will be ignored by the program. |