Grub4dos Guide - Map Command

 

The map command is used for disk emulation. It is one of the more complex commands available in Grub4dos - see here for grub4dos output when entering the command help map. Using the map command it is possible to -
  • Boot Windows from a non-first hard disk
  • Boot from hard disk images
  • Boot floppy disk images on a floppyless machine
  • Create virtual devices accessible from certain operating systems
  • Boot from ISO images (note - experimental)

There are two distinct types of mapping, direct and memory. Direct mapping is generally used for larger images/devices. If using direct mapping to create a virtual device from a disk image, then the image file must be contiguous (not fragmented). Either of the following programs can be used to defragment a file that is contiguous - contig or wincontig. Attempting to directly map a non-contiguous file will result in  Error 60: File for drive emulation must be in one contiguous disk area , in which case memory mapping or defragmenting the file, and then retrying, should be attempted.

Memory mapping, which copies the mapped device/image into memory, is generally used for smaller images - e.g. floppy disk images. In memory mapping the image file can be non-contiguous. Available system RAM will restrict the size of any image mapped to memory.

The "map" process is implemented using INT 13 - any disk emulation will remain accessible from an OS that uses compatible mode disk access, e.g. DOS and Windows 9x. The emulation can't however, be accessed from an OS which uses protected mode drivers (Windows NT/2000/XP/Vista, Linux, FreeBSD) once the protected mode kernel file(s) take control.

The command line interface will be used throughout this section, which will cover -
  • Direct Mapping
  • Memory Mapping
  • Booting from .ISO Images
  • Nested Mapping

Direct Mapping

