One way to access the MS-DOS file systems is to mount the DOS hard disk or floppy disk by using the mount command and then use regular Linux commands, such as ls and cp, to work with the mounted DOS file system. This approach of mounting a DOS file system is fine for hard disks. Linux can mount the DOS partition automatically at startup, and you can access the DOS directories on the hard disk at any time.
If you want a quick directory listing of a DOS floppy disk, however, mounting can soon become quite tedious. First, you must mount the floppy drive. Then, you must use the ls or cp command to work with the files. Finally, you must use the umount command before ejecting the floppy out of the drive.
This is where the mtools package comes to the rescue. The mtools package implements most common DOS commands; the commands use the same names as in DOS, except that you add an m prefix to each command. Thus, the command for getting a directory listing is mdir, and mcopy copies files. The best part of mtools is the fact that you don't need to mount the floppy disk to use the mtools commands.
Insider Insight |
Because the mtools commands write to and read from the physical device (floppy disk), you must log in as root to perform these commands. If you want any user to access the mtools commands, you must alter the permission settings for the floppy drive devices. Use the following command to permit anyone to read from and write to the first floppy drive: chmod o+rw /dev/fd0 |
The mtools package comes with the Red Hat Linux distribution on this book's companion CD-ROMs. When you install Linux, mtools installs automatically as part of the base Linux. The mtools executable files are in the /usr/bin directory. To see whether you have mtools, type ls /usr/bin/mdir at the shell prompt. If the ls command shows that this file exists, mtools is available on your system.
You also can type the following rpm command to verify that mtools is on your system:
rpm -q mtools mtools-3.9.8-7
If mtools is present, the output shows you the full name of the mtools package. The sample output shows that mtools version 3.9.8 is present on the system.
To try out mtools, follow these steps:
Log in as root or type su - and then enter the root password.
Place an MS-DOS floppy disk in your system's A drive.
Type mdir. You should see the directory of the floppy disk (in the standard DOS directory-listing format).
The mtools package should work with the default setup, but if you get any errors, you should check the /etc/mtools.conf file. That file contains the definitions of the drives (such as A, B, and C) that the mtools utilities see. Following are a few lines from a typical /etc/mtools.conf file:
drive a: file="/dev/fd0" exclusive mformat_only drive b: file="/dev/fd1" exclusive mformat_only # First SCSI hard disk partition #drive c: file="/dev/sda1" # First IDE hard disk partition drive c: file="/dev/hda1" # IDE Zip drive drive X: file="/dev/hdd4" exclusive
The pound sign (#) indicates the start of a comment. Each line defines a drive letter, the associated Linux device name, and some keywords that indicate how to access the device. In this example, the first two lines define drives A and B. The third noncomment
line defines drive C as the first partition on the first IDE drive (/dev/hda1). If you have other DOS drives (D, for example), you can add another line that defines drive D as the appropriate disk partition.
If your system's A drive is a high-density, 3.5-inch drive, you shouldn't need to change anything in the default /etc/mtools.conf file to access the floppy drive. If you also want to access any DOS partition in the hard drive, uncomment and edit an appropriate line for the C drive.
Typically, you use the mtools utilities to access the floppy disks. Although you can define C and D drives for your DOS hard-disk partitions, you may want to access those partitions by using the Linux mount command to mount them. Because you can mount the hard-disk partitions automatically at startup, accessing them through the Linux commands is normally just as easy.
Insider Insight |
You also can access Iomega Zip drives through mtools. Simply specify a drive letter and the appropriate device's filename. For built-in IDE (ATAPI) Zip drives, try /dev/hdd4 as the device file, and add the following line in the /etc/mtools.conf file: drive e: file="/dev/hdd4" After that, you should be able to use mtools commands to access the Zip drive (refer to it as the E drive). For example, to see the directory listing, place Zip disk in the Zip drive and type: mdir e: |
The mtools package is a collection of utilities. So far, I have been using mdir-the mtools counterpart of the DIR command in DOS. The other mtools commands are fairly easy to use.
Insider Insight |
If you know the MS-DOS commands, you find that using the mtools commands is very easy. Type the DOS command in lowercase letters, and remember to add m in front of each command. Because the Linux commands and filenames are case sensitive, you must use all lowercase letters as you type mtools commands. |
Table 12-3 summarizes the commands available in mtools.
mtools Utility |
MS-DOS Command (If Any) |
Action |
---|---|---|
mattrib |
ATTRIB |
Changes MS-DOS file-attribute flags |
mbadblocks |
Tests a floppy disk and marks the bad blocks in the file allocation table (FAT) |
|
mcd |
CD |
Changes an MS-DOS directory |
mcopy |
COPY |
Copies files between MS-DOS and Linux |
mdel |
DEL or ERASE |
Deletes an MS-DOS file |
mdeltree |
DELTREE |
Recursively deletes an MS-DOS directory |
mdir |
DIR |
Displays an MS-DOS directory listing |
mdu |
Lists space that a directory and its contents occupy |
|
mformat |
FORMAT |
Places an MS-DOS file system on a low-level-formatted floppy disk (Use fdformat to low-level-format a floppy in Red Hat Linux) |
minfo |
Gets information about an MS-DOS file system |
|
mkmanifest |
Makes a list of short name equivalents |
|
mlabel |
LABEL |
Initializes an MS-DOS volume label |
mmd |
MD or MKDIR |
Creates an MS-DOS directory |
mmove |
Moves or renames an MS-DOS file or subdirectory |
|
mmount |
Mounts an MS-DOS disk |
|
mpartition |
Creates an MS-DOS file system as a partition |
|
mrd |
RD or RMDIR |
Deletes an MS-DOS directory |
mren |
REN or RENAME |
Renames an existing MS-DOS file |
mshowfat |
Shows FAT entries for an MS-DOS file |
|
mtoolstest |
Tests and displays the current mtools configuration |
|
mtype |
TYPE |
Displays the contents of an MS-DOS file |
mwrite |
COPY |
Copies a Linux file to MS-DOS |
mzip |
Performs certain operations on SCSI Zip disks |
You can use the mtools commands just as you'd use the corresponding DOS commands. The mdir command, for example, works the same as the DIR command in DOS. The same goes for all the other mtools commands shown in Table 12-3.
Suppose that you run Red Hat Linux on your home PC and MS-DOS is no longer on your system, but you need to copy some files onto an MS-DOS floppy disk and take the disk to your office. If you already have a formatted MS-DOS floppy, you can simply mount that floppy and copy the file to the floppy by using the Linux cp command. But what if you don't have a formatted DOS floppy? The mtools package again comes to the rescue.
The mtools package provides the mformat utility, which can format a floppy disk for use in MS-DOS. Unlike the DOS format command that formats a floppy in a single step, the mformat command requires you to follow a two-step process:
Use the fdformat command to low-level-format a floppy disk. The fdformat command uses the floppy device name as the argument; the device name includes all the parameters necessary for formatting the floppy disk. Figure 12-9 illustrates the device-naming convention for the floppy drive device. Based on the information shown in Figure 12-9, you use the following command to format a 3.5-inch, high-density floppy disk in your system's A drive:
fdformat /dev/fd0H1440
Figure 12-9: Naming Convention for the Floppy Disk Drive in Red Hat Linux.
Use the mformat command to put an MS-DOS file system on the low-level- formatted floppy disk. If the floppy is in drive A, type the following command to create a formatted DOS floppy:
mformat a: