Grub&Grub2引导WinPE和live CD

Grub&Grub2引导WinPE和live CD

 

Grub引导

利用Grub强大的磁盘仿真map --mem功能,可以从各种不同的介质启动WinPE,不解开ISO就可以直接启动PE,这种启动模式把做好的PE成品拿来用就行,pe不用做任何更改就可以引导,非常简单。

当然,这不仅仅针对PE有效,对一般的live CD也实用,如: ubuntu live CD, slax, CDlinux等等。

 

下面是一个menu.lst

 

color white/blue blue/yellow light-red/blue 10

timeout 3

default 0

 

title WinPE

find  --set-root /boot/WinPE.iso
map --mem /boot/WinPE.iso (0xff)
map --hook
chainloader (0xff)

boot

 

title slax linux

find  --set-root /boot/slax.iso
map --mem /boot/slax.iso (0xff)
map --hook
chainloader (0xff)

boot

 

title foo.iso

map --mem  (bd)/boot/foo.iso (0xff)

map --hook

chainloader (0xff)

boot

 

 

title foo.iso&firadisk

map --mem (bd)/firadisk.img (fd0)

map --mem (bd)/peiso/TonPE.iso (0xff)

map --hook

chainloader (0xff)

boot

 

title setupldr.bin

chainloader (bd)/boot/setupldr.bin

boot

 

title startrom.0

pxe keep

chainloader --force (bd)/peiso/startrom.0

boot

 

title Boot from pxelinux

pxe keep

chainloader --raw (bd)/pxelinux.0

#chainloader --force (bd)/pxelinux.0

boot

 

title  test.iso

find --set-root --devices=g  /ntldr || find --set-root --devices=g  /bootmgr

map () (hd0)

map (hd0) ()

map --rehook

find --set-root --devices=g /ntldr || find --set-root --devices=g /bootmgr

#rootnoverify (hd0,0)

chainloader /ntldr || chainloader /bootmgr

 

title boot from hard disk

root (hd0,0)

chainloader +1

boot

 

title boot from hard disk

checkrange 0x80 read 0x8280 && map (hd1) (hd0)

checkrange 0x80 read 0x8280 && map --hook

chainloader (hd0)+1

boot

 

title command line

commandline

 

title reboot

reboot

 

title halt

halt

 

Grub2引导

GRUB2不支持GRUB那样的map操作来引导ISO文件。但能通过memdisk来引导。

 

memdisk 是什么?

memdisk能够启动某些软盘镜像,硬盘镜像,光盘镜像,通常是一些只读的live CD。

memdisk在内存的高地址区模拟出一个磁盘,在低地址区模拟出它自己使用的驱动,然后调用int13(磁盘驱动),int15(内存查询)bios中断。


怎么使用memdisk?

memdisk是一个auxillary(辅助)模块,用于联结能够加载linux内核的启动引导程序(这些启动引导程序有EXTLINUX/ISOLINUX/PXELINUX/SYSLINUX, grub, grub4dos,grub2等)。就引导程序方面来看,memdisk是内核,镜像文件是inital ramdisk(初始内存盘,作为initrd来传送的镜像文件,可以是zip或gzip压缩过的文件),也就是磁盘镜像。

 

在下面的例子中,hdt.img 为包含有硬件探测工具的软盘镜像文件,htd.iso为包含有硬件探测工具的光盘镜像文件,dos.img是包含有某版本的dos系统的软盘镜像。

