Accessing MEMDISK arguments from DOS

From Syslinux Wiki
Jump to: navigation, search


Being able to access the command line arguments given to MEMDISK from within the DOS image is frequently very useful. This makes possible the combination of several DOS images into one, by executing different (DOS) scripts depending on the MEMDISK arguments. SYSLINUX provides this information via an API.

There are several different programs to get those arguments:

  • mdiskchk.com of the Syslinux package (dosutil/mdiskchk.com)
  • getargs.com written by Eric Auer (can also check for the existence of drives):
http://ericauer.cosmodata.virtuaserver.com.br/soft/specials/combined-drivecheck-memdisk-getargs.zip
  • getargs.com written by Kenneth J. Davis, based on Syslinux's ifmemdsk.c32 and on Eric Auer's getargs.com:
https://github.com/PerditionC/memdisk_getargs
  • getargs.com written by Murali krishnan Ganapathy:
https://people.cs.uchicago.edu/~gmurali/gui/downloads.html



mdiskchk.com

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

  --safe-hooks      -s      Scan INT 13h "safe hook" chain.
  --mbfts           -m      Scan memory for MEMDISK mBFTs.
  --batch-output    -b      Output SET command based
                            on MEMDISK kernel arguments.
  --no-sequential   -n      Suppress probing all drive numbers.
mdiskchk.com --safe-hooks (-s)
  Attempt to walk the chain of INT 13h
  "safe hooks".  For each MEMDISK "safe hook" found,
  its detail will be reported.

mdiskchk.com --mbfts (-m)
  Scan between free base memory and
  0xA00000 looking for MEMDISK mBFTs.  For each one
  found, its detail will be reported.

mdiskchk.com --batch-output (-b)
  Suppress the normal detailed report and
  instead output a list of DOS 'SET' commands.  The
  output is useful to populate a batch file, and
  then 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)
  Suppress MDISKCHK.COM's
  classic behaviour of probing all BIOS drive
  numbers in search of MEMDISKs.  Some BIOS
  might not enjoy being probed.

These command-line options may be combined.


The following example demonstrates how autoexec.bat and mdiskchk.com can be used.

AUTOEXEC.BAT :

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

Running mdiskchk.com without arguments:

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

The above output from mdiskchk.com reflects the initial ISOLINUX boot entry:

# Boot fdubcd DOS floppy image
LABEL fdubcd
LINUX memdisk
INITRD fdubcd.img
APPEND raw


When scanning for MEMDISK mBFTs, mdiskchk.com 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:

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

The above "ubcdcmd=" argument is passed to the MEMDISK-mapped ISO image and allows us to choose which 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.

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

Q:\>mdiskchk.com --mbfts
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

Note again, the same ubcdcmd=xbios parameter in the above resulting output of mdiskchk.com.

The above example shows the ubcdcmd=xbios parameter being passed from the first memdisk instance that booted the ISO.

To actually make use of this ubcdcmd= parameter in DOS, the "--batch-output" method is rather useful:

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

Redirecting the output to a (.bat) file and running it (like shown above), the %ubcdcmd% variable can be used in 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 retrieved 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.



FreeDOS kernel



References

Some additional (mostly older) references: