The file system refers to the organization of files and directories. As a system administrator, you have to perform certain operations to manage the file system. For example, you have to learn how to mount-add a file system on a storage medium to the overall Red Hat Linux file system. You also need to back up important data and learn how to restore files from a backup. Other file system operations include sharing files with the Network File System (NFS) and accessing MS-DOS files. Chapter 7 introduces you to the Red Hat Linux file system, Chapter 20 describes how to back up and restore files, and Chapter 19 covers NFS. The next few sections explain how to mount file systems, and specifically, how to access DOS files in Linux.
The storage devices that you use in Red Hat Linux contain Linux file systems. Each device has its own local file system, consisting of a hierarchy of directories. Before you can access the files on a device, you have to attach the device's directory hierarchy to the tree that represents the overall Red Hat Linux file system.
Mounting is the operation that you perform to cause the file system on a physical storage device (a hard-disk partition or a CD-ROM) to appear as part of the Linux file system. Figure 12-7 illustrates the concept of mounting.
Figure 12-7 shows each device with a name that begins with /dev. For example, /dev/ cdrom is the CD-ROM drive and /dev/fd0 is the floppy drive. These physical devices are mounted at specific mount points on the Red Hat Linux file system. For example, the CD-ROM drive, /dev/cdrom, is mounted on /mnt/cdrom in the file system. After mounting the CD-ROM in this way, the RedHat directory on the CD-ROM appears as /mnt/ cdrom/RedHat in the Red Hat Linux file system.
The mount command has the following general format:
mount device-name mount-point
However, you can mount the CD-ROM by typing one of the following commands:
mount /dev/cdrom mount /mnt/cdrom
You can mount by specifying only the CD-ROM device name or the mount point name because of what's in a file named /etc/fstab. There is a line in the /etc/fstab file for the /mnt/cdrom mount point. That entry specifies the CD-ROM device name and the file system type. That's why you can mount the CD-ROM with a shorter mount command.
The /etc/fstab file is a configuration file-a text file containing information that the mount and umount commands use. Each line in the /etc/fstab file provides information about a device and its mount point in the Red Hat Linux file system. Essentially, the /etc/fstab file associates various mount points within the file system with specific devices, which enables the mount command to work from the command line with only the mount point or the device as argument.
Here is a /etc/fstab file from a typical Red Hat Linux system:
LABEL=/ / ext3 defaults 1 1 LABEL=/boot /boot ext3 defaults 1 2 none /dev/pts devpts gid=5,mode=620 0 0 none /proc proc defaults 0 0 none /dev/shm tmpfs defaults 0 0 /dev/hda6 swap swap defaults 0 0 /dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0 /dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0
The first field on each line shows a device name, such as a hard-disk partition (or it identifies a partition by a LABEL keyword). The second field is the mount point, and the third field indicates the type of file system on the device. You can ignore the last three fields for now.
This /etc/fstab file shows that the /dev/hda6 device (the second logical partition on the first IDE hard disk) functions as a swap device for virtual memory, which is why both the mount point and the file system type are set to swap.
If you have Microsoft Windows 95/98/Me installed on your hard disk, you've probably already mounted the DOS partition under Red Hat Linux. If not, you can easily mount DOS partitions in Red Hat Linux. Mounting makes the DOS directory hierarchy appear as part of the Linux file system. To identify the DOS partitions easily, you may want to mount the first DOS partition as /dosc, the second one as /dosd, and so on.
To determine whether your DOS hard disk partitions are set up to mount automatically, type the following grep command to look for the string vfat in the file /etc/fstab:
grep vfat /etc/fstab
If the output shows one or more lines that contain vfat, your Red Hat Linux system mounts DOS/Windows hard-disk partitions automatically.
If the grep command doesn't show any lines that contain the string vfat in /etc/fstab, your system is not set up to mount any DOS/Windows hard-disk partitions automatically. Of course, a very good reason may be that your hard disk doesn't have any DOS partitions.
Even if you don't have any DOS partitions on your hard disk, you should learn how to access a DOS file system from Red Hat Linux because you may need to access a DOS floppy disk on your Red Hat Linux system.
To mount a DOS hard disk partition or floppy, use the mount command but include the option -t vfat to indicate the file system type as DOS. For example, if your DOS partition happens to be the first partition on your IDE drive and you want to mount it on /dosc, use the following mount command:
mount -t vfat /dev/hda1 /dosc
The -t vfat part of the mount command specifies that the device you mount-/dev/ hda1-has an DOS/Windows file system. Figure 12-8 illustrates the effect of this mount command.
Figure 12-8 shows how directories in your DOS partition map to the Linux file system. What was the C:\DOS directory under DOS becomes /dosc/dos under Red Hat Linux. Similarly, C:\WINDOWS now is /dosc/windows. You probably can see the pattern. To convert a DOS filename to Linux (when you mount the DOS partition on /dosc), perform the following steps:
Change the DOS names to lowercase.
Change C:\ to /dosc/.
Change all backslashes (\) to slashes (/).
Just as you mount a DOS hard disk partition on the Red Hat Linux file system, you can also mount a DOS floppy disk. You must log in as root to mount a floppy, but you can follow the steps shown in the latter part of this section to set up your system so that any user can mount a DOS floppy disk. You also need to know the device name for the floppy drive. By default, Linux defines the following two generic floppy device names:
/dev/fd0 is the A drive (the first floppy drive).
/dev/fd1 is the B drive (the second floppy drive, if you have one).
As for the mount point, you can use any empty directory in the file system as the mount point, but the Red Hat Linux system comes with a directory, /mnt/floppy, specifically mounting a floppy disk.
To mount a DOS floppy disk on the /mnt/floppy directory, put the floppy in the drive and type the following command:
mount -t vfat /dev/fd0 /mnt/floppy
After you mount the floppy, you can copy files to and from the floppy by using Linux's copy command (cp). To copy the file gnome1.pcx from the current directory to the floppy, type the following:
cp gnome1.pcx /mnt/floppy
Similarly, to see the contents of the floppy disk, type the following:
If you want to remove the floppy disk from the drive, first unmount the floppy drive. Unmounting removes the association between the floppy disk's file system and the mount point on the Red Hat Linux file system. Use the umount command to unmount the floppy disk like this:
Nowadays, many PCs come installed with Windows XP or Windows 2000. Both Windows XP and 2000, as well as Windows NT, often use the NT File System (NTFS). Linux supports read-only access to NTFS partitions, but Red Hat does not come with the kernel module needed to support NTFS.