menuentry "Boot Hardware Detection Tool from floppy" {
  linux16 /memdisk
  initrd16 /hdt.img
}
menuentry "Boot Hardware Detection Tool from iso" {
  linux16 /memdisk iso
  initrd16 /hdt.iso
}
menuentry "Boot DOS from floppy image (with 'raw' parameter)" {
  linux16 /memdisk raw
  initrd16 /dosboot.img
}

    经本人实测,在Grub2环境下,只能通过linux16, initrd16来引导PE和live CD。

    用grub2命令行下的常规命令linux和initrd引导,当键入boot后电脑会重启,得不到想要的效果。而linux16和initrd16能正确引导,键入后会得到一段返回码。

 

    linux16,initrd16这些是告诉引导程序,以传统的16位协议进行引导系统。至于为什么要用传统的16位协议来进行系统引导,可能是leagcy系统的限制。在我测试的镜像文件中700M以下的live CD都没问题,能很顺利地进入live 系统,但当我通过手动键入命令偿试引导linux mint13(这个iso大约有1.2个G)时,硬盘指示灯快速闪烁几秒钟后没有任何动静,整个机器直接宕掉,键盘无效,只能强行断电。

    这个还有待后期进一步验证。

 

memdisk所支持的镜像类型?

镜像文件中包含磁盘镜像。磁盘镜像可以是软盘镜像,光盘镜像,硬盘镜像

 


软盘镜像

如果磁盘镜像文件小于4M时,memdisk会假定它是软盘镜像,并会根据其大小猜测它的几何参数(geometry)。memdisk能够认得出标准大小的软盘镜像文件和一些通常扩展的软盘镜像文件。

Grub&Grub2引导WinPE和live <wbr>CD

memdisk所在目录包含有一个小的perl脚本,该脚本能够确定软盘镜像文件的几何参数。一句话,memdisk可以识别大多数使用80磁柱的物理内存或更多的格式。

如果你的镜像文件大于4M并且是软盘镜像,这时你需要通过传递适当的参数来确定。如

linux16 memdisk flopply

initrid16 foo.img

 

 

硬盘镜像

如果镜像文件大于4m,memdisk会假定是硬盘文件。该镜像文件通常具有mbr和分区表,还可以有一个DOSEMU 几何参数头部,可以通过该几何参数头部确定该磁盘镜像的c/h/s几何参数。否则将通过检查分区表来确定几何参数。因此,镜像文件应该合适的分区,要不然memdisk没有办法确定其几何参数。


如果镜像文件小于4m,但又是硬盘镜像。你应该传递给memdisk适当的参数。如

linux16 memdisk harddisk

initrid16 foo.img



光盘镜像

对于光盘镜像,我们必需给memdisk传递iso参数。

linux16 memdisk iso

initrid16 foo.iso

    通过利用memdisk来启动cd/dvd镜像和利用map来启动光盘镜像是可能的。memdisk支持非模拟的,软盘模拟,硬盘模拟,光盘模拟。map是通过调用int 13实现的(对于这个,使用兼容模式磁盘访问的系统仍可以对模拟盘进行访问。像dos windows9x的系统都是)。对于使用保护模式的系统,如Windows NT/2000/XP/2003/Vista/2008/7, Linux, FreeBSD,来说,一但保护模式驱动得到控制权后,系统就不能对模拟盘进行访问了。

 

 

 

    要获得memdisk,我们需要一个叫syslinux的包,这个包在linux系统(rhel, centos, ubuntu...)中很容易找到,可以直接在的linux系统里/usr/local/share/syslinux...类似的目录中拷贝一份,当然也可以到syslinux的官方网站去下,http://www.syslinux.org/wiki/index.php/MEMDISK

    下载最新版的syslinux,解开压缩包,memdisk文件夹下面有一个memdisk文件(没有任何扩展名),把memdisk文件复制到Uboot文件夹下(随便你放在哪,这里我是放倒boot这个文件夹下)。

编辑你UGRUB2的配置文件(一般是U/grub2/grub.cfg),在启动项那个区域添加以下几行。

 

 

 

 

 

 

  

menuentry 'Boot Windows 8 PE ISO'{

        set root='(hd0,msdos1)'

        echo 'Loading Memdisk...'

        insmod memdisk

       linux16 /boot/memdisk iso raw

        echo 'Loading ISO...'

      initrd16 /boot/Win8PE.iso

}

  顺利的话,可以正常引导进入PE。

 

 

 

 

 

 

 

  

