我是靠谱客的博主 独特大米,最近开发中收集的这篇文章主要介绍MEMDISK,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

MEMDISK - Syslinux Wikiicon-default.png?t=LA92https://wiki.syslinux.org/wiki/index.php?title=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 - typically, 2K) chunk of low (DOS) memory for the driver itself, then hooking the INT 13h (disk driver) and INT 15h (memory query) BIOS interrupts.

目录

Usage

Syslinux family

GRUB and GRUB4DOS

GRUB2

Image types

Floppy images

Hard disk images

ISO images

INT 13h access

Using INT 13h BIOS calls

Windows NT based

Linux

Parameters and options

Image geometry and type

Memory access method

Write-protect images

Hide real drives

EDD

PXE

Pause

Stack size

El Torito driver for DOS

Accessing MEMDISK arguments from DOS


Usage

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 and
  • hdt.iso is an ISO image containing Hardware Detection Tool (running directly on SYSLINUX)
  • and dosboot.img is a floppy image containing some version of DOS.

Syslinux family

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

 memdisk initrd=hdt.img

... where hdt.img is the name of the disk image file. In the above example, the memdisk file and the disk image are expected to be present in the appropriate location (e.g. 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 :

 # Hardware Detection Tool from floppy image
 LABEL hdt_floppy
  LINUX memdisk
  INITRD hdt.img
 
 # Hardware Detection Tool from iso image (with 'iso' parameter)
 LABEL hdt_iso
  LINUX memdisk
  INITRD hdt.iso
  APPEND iso
 
 # DOS from floppy image (with 'raw' parameter)
 LABEL dos_floppy_with_raw
  LINUX memdisk
  INITRD dosboot.img
  APPEND raw

See also ifmemdsk.c32.

GRUB and GRUB4DOS

In your menu.lst file, use something like:

 title Hardware Detection Tool from floppy image
   kernel /memdisk
   initrd /hdt.img
 
 title Hardware Detection Tool from iso image (with 'iso' parameter)
   kernel /memdisk iso
   initrd /hdt.iso
 
 title DOS from floppy image (with 'raw' parameter)
   kernel /memdisk raw
   initrd /dosboot.img
 
 title CorePlus (TinyCore installation CD) from ISO image
   root (hd0,0)
   kernel /memdisk iso
   initrd /CorePlus.iso

On some systems you may receive an "error 28: Selected item cannot fit into memory" message despite the physical memory being far larger than the requirements of the OS in the image. In this case, try adding an appropriate "uppermem <memsize>" statement to your grub configuration, e.g. 1G for CorePlus:

 title CorePlus (TinyCore install CD) from ISO image with 1G memory assigned
   uppermem 1048576
   root (hd0,0)
   kernel /memdisk iso
   initrd /CorePlus.iso

Note that the <memsize> parameter for the (GRUB) uppermem command is interpreted as "allow/show/allocate <memsize> KiB above the first 1MiB".

GRUB2

Add the following in your config scripts for grub2:

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

Image types

The image file should contain either:

  • a floppy image,
  • a hard disk image,
  • an ISO image,
    • or an ISOHYBRID 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 MiB) then 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:

   163,840 bytes  (160K) c=40 h=1 s=8    5.25" SSSD
   184,320 bytes  (180K) c=40 h=1 s=9    5.25" SSSD
   327,680 bytes  (320K) c=40 h=2 s=8    5.25" DSDD
   368,640 bytes  (360K) c=40 h=2 s=9    5.25" DSDD
   655,360 bytes  (640K) c=80 h=2 s=8    3.5"  DSDD
   737,280 bytes  (720K) c=80 h=2 s=9    3.5"  DSDD
 1,222,800 bytes (1200K) c=80 h=2 s=15   5.25" DSHD
 1,474,560 bytes (1440K) c=80 h=2 s=18   3.5"  DSHD
 1,638,400 bytes (1600K) c=80 h=2 s=20   3.5"  DSHD (extended)
 1,720,320 bytes (1680K) c=80 h=2 s=21   3.5"  DSHD (extended)
 1,763,328 bytes (1722K) c=82 h=2 s=21   3.5"  DSHD (extended)
 1,784,832 bytes (1743K) c=83 h=2 s=21   3.5"  DSHD (extended)
 1,802,240 bytes (1760K) c=80 h=2 s=22   3.5"  DSHD (extended)
 1,884,160 bytes (1840K) c=80 h=2 s=23   3.5"  DSHD (extended)
 1,966,080 bytes (1920K) c=80 h=2 s=24   3.5"  DSHD (extended)
 2,949,120 bytes (2880K) c=80 h=2 s=36   3.5"  DSED
 3,194,880 bytes (3120K) c=80 h=2 s=39   3.5"  DSED (extended)
 3,276,800 bytes (3200K) c=80 h=2 s=40   3.5"  DSED (extended)
 3,604,480 bytes (3520K) c=80 h=2 s=44   3.5"  DSED (extended)
 3,932,160 bytes (3840K) c=80 h=2 s=48   3.5"  DSED (extended)

