Using diskettes and CD-ROMs with Red Hat Linux requires some understanding about removable media. This chapter discusses how to read and write files to and from diskettes, how to format diskettes, and how to read and copy data from a CD-ROM. This chapter also covers using CD-writable and CD-rewritable drives.
The term disk typically refers to disks such as hard drives; the term diskette usually refers specifically to floppy disks; and the term disc refers to optical media such as CD-ROMs and DVDs.
Diskettes are one of the oldest removable media solutions available for the PC. Diskettes are ideal as a portable storage solution for files that need to be physically moved around. For example, if two PCs are not on the same network, diskettes are a great solution to transfer files from one computer to the other.
A diskette must be mounted first before it can be used. Insert a diskette into the diskette drive and type mount /mnt/floppy/ at a shell prompt.
The diskette drive activity light should blink as the diskette's file system is mounted to the /mnt/floppy directory.
You can access the contents of the diskette by changing into that directory with the cd /mnt/floppy/ command.
Alternatively, you can also mount a diskette by right-clicking on the desktop and choosing Disks > Floppy. This mounts the diskette and adds a desktop icon that you can double-click to explore the diskette contents.
Now that the diskette has been mounted it is available to be copied from or written to. You can open, save, and copy files to or from the diskette as you would normally do to your hard drive. You can even explore the diskette's contents in Nautilus or Konqueror.
Figure 7-1. Viewing Files on a Diskette with Nautilus
When you are finished using the diskette, you should unmount it before ejecting it from the drive. To do this, close any applications that may be using files on the diskette or exploring the diskette's contents (such as Nautilus or Konqueror), and at a shell prompt type the following command:
You can now safely eject the diskette from the drive.
If you are using the default Red Hat desktop environment, you can unmount the diskette by right-clicking on the icon and choosing Unmount Volume from the menu that appears.
If you have an MS-DOS formatted diskette, you can access the files on it by using the mtools utility. mtools offers a wide range of options for working with diskettes, including copying, moving, deleting, and formatting. (To read more about mtools, type man mtools at a shell prompt.)
For example, to copy a file called file.txt from an MS-DOS formatted diskette (such as one from a Windows system), type the following command at a shell prompt:
mcopy a:file.txt file.txt
file.txt will then be copied from the diskette drive (assuming that the disk is in drive A:) to the directory you were in when you issued the mcopy command. If you are in your home directory, you will find file.txt located there.
If you want to view the contents of an MS-DOS formatted diskette, type mdir at the prompt. You will be shown the contents of the diskette. The directory listing will look familiar to some MS-DOS or Windows users, as it is styled in the MS-DOS dir listing format. For example:
[joe@localhost joe]$ mdir a: Volume in drive A has no label Volume Serial Number is 0000-0000 Directory for A:/ FOOBAR TXT 6004 01-01-1999 1:01 ZZTOP COM 1533 01-01-1999 1:01 TAXES99 XLS 26469 01-01-1999 1:01 THISFILE TXT 277 01-01-1999 1:01 COMMAND COM 93890 01-01-1999 1:01 5 files 128 173 bytes 1 271 827 bytes free
To change to a subdirectory on the diskette, type the following command at a shell prompt:
In the above command, replace subdir with the name of the subdirectory you want to access.
To copy files from a Linux machine to an MS-DOS formatted diskette so that a Windows machine can read it, you should format your disk with an MS-DOS (FAT) file system, which can be done with a Windows OS or with gfloppy (see the “Using gfloppy” section later in this chapter). Then mount it in Linux as described in the preceding section. Copy files using the following command (substituting filename with the name of the file you wish to copy):
cp filename /mnt/floppy
You can then unmount the floppy and eject it from the drive. The new file on the diskette should now be accessible from your Windows machine.
The file will not be copied until after the umount command has been successfully executed.
To use a diskette specifically with Red Hat Linux, you need to format the disk using the ext2 file system. ext2 is one of the file systems supported by Red Hat Linux, and is the default method used for formatting diskettes.
Formatting a diskette will erase all of its contents. Be sure to back up any files that you need before performing any of the following operations on your diskettes.
After you have created an ext2 file system on the diskette, you can manipulate its contents in the same ways that you manipulate directories and files on your hard drive.
If you’re wondering why a floppy should be formatted with ext2 rather than ext3, it’s because the only real difference between ext2 and ext3 is journaling, which increases the size of the file system. Because diskettes are so small, they don’t require journaling features (or the increased size of the file system), so ext2 should be used instead of ext3 for diskettes.
To start gfloppy, click the Main Menu button and choose System Tools > Floppy Formatter (or, from a shell prompt, you can type /usr/bin/gfloppy). As shown in Figure 7-2, the gfloppy interface is small and has few options.
The default settings are sufficient for most users and needs; however, you can format your diskette with an MS-DOS file system type if you desire. You can also choose the density of your floppy disk (if you are not using the usual high density 3.5" 1.44MB diskette). You can also elect to quick format the diskette if it was previously formatted as ext2.
Figure 7-2. gfloppy
Insert a diskette and change the settings to suit your needs; then click Format. The status box will appear on top of the main window, showing you the status of formatting and verifying (see Figure 7-3). When it is complete, you can eject the disk and close gfloppy.
Figure 7-3. gfloppy Status Box
Another way to format a diskette for either ext2 or MS-DOS is to use KFloppy. To start the utility, open a shell prompt and type the command kfloppy. You will be presented with a graphical interface, as shown in Figure 7-4.
Insert a diskette that you wish to format and choose whether you want a Quick Format or Full Format by choosing the appropriate radio button. To check for bad sectors or blocks on the diskette while formatting, choose Verify Integrity in the associated check box.
Figure 7-4. KDE Floppy Formatter
To begin formatting, click the Format button. A window will pop up asking if you wish to format the diskette. Click Continue to dismiss this window and begin formatting. A status bar will appear at the bottom of the window showing the status of the format. After the diskette has been formatted, a final window will appear to inform you of a successful format. Click OK, remove the diskette, and click Quit to close the application.
The mke2fs command is used to create a Linux ext2 file system on a device such as a hard drive partition or (in this case) a floppy diskette. mke2fs essentially formats the device and creates an empty, Linux-compatible device that can then be used for storing files and data.
Insert your diskette into the drive and issue the following command at a shell prompt:
On Linux systems, /dev/fd0 refers to the first diskette drive. If your computer has more than one floppy disk drive, your primary floppy drive will be /dev/fd0, your second floppy drive will be designated /dev/fd1, and so on.
The mke2fs utility has a number of options. The -c option makes the mke2fs command check the device for bad blocks before creating the file system. The other options are covered in the mke2fs man page.
Once you have created an ext2 file system on the diskette, it is ready to be used with your Red Hat Linux system.