menuentry 'CDlinux'{

        set root='(hd0,msdos1)'

        echo 'Loading Memdisk...'

        insmod memdisk

       linux16 /boot/memdisk iso raw

        echo 'Loading ISO...'

      initrd16 /boot/CDlinux.iso

}

 

 

 

 

 

 

  

menuentry 'Ubuntu 12.04 server'{

        set root='(hd0,msdos1)'

        echo 'Loading Memdisk...'

        insmod memdisk

       linux16 /boot/memdisk iso raw

        echo 'Loading ISO...'

      initrd16 /boot/ubuntu-12.04-server-amd64.iso

}

 linux也没问题。

 

下面是memdisk的官方英文文档

http://www.syslinux.org/wiki/index.php/MEMDISK

 

 

 

MEMDISK

From Syslinux Wiki


Contents

 [hide

What is MEMDISK?

MEMDISK is meant to allow booting legacy operating systems. MEMDISK can boot floppy images, hard disk images and some ISO images.

MEMDISK simulates a disk by claiming a chunk of high memory for the disk and a (very small - 2K typical) chunk of low (DOS) memory for the driver itself, then hooking the INT 13h (disk driver) and INT 15h (memory query) BIOS interrupts.


How can I use MEMDISK?

MEMDISK is an auxiliary module used in conjunction with a boot loader that can load linux kernels (EXTLINUX/ISOLINUX/PXELINUX/SYSLINUX, grub, grub4dos grub2, ...). You need a disk image as well as the memdisk file itself. As far as the bootloader is concerned, MEMDISK is the "kernel" and disk image is the initial ramdisk (initrd).

The disk image, passed as initrd, can be a compressed zip or gzip file.

In the next examples hdt.img is a floppy image (hdt.iso is a ISO image) containing Hardware Detection Tool (runs directly on SYSLINUX) and dosboot.img is a floppy image that contains some version of DOS.


EXTLINUX/ISOLINUX/PXELINUX/SYSLINUX

You can use MEMDISK straight off the boot loader command line like the following:

memdisk initrd=hdt.img

... where, of course, hdt.img is the name of the disk image file. The memdisk file and the disk image need to be present in the appropriate location (for PXELINUX, on your TFTP server, for ISOLINUX, in the /isolinux directory on your CD, etc.)

Normally, however, you would put something like the following in the configuration file:

 # Boot Hardware Detection Tool from floppy image
 LABEL hdt_floppy
  LINUX memdisk
  INITRD hdt.img

 # Boot Hardware Detection Tool from iso image (with 'iso' parameter)
 LABEL hdt_iso
  LINUX memdisk
  INITRD hdt.iso
  APPEND iso

 # Boot DOS from floppy image (with 'raw' parameter)
 LABEL dos_floppy_with_raw
  LINUX memdisk
  INITRD dosboot.img
  APPEND raw

GRUB and GRUB4DOS

In your menu.lst file, use something like:

 title Boot Hardware Detection Tool from floppy
   kernel /memdisk
   initrd /hdt.img

 title Boot Hardware Detection Tool from iso image (with 'iso' parameter)
   kernel /memdisk iso
   initrd /hdt.iso

 title Boot DOS from floppy image (with 'raw' parameter)
   kernel /memdisk raw
   initrd /dosboot.img

GRUB2

Add the following in your config scripts for grub2:

 menuentry "Boot Hardware Detection Tool from floppy" {
   linux16 /memdisk
   initrd16 /hdt.img
 }

 menuentry "Boot Hardware Detection Tool from iso" {
   linux16 /memdisk iso
   initrd16 /hdt.iso
 }

 menuentry "Boot DOS from floppy image (with 'raw' parameter)" {
   linux16 /memdisk raw
   initrd16 /dosboot.img
 }

Supported image types

The image file should contain a disk image, either a floppy disk or hard disk image, or an iso image.

The disk image can be compressed with zip or gzip.


Floppy images

If the disk image is less than 4,194,304 bytes (4096K, 4 MB) it is assumed to be a floppy image and MEMDISK will try to guess its geometry based on the size of the file. MEMDISK recognizes all the standard floppy sizes as well as common extended formats:

Grub&Grub2引导WinPE和live <wbr>CD

A small perl script is included in the MEMDISK directory which can determine the geometry that MEMDISK would select for other sizes; in general MEMDISK will correctly detect most physical extended formats used, with 80 cylinders or slightly more.

 LABEL floppy_image
  LINUX memdisk
  INITRD floppy.img

If your image is larger than 4 MB and a floppy image, you can force MEMDISK to treat it as a floppy image:

 LABEL floppy_image
  LINUX memdisk
  INITRD floppy.img
  APPEND floppy

Hard disk images

If the image is 4 MB or larger, it is assumed to be a hard disk image, and should typically have an MBR and a partition table. It may optionally have a DOSEMU geometry header; in which case the header is used to determine the C/H/S geometry of the disk. Otherwise, the geometry is determined by examining the partition table, so the entire image should be partitioned for proper operation (it may be divided between multiple partitions, however.)

 LABEL harddisk_image
  LINUX memdisk
  INITRD harddisk.img

If your image is smaller than 4 MB and it is a hard disk image, you can force MEMDISK to treat it as a hard disk image:

 LABEL harddisk_image
  LINUX memdisk
  INITRD harddisk.img
  APPEND harddisk

ISO images

For ISO images, the parameter 'iso' must be passed to MEMDISK.

 LABEL hdt_iso
   LINUX memdisk
   INITRD hdt.iso
   APPEND iso

Sometimes

   APPEND iso raw

is the better "APPEND" option. For example, some Windows ISO's need the 'raw' option on some PCs.

It is possible to map and boot from some CD/DVD images using MEMDISK. No-emulation, floppy emulation and hard disk emulation ISO's are supported.

The "map" process is implemented using INT 13h - any disk emulation will remain accessible from an OS that uses compatible mode disk access, e.g. DOS and Windows 9x. The emulation via INT 13h can't however, be accessed from an OS which uses protected mode drivers (Windows NT/2000/XP/2003/Vista/2008/7, Linux, FreeBSD) once the protected mode kernel drivers take control. If the OS contains drivers for accessing this mapped ISO, or knows how to find the ISO on the disk, there is no booting problem of course (see next section).

ISOHYBRID images

If the image is a so called ISOHYBRID image, you can also treat it as a harddisk image. This is possible because such an image also contains a MBR (Master Boot Record).

To check if your image is an ISOHYBRID, run:

   fdisk -l your_image.iso

For a normal ISO image, the output will look like this:

   Disk your_image.iso: 140 MB, 140509184 bytes
   64 heads, 32 sectors/track, 134 cylinders, total 274432 sectors
   Units = sectors of 1 * 512 = 512 bytes
   Sector size (logical/physical): 512 bytes / 512 bytes
   I/O size (minimum/optimal): 512 bytes / 512 bytes
   Disk identifier: 0xcbacee9f

   Disk your_image.iso doesn't contain a valid partition table

For an ISOHYBRID, the output will look like this:

   Disk your_image.iso: 140 MB, 140509184 bytes
   64 heads, 32 sectors/track, 134 cylinders, total 274432 sectors
   Units = sectors of 1 * 512 = 512 bytes
   Sector size (logical/physical): 512 bytes / 512 bytes
   I/O size (minimum/optimal): 512 bytes / 512 bytes
   Disk identifier: 0xcbacee9f

            Device Boot      Start         End      Blocks   Id  System
   your_image.iso1   *           0      274431      137216   83  Linux

INT 13h access: Not all images will complete the boot process!

Real mode operating systems and boot loaders that use INT 13h BIOS calls

DOS (MS-DOS, FreeDOS, DR-DOS, ...), Windows 95/98/ME and boot loaders (Syslinux, grub, grub4dos, gujin, gag, mbldr, ...) that use INT 13h to read from disks will successfully complete the boot process with MEMDISK (assuming that there are no BIOS bugs, or software bugs).

Windows NT/2000/XP/2003/Vista/2008/7 (NT based)

These Windows versions use INT 13h access only in the start of the booting process (loading only the necessary drivers). Once the protected mode drivers are functional to access the disks, Windows can't see the memory mapped drives created by MEMDISK (CD/DVD, hard disk and floppy disk images) and it will fail to complete the boot process.


Solutions:

- Drivers that detect the MEMDISK mapped floppy/disk/ISO image

- WinVBlock driver

WinVBlock is a Windows driver that overcomes this problem. It detects the MEMDISK mapped drives (CD/DVD, hard disk and floppy disk images) so Windows can read and write to those disks.

For more info about WinVBlock (it can do more than detecting MEMDISK mapped drives) and how to build your Windows images: http://reboot.pro/8168/

Windows images may need the 'raw' parameter on some PCs:

 LABEL windows_winvblock
   LINUX memdisk
   INITRD windows_harddisk.img
   APPEND raw
 LABEL windows_winvblock
   LINUX memdisk
   INITRD windows.iso
   APPEND iso raw
- Firadisk driver

Firadisk is a Windows driver comparable with WinVBlock. It detects the MEMDISK mapped drives (CD/DVD, hard disk and floppy disk images) so Windows can read and write to those disks.

For more info about Firadisk (it can do more than detecting MEMDISK mapped drives) and how to build your Windows images: http://www.boot-land.net/forums/index.php?showtopic=8804

Windows images may need the 'raw' parameter on some PCs:

 LABEL windows_firadisk
   LINUX memdisk
   INITRD windows_harddisk.img
   APPEND raw
 LABEL windows_firadisk
   LINUX memdisk
   INITRD windows.iso
   APPEND iso raw

- Windows PE based

You can also build a RAM disk based Windows PE. RAM disk based discs use ramdisk.sys and setupldr.bin files from windows 2003 server SP1 source, see:

- Windows Vista/2008/7 with WIM images

Windows Vista/2008/7 can be booted from a WIM image (loaded from disk via INT 13h).

If you get the following message while booting the ISO:

A required CD/DVD drive device driver is missing.
 If you have a floppy disk, CD, DVD, or USB flash drive,
 please insert it now.

use the ImDisk solution, described at [1].

Linux

The majority of Linux based CD images will also fail to work with MEMDISK ISO emulation. Linux distributions require kernel and initrd files to be specified, as soon as these files are loaded the protected mode kernel driver(s) take control and the virtual CD will no longer be accessible. If any other files are required from the CD/DVD they will be missing, resulting in boot error(s).

Linux distributions that only require kernel and initrd files function fully via ISO emulation, as no other data needs accessing from the virtual CD/DVD drive once they have been loaded. The boot loader has read all necessary files to memory by using INT 13h, before booting the kernel.

There are ways to get around the problem of not finding the required files:

- Passing ISO parameter to the kernel

Some distributions allow you to pass an extra parameter to the kernel append line, which tells the init scripts to look for an ISO file on a disk. Some distro's require that the drive and partition number where the ISO is stored is explicitly specified, while others will search each partition for the specified filename.

This parameter is distro specific, so look at the docs of your distro. Some popular ones:

  • findiso=
  • iso-scan/filename=

- memdiskfind in combination with phram and mtdblock

There is also another solution, which requires the phram and mtdblock kernel module and memdiskfind utility of the Syslinux package (utils/memdiskfind). memdiskfind will detect the MEMDISK mapped image and will print the start and length of the found MEMDISK mapped image in a format phram understands:

modprobe phram phram=memdisk,$(memdiskfind)
modprobe mtdblock

This will create a /dev/mtdblock0 device, which should be the .ISO image, and should be mountable.

If your image is bigger than 128MiB and you have a 32-bit OS, then you have to increase the maximum memory usage of vmalloc, by adding:

vmalloc=<at_least_size_of_your_image_in_MiB>Mi

Example:
vmalloc=256Mi

to your kernel parameters.

memdiskfind can be compiled with the klibc instead of with the glibc C library to get a much smaller binary for use in the initramfs:

cd ./syslinux-4.04/utils/
make spotless
make CC=klcc memdiskfind

More info + links to the Arch Linux implementation: http://reboot.pro/11690/

Parameters and options

Specifying geometry and image type manually

You can also specify the geometry manually with the following command line options:

   c=#          Specify number of cylinders (max 1024[*])
   h=#          Specify number of heads (max 256[*])
   s=#          Specify number of sectors (max 63)
   floppy[=#]   The image is a floppy image[**]
   harddisk[=#] The image is a hard disk image[**]
   iso          The image is an El Torito ISO9660 image (drive 0xE0)

   # represents a decimal number.

    [*] MS-DOS only allows max 255 heads;
        and on floppy disks it only allows max 255 cylinders.

   [**] Normally MEMDISK emulates the first floppy or hard disk.  This
        can be overridden by specifying an index, e.g. floppy=1 will
        simulate fd1 (B:). This may not work on all operating systems
        or BIOSes.

Example:

 # Boot harddisk image as second hard disk and specify C/H/S geometry
 LABEL hdt_floppy
   LINUX memdisk
   INITRD harddisk.img
   APPEND harddisk=1 c=255 h=64 s=22

Set memory access method (raw, bigraw, int , safeint)

MEMDISK normally uses the BIOS "INT 15h mover" API to access high memory. This is well-behaved with extended memory managers which load later. Unfortunately it appears that the "DOS boot disk" from WinME/XP *deliberately* crash the system when this API is invoked. The following command-line options tells MEMDISK to enter protected mode directly, whenever possible:

   raw               Use raw access to protected mode memory.

   bigraw       Use raw access to protected mode memory, and leave the
                CPU in "big real" mode afterwards.

   int          Use plain INT 15h access to protected memory.  This assumes
                that anything which hooks INT 15h knows what it is doing.

   safeint      Use INT 15h access to protected memory, but invoke
                INT 15h the way it was *before* MEMDISK was loaded.
                This is the default since version 3.73.

It is possible that your image works fine without those parameters on some PCs or virtual machines, but fail to boot on other PCs. In this situation, adding 'raw' will normally solve your problem.

Example:

 LABEL dos_with_extended_memory_manager
   LINUX memdisk
   INITRD dos_emm.img
   APPEND raw

Write protected floppy and hard disk images

The disk is normally writable (although, of course, there is nothing backing it up, so it only lasts until reset.) If you want, you can mimic a write-protected disk by specifying the command line option:

  ro           Disk is readonly

Example:

 # Simulate write protected floppy
 LABEL hdt_write_protected_floppy
   LINUX memdisk
   INITRD hdt.img
   APPEND ro

Hide real floppy or hard drive

Some systems without a floppy drive have been known to have problems with floppy images. To avoid such problems, first of all make sure you don't have a floppy drive configured on the BIOS screen. If there is no option to configure that, or that doesn't work, you can use:

   nopass       Hide all real drives of the same type (floppy or hard disk)
   nopassany    Hide all real drives (floppy and hard disk)

Example:

 # Hide real floppy drive (when no real floppy drive is attached)
 LABEL hide_floppy
   LINUX memdisk
   INITRD hdt.img
   APPEND nopass

Enable/Disable BIOS Enhanced Disk Drive Services

MEMDISK by default supports EDD/EBIOS on hard disks, but not on floppy disks. This can be controlled with the options:

  edd          Enable EDD/EBIOS
  noedd        Disable EDD/EBIOS

Example:

 # Enable EDD for the HDT floppy
 LABEL EDD_on_floppy
   LINUX memdisk
   INITRD hdt.img
   APPEND edd

MEMDISK and PXE booting

Similarly, if you're booting DOS over the network using PXELINUX, you can use the "keeppxe" option and use the generic PXE (UNDI) NDIS network driver, which is part of the PROBOOT.EXE distribution from Intel: [2]

   keeppxe      Keep PXE capabilities when booted from PXELINUX

Pause MEMDISK before booting

To view the messages produced by MEMDISK, use:

  pause        Wait for a keypress right before booting

Example:

 # Pause MEMDISK before booting
 LABEL pause_memdisk
   LINUX memdisk
   INITRD hdt.img
   APPEND pause

Set stack size

The following option can be used to set the real-mode stack size. The default is 512 bytes, but if there is a failure it might be interesting to set it to something larger:

  stack=size   Set the stack to "size" bytes

Example:

 # Change stack size to 2kiB (2048 bytes)
 LABEL change_stack_size
   LINUX memdisk
   INITRD hdt.img
   APPEND stack=2048

MEMDISK and generic El Torito CD-ROM driver for DOS

If you're using MEMDISK to boot DOS from a CD-ROM (using ISOLINUX), you might find the generic El Torito CD-ROM driver (eltorito.sys) by Gary Tong and Bart Lagerweij useful. It is now included with the Syslinux distribution, in the dosutil directory. See the file dosutil/eltorito.txt for more information.

Example usage of eltorito.sys in CONFIG.SYS:

device=eltorito.sys /X:MSCD0001

Corresponding MSCDEX command which can be placed in AUTOEXEC.BAT:

MSCDEX /X:MSCD0001 /L:X

Where X is the drive letter.


Accessing MEMDISK arguments from DOS

Many times it is very useful to be able to access the command line arguments given to MEMDISK from within the DOS image. This would allow one to combine several DOS images into one, by executing different scripts depending on the arguments.

You can use 3 different programs to get the those arguments:

  • mdiskchk.com of the Syslinux package (dosutil/mdiskchk.com)
  • getargs.com written by Eric Auer (also can check for the existence of drives):
 http://ericauer.cosmodata.virtuaserver.com.br/soft/specials/combined-drivecheck-memdisk-getargs.zip
  • getargs.com written by Murali krishnan Ganapathy:
 http://people.cs.uchicago.edu/~gmurali/gui/downloads.html

mdiskchk.com

Usage: mdiskchk [--safe-hooks] [--mbfts] [--batch-output]

Action: --safe-hooks     Will scan INT 13h "safe hook" chain
        --mbfts          Will scan memory for MEMDISK mBFTs
        --batch-output   Will output SET command output based
                         on MEMDISK kernel arguments
        --no-sequential  Suppresses probing all drive numbers
mdiskchk.com --mbfts (-m)
  This mode will scan between free base memory and
  0xA00000 looking for MEMDISK mBFTs.  For each one
  found, its detail will be reported.

mdiskchk.com --safe-hooks (-s)
  This mode will attempt to walk the chain of INT 13h
  "safe hooks".  For each MEMDISK "safe hook" found,
  its detail will be reported.

mdiskchk.com --batch-output (-b)
  This mode suppresses the normal detail report and
  instead outputs a list of DOS SET commands.  This
  is useful if one wishes to populate a batch file
  and call that batch file to set DOS environment
  variables, so that programs have access to those
  MEMDISK kernel arguments passed at boot-time.

mdiskchk.com --no-sequential mode (-n)
  It might be useful to suppress MDISKCHK.COM's
  classic behaviour of probing all BIOS drive
  numbers in search of MEMDISKs.  Some BIOSes
  might not enjoy being probed.

These command-line options may be combined.

For example, your AUTOEXEC.BAT might go:

@echo off
echo @echo off>setenv.bat
mdiskchk.com -m -s -b -n >>setenv.bat
call setenv.bat>nul

When running mdiskchk.com without arguments, you will see something like this:

Q:>mdiskchk.com    
Drive 00 is MEMDISK 3.86:                         
        Address = 0x06ff8000, len = 5760 sectors, chs = 80/2/36,                
        loader = 0x33 (ISOLINUX),                 
        cmdline = raw initrd=fdubcd.img BOOT_IMAGE=memdisk

When scanning for MEMDISK mBFTs, mdiskchk will find previous MEMDISK instances. This can be useful to detect parameters passed to the first MEMDISK (e.g. an ISO) and use them in the MEMDISK mapped floppy image.

Here is an example of the UBCD Freedos floppy image packed in an ISO. The floppy image inside the ISO is booted with MEMDISK. The ISO, which uses ISOLINUX as bootloader, is also booted with MEMDISK.

ubcdcmd= is passed to the MEMDISK mapped ISO image and allows us to choose with specific tool we want to run once we are booted into FreeDOS from the bootloader (QEMU in this case, but normally ISOLINUX, SYSLINUX, ...) itself, instead of from a menu inside the FreeDOS image which is the normal way:

qemu -kernel ./memdisk -initrd fdubcd.iso -append 'iso ubcdcmd=xbios'

Running the mdiskchk.com --mbfts command from within FreeDOS:

Q:>mdiskchk.com --mbfts                          
Drive 00 is MEMDISK 3.86:                         
        Address = 0x06ff8000, len = 5760 sectors, chs = 80/2/36,                
        loader = 0x33 (ISOLINUX),                 
        cmdline = raw initrd=fdubcd.img BOOT_IMAGE=memdisk                      
Drive E0 is MEMDISK 3.86:                         
        Address = 0x072e9000, len = 6668 sectors, chs = 65535/255/15,           
        loader = 0xb0 (Qemu),                     
        cmdline = iso ubcdcmd=xbios               
Drive 00 is MEMDISK 3.86:                         
        Address = 0x06ff8000, len = 5760 sectors, chs = 80/2/36,                
        loader = 0x33 (ISOLINUX),                 
        cmdline = raw initrd=fdubcd.img BOOT_IMAGE=memdisk

As you can see, the ubcdcmd=xbios parameter is passed to the memdisk instance that booted the ISO.

To use this ubcdcmd= parameter, we can better use the --batch-output method:

Q:>mdiskchk.com --mbfts --batch-output                 
set raw=1           
set initrd=fdubcd.img                             
set BOOT_IMAGE=memdisk                            
set iso=1           
set ubcdcmd=xbios   
set raw=1           
set initrd=fdubcd.img                             
set BOOT_IMAGE=memdisk

If we redirected the output to a file (.bat) and run it (like shown above), we now can use the %ubcdcmd% variable in our batch files to get access to the 'xbios' value.

getargs.com

Add one of the getargs.com versions to your DOS image and use it as follows inside any of your .bat files:

REM Retrieve and save MEMDISK arguments in settings.bat
getargs.com > settings.bat

REM Run setting.bat so the retreived MEMDISK arguments are
REM set as environment variables for further usage.
settings.bat

If the call to MEMDISK was:

# Boot DOS and pass arguments
LABEL dos_with_args
LINUX memdisk
INITRD my_dos.img
APPEND ACTION=install NETSHARE=sharename

then after the call to settings.bat the environment variables INITRD, ACTION and NETSHARE will be set to my_dos.img, install and sharename respectively.

 

 

原文地址:https://www.cnblogs.com/lixuebin/p/10814594.html