A small perl script, included in the MEMDISK directory, 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 higher.

 LABEL floppy_image
  LINUX memdisk
  INITRD floppy.img

If your image is larger than 4 MiB and it is 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 MiB or larger, then it is assumed to be a hard disk image, and should typically have an MBR and a partition table. The image may optionally have a DOSEMU geometry header; in such 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, though.

 LABEL harddisk_image
  LINUX memdisk
  INITRD harddisk.img

If your image is smaller than 4 MiB 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 a more appropriate "APPEND" option. For example, some Windows ISOs 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" ISOs 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. However, the emulation via INT 13h can't be accessed from an OS that uses protected mode drivers (e.g. 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 (see the next section).

ISOHYBRID images

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

To check if your image is 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 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
 
          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! The following sections describe some cases and possible solutions.

  • #Using_INT_13h_BIOS_calls
  • #Windows_NT_based
  • #Linux

Using INT 13h BIOS calls

Real mode operating systems such as DOS (MS-DOS, FreeDOS, DR-DOS, ...), Windows 95/98/ME that use INT 13h BIOS calls, and boot loaders (the Syslinux family, 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 based

Examples of "Windows NT"-based OS: Windows NT/2000/XP/2003/Vista/2008/7... These Windows versions do not use INT 13h access, except during 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.


Examples of Potential Solutions:

  • #Windows_drivers such as WinVBlock and Firadisk
  • #Windows_PE_based
  • #WIM_images

Windows drivers

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

Each of these Windows drivers can do more than detecting MEMDISK-mapped drives.

For more info about WinVBlock and how to build your Windows images: http://reboot.pro/8168/

For more info about Firadisk and how to build your Windows images: http://reboot.pro/8804/

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
 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 RAMdisk-based Windows PE. RAMdisk-based discs use ramdisk.sys and setupldr.bin files from Windows 2003 Server SP1 source, see:

  • "Howto Boot A Pebuilder Iso From Ram, Simple solution", first-post circa 2005Jan, archived
  • "How To Boot A Readwrite Pe System From Ram, (not SDI based)", first-post circa 2007Feb, first-post last edition circa 2009Jul, archived

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 "WIN7 Instal from ISO > semi-automatic IMDISK setup" (sic).

Linux

The majority of Linux-based ISO 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 will fully function via ISO emulation, as no other data needs access 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.


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

  • #Kernel_parameters
  • #memdiskfind_and_kernel_modules phram and mtdblock

Kernel parameters

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

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

  • findiso=
  • iso-scan/filename=

memdiskfind and kernel modules

There is also another solution, which requires the phram and mtdblock kernel modules and the memdiskfind utility of the Syslinux package ([bios/]utils/memdiskfind). memdiskfind will detect the MEMDISK-mapped image and will print the start and length of it 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 library (instead of 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 and links to the Arch Linux implementation: memdisk driver for linux

Parameters and options

  • #Image_geometry_and_type:
   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.
  • #Memory_access_method:
   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.
  • #Write-protect_images:
   ro		Disk is read-only
  • #Hide_real_drives:
   nopass	Hide all real drives of the same type (floppy or hard disk)
   nopassany	Hide all real drives (floppy and hard disk)
  • #EDD BIOS Enhanced Disk Drive Services:
   edd		Enable EDD/EBIOS
   noedd	Disable EDD/EBIOS
  • #PXE:
   keeppxe	Keep PXE capabilities when booted from PXELINUX
  • #Pause Read MEMDISK messages:
   pause	Wait for a key-press right before booting
  • #Stack_size:
   stack=size	Set the stack to "size" bytes

Image geometry and type

You can also manually specify the geometry and type of the image 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

Memory access method

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* crashes the system when this API is invoked. The following command-line options tell 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.

Your image might work fine without those parameters on some PCs or virtual machines, but might 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-protect images

The MEMDISK-mapped (floppy or hard) disk is normally writable (although, of course, there is nothing backing it up, so it only lasts until reset). You can mimic a write-protected disk by specifying the command line option:

   ro		Disk is read-only

Example:

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

Hide real drives

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

EDD

MEMDISK supports BIOS Enhanced Disk Drive Services (EDD/EBIOS). On hard disks, EDD is set on by default, 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

PXE

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: [1]

   keeppxe	Keep PXE capabilities when booted from PXELINUX

Pause

To view the messages produced by MEMDISK, use:

   pause	Wait for a key-press right before booting

Example:

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

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

El Torito driver for DOS

If you're using MEMDISK to boot DOS from a CD-ROM (using ISOLINUX), you might find useful the "generic El Torito CD-ROM driver (eltorito.sys)" by Gary Tong and Bart Lagerweij. 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 /D:MSCD0001

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

 MSCDEX /D:MSCD0001 /L:X

Where "X" is the drive letter.

Accessing MEMDISK arguments from DOS

See the How to access MEMDISK arguments from DOS page.

最后

以上就是独特大米为你收集整理的MEMDISK的全部内容,希望文章能够帮你解决MEMDISK所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部