Difference between revisions of "Accessing MEMDISK arguments from DOS"

From Syslinux Wiki
Jump to: navigation, search
m (Additional getargs alternative.)
(Wiki formatting. Update links. FreeDOS kernel section and additional references.)
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
 
[[Category:MEMDISK]]
 
[[Category:MEMDISK]]
  
Being able to access the command line arguments given to [[MEMDISK]] from within the DOS image is frequently very useful. This allows to combine several DOS images into one, by executing different scripts depending on the MEMDISK arguments. SYSLINUX provides this information via an API.
+
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:
 
There are several different programs to get those arguments:
<!-- The FreeDOS kernel might eventually also provide a method to -->
 
<!-- retrieve MEMDISK arguments and to use them in its -->
 
<!-- (fd)config.sys and in autoexec.bat. -->
 
  
 
* '''mdiskchk.com''' of the Syslinux package (dosutil/mdiskchk.com)
 
* '''mdiskchk.com''' of the Syslinux package (dosutil/mdiskchk.com)
Line 17: Line 18:
 
<!--  http://web.archive.org/web/20060620033233/http://www.coli.uni-saarland.de/~eric/stuff/soft/specials/combined-drivecheck-memdisk-getargs.zip  -->
 
<!--  http://web.archive.org/web/20060620033233/http://www.coli.uni-saarland.de/~eric/stuff/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:
+
* '''getargs.com''' written by Kenneth J. Davis, based on Syslinux's [[ifmemdsk.c32]] and on Eric Auer's getargs.com:
http://github.com/PerditionC/memdisk_getargs  
+
https://github.com/PerditionC/memdisk_getargs  
 
<!--  -->
 
<!--  -->
 
<!--  Some references:  -->
 
<!--  Some references:  -->
Line 26: Line 27:
 
<!--  -->
 
<!--  -->
 
* '''getargs.com''' written by Murali krishnan Ganapathy:
 
