The mtools Utilities: msdos

 < Day Day Up > 



Your Linux system provides a set of utilities, known as mtools, that enable you to access a floppy and hard disks formatted for MS-DOS easily (see Table 10-6).

Copying Files to a DOS Floppy

The mcopy command enables you to copy files to and from an MS-DOS floppy disk in your floppy drive or a Windows partition on your hard drive. No special operations, such as mounting, are required. With mtools, you needn't mount an MS-DOS partition to access it. For an MS-DOS floppy disk, place the disk in your floppy drive, and you can then use mtool commands to access those files. For example, to copy a file from an MS-DOS floppy disk to your Linux system, use the mcopy command. You specify the MS-DOS disk with a: for the A drive. Unlike normal DOS pathnames, pathnames used with mtool commands use forward slashes instead of backslashes. The directory docs on the A drive would be referenced by the pathname a:/docs, not a:\docs. Unlike MS-DOS, which defaults the second argument to the current directory, you always need to supply the second argument for mcopy. The next example copies the file mydata to the MS-DOS disk, and then copies the preface file from the disk to the current Linux directory.

$ mcopy mydata a: $ mcopy a:/preface  . 
Note 

Currently, mtools cannot access Windows XP, NT, and 2000 NTFS partitions.

mtools Commands

You can use the mdir command to list files on your MS-DOS disk, and you can use the mcd command to change directories on it. The next example lists the files on the MS-DOS disk in your floppy drive, and then changes to the docs directory on that drive:

$ mdir a: $ mcd a:/docs

Most of the standard MS-DOS commands are available as mtool operations. You can create MS-DOS directories with mmd and erase MS-DOS files with mdel. A list of mtool commands is provided in Table 10-6. For example, to display a file on drive B on an MS-DOS disk in the second floppy drive, use mtype and the name of the file preceded by b:/.

$ mtype b:/readme
Table 10-6: The mtools Access Commands

Commands

Execution

mcopy filename filename

Copies a file to and from an MS-DOS disk or your Linux system. The following copies a file from an MS-DOS floppy disk to your Linux system:
mcopy a:/filename directory-or-filename The following copies a file from Linux for an MS-DOS floppy disk in your floppy drive:
mcopy filename a:/filename

mcd directory-name

Changes directory on your MS-DOS file system.

mdir

Lists the files on an MS-DOS disk in your floppy drive.

mattrib

Changes the attribute of an MS-DOS file.

mdel filename

Deletes an MS-DOS file.

mformat

Adds an MS-DOS file system to a floppy disk.

mlabel

Makes a volume label.

mmd directory-name

Makes an MS-DOS directory.

mrd directory-name

Removes an MS-DOS directory.

mread filename filename

Low-level read (copy) of an MS-DOS file to Unix.

mren filename filename

Renames an MS-DOS file.

mtype filename

Displays contents of an MS-DOS file.

mwrite filename filename

Low-level write (copy) a Unix file to MS-DOS.

Configuring mtools: /etc/ mtools.conf

Access to MS-DOS or Windows 95, 98, or ME partitions by mtools is configured by the /etc/mtools.conf file. This file lists several different default MS-DOS or Windows partitions and disk drives. Each drive or partition is identified with a particular device name. Entries for your floppy drives are already entered, using the device names /dev/fd0 and /dev/fd1 for the first and second floppy drives. An entry in the /etc/mtools.conf file takes the form of the drive label followed by the term file and the equal sign, and then the device name of the drive or partition you want identified with this label. The device name is encased in quotes. For example, assuming the first hard disk partition is an MS-DOS partition and has the device name of /dev/hda1, the following entry would identify this as the C drive on an MS-DOS system:

drive c: file="/dev/hda1"

You must have the correct device name for your partition. These device names are listed in the /etc/fstab file and can also be viewed with the Linuxconf local drive access panel on your root user desktop. If you have a SCSI hard disk, the hard disk partition has the form of sd, followed by a character for the hard drive and a number for the partition in it. For example, sda1 refers to the first partition on the SCSI hard drive. IDE hard drives have the form of hd, also followed by a character and a partition number—hda1 refers to the first partition on an IDE hard drive.

On most distributions, a default /etc/mtools.conf file is installed for you (see the following /etc/mtools.conf example). This file has commented entries for the C drive: one for a SCSI hard disk partition and one for an IDE partition. Both are commented out with a preceding #. If you have an IDE hard drive (as most users do), you need to remove the preceding # symbol from the entry for the IDE hard disks partition and leave the preceding # symbol in front of the entry for the SCSI partition. Also, if your MS-DOS partition on your IDE hard drive is not the first partition, you must change the device name. For example, if the MS-DOS partition is the second partition, the device name will be /dev/hda2. If you have several MS-DOS partitions, you can add entries for each one, assigning a different label to each. The following example assigns the d: label to the fourth hard disk partition on an IDE drive:

drive d: file="/dev/hda4"

/etc/mtools.conf

start example
 # Linux floppy drives 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" drive d: file="/dev/hda5" #dosemu floppy image drive m: file="/var/lib/dosemu/diskimage" #dosemu hdimage drive n: file="/var/lib/dosemu/diskimage" offset=8832 #Atari ramdisk image drive o: file="/tmp/atari_rd" offset=136 mtools_lower_case=1 
end example

Copying Files to a DOS Partition

Once the DOS hard disk partitions are referenced, you can then use their drive letters to copy files to and from them to your Linux partitions. The following command copies the file mydoc.html to the c: partition in the directory webstuff and renames it mydoc.htm. Notice the use of forward slashes instead of backward slashes.

$ mcopy mypage.html c:/webstuff/mypag.htm

Because of the differences in the way DOS and Linux handle newlines in text files, you should use the -t option whenever copying a DOS text file to a Linux partition. The following command copies the mydoc.txt file from the c:/project directory to the /newdocs directory:

$ mcopy -t c:/project/mydoc.txt /newdocs



 < Day Day Up > 



Red Hat(c) The Complete Reference
Red Hat Enterprise Linux & Fedora Edition (DVD): The Complete Reference
ISBN: 0072230754
EAN: 2147483647
Year: 2004
Pages: 328

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net