The direct mapping section covers the following -
  • Booting Disk Image Files
  • Disk Swapping (e.g. for booting Windows from a non-first hard disk

Booting Disk Image Files

An example of direct mapping of a floppy disk image was given in the Boot Options section of this guide -

title Boot Disk Image
map (hd0,0)/win98.ima (fd0)
map --hook
chainloader (fd0)+1
rootnoverify (fd0)
map --floppies=1
Breaking down these commands line by line, as they would be entered from the command line (above is from a configuration file entry) -
  • title Boot Disk Image - description for configuration file entry. This would be omitted when using the command line.
  • map (hd0,0)/win98.ima (fd0) [enter] - this maps the image file (in this case win98.ima, at the root of first partition on the first hard disk) to the first floppy (fd0).
  • map --hook [enter] - this command makes the mapping take place immediately. Until map --hook is entered, all map commands are only recognised from the booted operating system. Once map --hook is executed, mappings become "global" - they take effect even within Grub4dos. This in covered in more detail in the following section. If the floppy image fails to boot and you are returned to the command line interface (or menu) the mapping will remain in effect until the map --unhook command is issued.
  • chainloader (fd0)+1 [enter] - this tells grub4dos to chainload the first sector of the first floppy disk. As the image file has been mapped as (fd0) and the map --hook command has been issued, this will boot the image file.
  • rootnoverify (fd0) [enter] - this tells grub4dos to make the first (mapped) floppy the ROOT device, without attempting to mount the device. As discussed previously, this can usually be substituted by the "normal" root command, at least for objects that have standard filesystems, like the floppy in this example.
  • map --floppies=1 [enter] - this tells grub4dos that it must "show" just one floppy (the mapped one) to the OS - this can usually be omitted. The boot command will also need to be executed when using the command line.

Grub4dos feedback when entering the above commands from the command line -

grub> map (hd0,0)/win98.ima (fd0)
FAT12 BPB found with 0xEB (jmp) leading the boot sector.

probed C/H/S =80/2/18, probed total sectors = 2880

floppies_orig=0, harddrives_orig=2, floppies_curr=1, harddrives_curr=2

grub> map --hook

grub> chainloader (fd0)+1

grub> rootnoverify (fd0)

grub> map --floppies=1

grub> boot_
Booting hard disk images uses the same principles required for booting a floppy disk image. E.g. to boot hard disk image PE.ima from the first logical volume on the second hard disk -
  • map (hd1,4)/PE.ima (hd0) [enter] - this maps the image file (in this case PE.img, at the root of first logical volume on the second hard disk) as the first hard disk (hd0).
  • map --hook [enter] - same usage as in floppy disk image example above.
  • chainloader (hd0)+1 [enter] - this tells grub4dos to chainload the MBR of the first hard disk. As the image file has been mapped as (hd0) and the map --hook command has been issued, this will boot the MBR of the image file.
  • rootnoverify (hd0) [enter] - this tells grub4dos to make the first (mapped) hard disk the ROOT device, without attempting to mount the device. In this case the root command cannot be used as the whole disk cannot be mounted. It would however be possible to use the root command if chainloading a partition within the disk image - e.g. if chainloader command was chainloader (hd0,0)+1, root (hd0,0)+1 could work, provided the partition type was supported.
  • boot [enter] - boot the chainloaded entry.

When directly mapping a hard disk image the image file must have a valid MBR. An image with multiple partitions should be mapped as a (hd) type device. If the hard disk image file is of a single partition (without MBR), then it should be mapped as a floppy disk.

There are a number of examples of direct mapping in the README_GRUB4DOS.txt file.

Disk Swapping

An example of when you might use the map command to change the disk order occurs when booting from a USB device (e.g. flash drive, or external hard drive). As the BIOS settings are changed to boot from the USB bus, the internal hard disk would become (hd1). DOS and Windows 9x will not boot from a non-first hard disk, although Windows NT based systems will theoretically boot from a non-first disk the arcpaths in boot.ini will have become invalid when booting from the USB device. If a windows OS is installed on the internal device it will therefore no longer boot.

Another example would be adding a new hard disk to an existing system. If for example the old disk had Windows XP installed - and was moved from 'master' to 'slave' (becoming (hd1)), whilst the new disk was set as 'master' (hd0) and Windows Vista was installed to it, it would no longer be possible to boot Windows XP from the slave disk.

It is possible to boot these systems from a non-first hard disk by using the map command to change the disk order (e.g. remapping (hd1) to (hd0)).

In the test setup, the system has two hard disk drives -
  • (hd0) - FAT, 300MB, Linux installed to (hd0,0)
  • (hd1) - FAT, 20MB, MS-DOS installed to (hd1,0)

(hd0,0) contains the marker file hd0.tag and (hd1,0) contains the marker file hd1.tag. The MBR Wizard program has been added to (hd1,0), to check which disks are accessible from dos after using various map commands.

Attempting to boot DOS from (hd1) without remapping the drive, using the commands -
  • root (hd1,0) [enter]
  • chainloader +1 [enter]
  • boot [enter]

results in the following error,

Invalid system disk
Replace the disk, and then press any key
It is possible to "trick" the system into thinking that device (hd1) is the first hard disk by using the map command. To remap (hd1) as (hd0) and chainload the DOS kernel io.sys, use the commands -
  • map (hd1) (hd0) [enter]
  • root (hd1,0) [enter]
  • chainloader /io.sys [enter]
  • boot [enter]

NOTE - using the above sequence of commands, the mapping of (hd1) to (hd0) does not take effect until after the boot command has been issued. Although (hd1) has been mapped as (hd0), all references to the actual device remain (hd1) in Grub4dos. Entering the command find /hd0.tag from the Grub4dos command line will return the device (hd0,0), whilst entering the command find /hd1.tag from the Grub4dos command line will return the device (hd1,0) - see box below.

grub> map (hd1) (hd0)

grub> find /hd0.tag
 (hd0,0)

grub> find /hd1.tag
 (hd1,0)

grub> root (hd1,0)
 Filesystem type is fat, partition type 0xe

grub> chainloader /io.sys
Will boot MS-DOS 7.x from drive=0x81, partition=0x0(hidden sectors=0x3f)

grub> boot_

Note the output following the chainloader command ...from drive=0x81. After booting into DOS the command mbrwizd.exe /list was executed. As you can see from the disk size and filesystem type parameters in figure 1. - the device (hd1) is listed as Disk:0 and Disk:1 - the device (hd0) is not visable.

figure 1.
As noted previously, when using the map command the mapping does not take place until after the boot command is issued. Using the command map --hook however, makes any map commands take place immediately. This is best explained by the following example -
  • map (hd1) (hd0) [enter]
  • map --hook [enter]
  • root (hd0,0) [enter]
  • chainloader /io.sys [enter]
  • boot [enter]

NOTE - using the above sequence of commands, the mapping of (hd1) to (hd0) takes effect immediately after the map --hook command has been issued. Entering the command find /hd0.tag from the Grub4dos command line will result in a "File not found" error, whilst entering the command find /hd1.tag from the Grub4dos command line will return the devices (hd0,0) and (hd1,0) - see box below.

grub> map (hd1) (hd0)

grub> map --hook

grub> find /hd0.tag
Error 15: File not found

grub> find /hd1.tag
 (hd0,0)
 (hd1,0)

grub> root (hd0,0)
 Filesystem type is fat, partition type 0xe

grub> chainloader /io.sys
Will boot MS-DOS 7.x from drive=0x80, partition=0x0(hidden sectors=0x3f)

grub> boot_

Note the output following the chainloader command ...from drive=0x80. After booting into DOS the command mbrwizd.exe /list was executed. The results were the same as in the previous example, with the device (hd1) listed as Disk:0 and Disk:1 - and the device (hd0) not visible.

To make both hard disks visible in DOS, remap (hd1) as (hd0) and (hd0) as (hd1) by using the command -
  • map (hd1) (hd0) [enter]
  • map (hd0) (hd1) [enter]
  • root (hd1,0) [enter]
  • chainloader /io.sys [enter]
  • boot [enter]

NOTE - After entering the commands map (hd1) (hd0) and map (hd0) (hd1), entering find /hd0.tag from the Grub4dos command line will return the device (hd0). Entering find /hd1.tag will return the device (hd1). Once DOS has booted both disks will be accessible, however the physical device (hd1) will be listed as Disk: 0, and the device (hd0) will be Disk: 1 - see figure 2.

figure 2.
The following commands, using map --hook, can also be used -
  • map (hd1) (hd0) [enter]
  • map (hd0) (hd1) [enter]
  • map --hook [enter]
  • root (hd0,0) [enter]
  • chainloader /io.sys [enter]
  • boot [enter]

Remember that disk emulation will only remain accessible from an OS that still uses INT 13. In the examples used above, Windows NT based systems would see device (hd0) as "disk 0" and device (hd1) as "disk 1", as soon as the boot process was complete.

It is also possible to map an individual partition as a device, e.g. -
  • map (hd1,0)+1 (hd0) [enter]
  • map (hd0) (hd1) [enter]
  • map --hook [enter]
  • chainloader (hd0,0)/io.sys [enter]
  • rootnoverify (hd0) [enter]
  • boot [enter]

When mapping a partition the syntax (hdm,n)+1 is used to represent the whole partition (where m=disk number, and n=partition number), not just the first sector.

Grub4dos feedback when mapping a partition using the above commands -

grub> map (hd1,0)+1 (hd0)
FAT16 BPB found with 0xEB (jmp) leading the boot sector.

probed C/H/S =40/16/63, probed total sectors = 40257
Try to locate extended partition (hd1)0+40320 for the virtual (hd0).

probed C/H/S =40/16/63, probed total sectors = 40320

grub> map (hd1) (hd0)

grub> map --hook

grub> chainloader /io.sys
Will boot MS-DOS 7.x from drive=0x80, partition=0x0(hidden sectors=0x3f)

grub> rootnoverify (hd0)

grub> boot_
Individual partitions can be mapped as a floppy device - this has an advantage in that the hard disks remain unchanged and will remain accessible from the booted operating system in their original order. E.g. -
  • map (hd1,0)+1 (fd0) [enter]
  • map --hook [enter]
  • root (fd0) [enter]
  • chainloader (fd0)+1 [enter]
  • boot [enter]

A cautionary note from the README_GRUB4DOS.txt file

"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."

 

Memory Mapping

Memory mapping uses the same command syntax as the direct mapping examples above, with the addition of the --mem switch.

E.g. instead of -
  • map (hd0,0)/win98.ima (fd0) [enter]
  • map --hook [enter]
  • root (fd0) [enter]
  • chainloader (fd0)+1 [enter]
  • boot [enter]
use,
  • map --mem (hd0,0)/win98.ima (fd0) [enter]
  • map --hook [enter]
  • root (fd0) [enter]
  • chainloader (fd0)+1 [enter]
  • boot [enter]

When memory mapping is used the disk image file can be non-contiguous. Devices can also be mapped to memory - e.g. map --mem (hd0,0)+1 (fd0) (as explained previously, the +1 notation is used in the map command to denote the whole partition). If mapping a disk image of a partition without a MBR to memory, it can be mapped as a (hd) device as the MBR will be created within Grub4dos - based on the partition data.

Compressed images can also be used when memory mapping. The images must be compressed with gzip (.gz file extension), which is a freeware opensource compressor. Since many disk images are not "full", their contents can be compressed with a noticeable compression ratio. A standard floppy image (1440 Kb) can usually be reduced to a fraction of its original size. The use of compressed images is therefore recommended, as it allows for faster loading and less usage of disk space.

Example use for Gzip'ed images -
  • find --set-root /win98.ima.gz [enter]
  • map --mem /win98.ima.gz (fd0) [enter]
  • map --hook [enter]
  • root (fd0) [enter]
  • chainloader +1 [enter]
  • boot [enter]

gzip can be downloaded from here. Using gzip to compress the floppy disk image bcdl201a.ima, the image was compressed from 1440kb to 10.4kb.

Although Grub4dos only supports the .gz format natively, the memdisk kernel (part of the syslinux project) can be loaded to support .zip compressed images - e.g. the Winimage .imz format. The memdisk kernel can be gzip'ed and loaded from Grub4dos.

Examples for using memdisk (compressed using gzip) to boot a floppy disk image -
  • find --set-root /memdisk.gz [enter]
  • kernel /memdisk.gz [enter]
  • initrd /win98.ima [enter]
  • boot [enter]

or,

  • find --set-root /memdisk.gz [enter]
  • kernel /memdisk.gz [enter]
  • initrd /win98.ima.gz [enter]
  • boot [enter]

or,

  • find --set-root /memdisk.gz [enter]
  • kernel /memdisk.gz [enter]
  • initrd /win98.ima.zip [enter]
  • boot [enter]

NOTE - in the above examples win98.ima would need to be on the same partition as memdisk.gz

Booting from .ISO Images

New versions of Grub4dos are able to map and boot from some CD images, however it should be noted that this feature is experimental. Certain CD-ROM (ISO9660) images can be mapped as the device (hd32), and booted using the following commands (replace (device)/path/file.iso with the relevant path/filename) -
  • map (device)/path/file.iso (hd32) [enter]
  • map --hook [enter]
  • root (hd32) [enter]
  • chainloader (hd32) [enter] - this can be substituted with chainloader ()  [enter], as the root device was set in the previous command.
  • boot [enter]

There are different types of CD boot emulation, including floppy emulation - in which the boot sector of the CD is a bootable floppy disk image. The boot sector is not accessible when viewing the CD in a file manager such as Windows Explorer and might appear to be a blank disk if no files are contained on the disc root.

In the following test an image was taken of a CD containing a DOS boot disk based bootsector, with various DOS utilities on the CD (not in the boot sector image). When booting this setup from a real CD, the bootsector image is allocated as the A: drive, and the CD-ROM (and files at the root of the CD) is allocated the next available drive letter. The CD image file (hd0,0)/dos.iso was booted using the commands above, this resulted in the following Grub4dos output -

grub> map (hd0,0)/dos.iso (hd32)

grub> map --hook

grub> root (hd32)
 Filesystem type is iso9660, using the whole disk

grub> chainloader (hd32)

Load segment: 0x0    System Type: 0x0    Sector Count: 0x1
Load RBA: 0x3E    Boot Type: 2 = 1.44M floppy

grub> boot

The CD appeared to boot normally. The CD bootsector image was loaded and allocated the A: drive letter and the CD-ROM was allocated as E: drive. Unfortunately attempting to access any files on the E: drive (the root of the CD image) resulted in an error.

The README_GRUB4DOS.txt file suggests the following when using DOS -
...google for ELTORITO.SYS and use it in CONFIG.SYS as a device driver for the virtual cdrom. Example usage of eltorito.sys in CONFIG.SYS: device=eltorito.sys /D:oemcd001 Corresponding MSCDEX command which can be placed in AUTOEXEC.BAT: MSCDEX /D:oemcd001 /L:D

NOTE - if mkisofs 杋so-level 4 command has been used to create the .iso image (as is normal with PE builds), MSCDEX.EXE should not be used - replace with SHSUCDX (see here).

Edited config.sys and autoexec.bat and injected the amended files (and eltorito.sys) into the boot image, before rebuilding dos.iso. The remastered CD-ROM was booted, as before the bootsector itself was accessible however the root of the CD was not.

README_GRUB4DOS.txt also suggests replacing (hd32) with (0xFF), e.g. -
  • map (device)/path/file.iso (0xFF) [enter]
  • map --hook [enter]
  • root (0xFF) [enter]
  • chainloader (0xFF) [enter] or chainloader ()  [enter] as root has already been set.
  • boot [enter]

When mapping the .iso containing eltorito.sys in the bootsector as device (0xFF), the CD-ROM booted and both the bootsector image and the root of the CD were accessible.

The above example illustrates some of the complexities of CD-ROM Emulation. For working examples see this thread here

Nested Mapping

Using recent versions of Grub4dos it is possible to map an image from another mapped image - this is sometimes referred to as double mapping. The UBCD project, for example, utilises a bootable CD containing bootable floppy disk images. Using the CDROM Emulation discussed above, it is possible to map a UBCD .iso file as (hd32), then map a floppy image from (hd32) as device (fd0), then boot from the newly mapped floppy image. E.g. -
  • map --mem (hd0,0)/ubcd34-basic.iso (hd32) [enter]
  • map --hook [enter]
  • map --mem (hd32)/IMAGES/MAXBLAST.IGZ (fd0) [enter]
  • map --hook [enter]
  • root (fd0) [enter]
  • chainloader +1 [enter]
  • boot [enter]
Note from Grub4dos author tinybit - there is no limit to the depth of the nest when using this form of mapping. Expanding on the example above, it would be possible to map another image from within the mapped device (fd0). E.g. -
  • map --mem (hd0,0)/ubcd34-basic.iso (hd32) [enter]
  • map --hook [enter]
  • map --mem (hd32)/IMAGES/MAXBLAST.IGZ (fd0) [enter]
  • map --hook [enter]
  • map --mem (fd0)/floppy.img.gz (fd1) [enter]
  • map --hook [enter]
  • root (fd1) [enter]
  • chainloader +1 [enter]
  • boot [enter]

    PREVIOUS    INDEX    NEXT

你可能感兴趣的:(Grub4dos Guide - Map Command)