* '''getargs.com''' written by Murali krishnan Ganapathy:
http://people.cs.uchicago.edu/~gmurali/gui/downloads.html
+
[https://web.archive.org/web/20150720200235/https://people.cs.uchicago.edu/~gmurali/gui/downloads.html https://people.cs.uchicago.edu/~gmurali/gui/downloads.html]
  
  
 +
<br />
 
== mdiskchk.com ==
 
== mdiskchk.com ==
  
 +
{|
 +
|
 
<pre>
 
<pre>
 
Usage: mdiskchk [--safe-hooks] [--mbfts] [--batch-output] [--no-sequential]
 
Usage: mdiskchk [--safe-hooks] [--mbfts] [--batch-output] [--no-sequential]
Line 40: Line 44:
 
   --no-sequential  -n      Suppress probing all drive numbers.
 
   --no-sequential  -n      Suppress probing all drive numbers.
 
</pre>
 
</pre>
 +
|-
 +
|
 
<pre>
 
<pre>
 
mdiskchk.com --safe-hooks (-s)
 
mdiskchk.com --safe-hooks (-s)
Line 65: Line 71:
 
   might not enjoy being probed.
 
   might not enjoy being probed.
 
</pre>
 
</pre>
 +
|}
 +
 
These command-line options may be combined.
 
These command-line options may be combined.
  
  
The following example demonstrates how <tt>autoexec.bat</tt> and <tt>mdiskchk.com</tt> can be used.
+
The following example demonstrates how  
 +
<tt>autoexec.bat</tt> and <tt>mdiskchk.com</tt> can be used.
  
 
AUTOEXEC.BAT :
 
AUTOEXEC.BAT :
 +
 +
{|
 +
|
 
<pre>
 
<pre>
 
@echo off
 
@echo off
Line 77: Line 89:
 
call setenv.bat>nul
 
call setenv.bat>nul
 
</pre>
 
</pre>
 +
|}
 +
 
Running <tt>mdiskchk.com</tt> without arguments:
 
Running <tt>mdiskchk.com</tt> without arguments:
 +
 +
{|
 +
|
 
<pre>
 
<pre>
 
Q:\>mdiskchk.com
 
Q:\>mdiskchk.com
Line 85: Line 102:
 
         cmdline = raw initrd=fdubcd.img BOOT_IMAGE=memdisk
 
         cmdline = raw initrd=fdubcd.img BOOT_IMAGE=memdisk
 
</pre>
 
</pre>
 +
|}
  
The above output from <tt>mdiskchk.com</tt> reflects the initial ISOLINUX boot entry:
+
The above output from <tt>mdiskchk.com</tt> reflects the initial  
 +
ISOLINUX boot entry:
 +
 
 +
{|
 +
|
 
<pre>
 
<pre>
 
# Boot fdubcd DOS floppy image
 
# Boot fdubcd DOS floppy image
Line 94: Line 116:
 
APPEND raw
 
APPEND raw
 
</pre>
 
</pre>
 +
|}
  
  
When scanning for MEMDISK mBFTs, <tt>mdiskchk.com</tt> 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.
+
When scanning for MEMDISK mBFTs,  
 +
<tt>mdiskchk.com</tt> 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.
+
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:
 
<!-- Note: fdubcd.iso is part of UBCD v.5.1.x. only. -->
 
<!-- Note: fdubcd.iso is part of UBCD v.5.1.x. only. -->
 
<!-- Other versions of UBCD include "fdubcd" packed in other -->
 
<!-- Other versions of UBCD include "fdubcd" packed in other -->
 
<!-- image formats, not as fdubcd.iso -->
 
<!-- image formats, not as fdubcd.iso -->
  
 +
{|
 +
|
 
<pre>
 
<pre>
 
qemu -kernel ./memdisk -initrd fdubcd.iso -append 'iso ubcdcmd=xbios'
 
qemu -kernel ./memdisk -initrd fdubcd.iso -append 'iso ubcdcmd=xbios'
 
</pre>
 
</pre>
 +
|}
  
The above "<tt>ubcdcmd=</tt>" 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:
+
The above "<tt>ubcdcmd=</tt>" 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 "<code> mdiskchk.com --mbfts </code>" command from within FreeDOS:
 
Running the "<code> mdiskchk.com --mbfts </code>" command from within FreeDOS:
 +
 +
{|
 +
|
 
<pre>
 
<pre>
 
Q:\>mdiskchk.com --mbfts
 
Q:\>mdiskchk.com --mbfts
Line 121: Line 159:
 
         cmdline = raw initrd=fdubcd.img BOOT_IMAGE=memdisk
 
         cmdline = raw initrd=fdubcd.img BOOT_IMAGE=memdisk
 
</pre>
 
</pre>
Note again, the same <tt>ubcdcmd=xbios</tt> parameter in the above resulting output of <tt>mdiskchk.com</tt>.
+
|}
  
The above example shows the <tt>ubcdcmd=xbios</tt> parameter being passed from the first memdisk instance that booted the ISO.
+
Note again, the same <tt>ubcdcmd=xbios</tt> parameter in the above
 +
resulting output of <tt>mdiskchk.com</tt>.
  
To actually make use of this <tt>ubcdcmd=</tt> parameter in DOS, the "<tt>--batch-output</tt>" method is rather useful:
+
The above example shows the <tt>ubcdcmd=xbios</tt> parameter being
 +
passed from the first memdisk instance that booted the ISO.
 +
 
 +
To actually make use of this <tt>ubcdcmd=</tt> parameter in DOS,  
 +
the "<tt>--batch-output</tt>" method is rather useful:
 +
 
 +
{|
 +
|
 
<pre>
 
<pre>
 
Q:\>mdiskchk.com --mbfts --batch-output
 
Q:\>mdiskchk.com --mbfts --batch-output
Line 134: Line 180:
 
set BOOT_IMAGE=memdisk
 
set BOOT_IMAGE=memdisk
 
</pre>
 
</pre>
Redirecting the output to a (.bat) file and running it (like shown above), the <code>%ubcdcmd%</code> variable can be used in batch files to get access to the 'xbios' value.
+
|}
  
 +
Redirecting the output to a (.bat) file and running it (like shown above),
 +
the <code>%ubcdcmd%</code> variable can be used in batch files
 +
to get access to the 'xbios' value.
  
 +
<br />
 
== getargs.com ==
 
== getargs.com ==
  
Add one of the <tt>getargs.com</tt> versions to your DOS image and use it as follows inside any of your .bat files:
+
Add one of the <tt>getargs.com</tt> versions to your DOS image  
 +
and use it as follows inside any of your .bat files:
 +
 
 +
{|
 +
|
 
<pre>
 
<pre>
 
REM * Retrieve and save MEMDISK arguments in settings.bat
 
REM * Retrieve and save MEMDISK arguments in settings.bat
Line 148: Line 202:
 
settings.bat
 
settings.bat
 
</pre>
 
</pre>
 +
|}
  
 
If the call to MEMDISK was:
 
If the call to MEMDISK was:
 +
 +
{|
 +
|
 
<pre>
 
<pre>
 
# Boot DOS and pass arguments
 
# Boot DOS and pass arguments
Line 157: Line 215:
 
APPEND ACTION=install NETSHARE=sharename
 
APPEND ACTION=install NETSHARE=sharename
 
</pre>
 
</pre>
 +
|}
 +
 +
then after the call to <tt>settings.bat</tt> the environment variables
 +
INITRD, ACTION and NETSHARE will be set to
 +
''my_dos.img'', ''install'' and ''sharename'' respectively.
 +
 +
 +
<br />
 +
== FreeDOS kernel ==
 +
 +
<!-- The FreeDOS kernel might eventually also provide a method to -->
 +
<!-- retrieve MEMDISK arguments and to use them in its -->
 +
<!-- (fd)config.sys and in autoexec.bat. -->
 +
<!-- UPDATE: see the following links: -->
 +
* https://sourceforge.net/p/freedos/mailman/message/27544941/ kernel menu choice from Syslinux (2011May)
 +
* http://www.fdos.org/kernel/testing/memdisk/memdisk.txt
 +
* https://github.com/FDOS/kernel/blob/master/docs/memdisk.txt
 +
* https://github.com/FDOS/kernel/blob/master/kernel/memdisk.asm
 +
  
then after the call to <tt>settings.bat</tt> the environment variables INITRD, ACTION and NETSHARE will be set to ''my_dos.img'', ''install'' and ''sharename'' respectively.
+
<br />
 +
== References ==
 +
Some additional (mostly older) references:
 +
* FreeDOS beta9 RC5 bootdisk 1440 (2004Apr) -> <tt>IFMEMDSK.COM  Detects if {{nowrap|Iso/Sys-Linux}} was loaded with Memdisk</tt> (2003Dec, Eric Auer)
 +
* ifmemdsk.zip (Eric Auer)
 +
* http://ericauer.cosmodata.virtuaserver.com.br/soft/specials/tiny-memdisk-getargs.zip (Eric Auer)
 +
* [[ifmemdsk.c32]]

Latest revision as of 17:18, 11 January 2019


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: