Managing the File System
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.
Mounting a Device on the File System
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: Mounting Devices on the Red Hat Linux File System.
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.
You can use the mount command to manually mount a device on the Red Hat Linux file system at a specified directory. That directory is the mount point. For example, to mount the CD-ROM drive at /mnt/cdrom directory, you would type the following command (after logging in as root ):
mount /dev/cdrom /mnt/cdrom
The mount command reports an error if the CD-ROM device is mounted already or if no CD-ROM is in the drive. Otherwise, the mount operation succeeds, and you can access the CD-ROM's contents through the /mnt/cdrom directory.You can use any directory as the mount point. If you mount a device on a nonempty directory, however, you cannot access the files in that directory until you unmount the device by using the umount command. You should always, therefore, use an empty directory as the mount point.Red Hat Linux comes with the /mnt/cdrom directory for mounting CD-ROMs and /mnt/floppy for mounting floppy drives. If you have a Zip drive, the installation program detects that drive and creates a /mnt/zip directory as the mount point for the Zip drive.
To unmount a device when you no longer need it. use the umount command. For example, to unmount the CD-ROM device, type:
umount /dev/cdrom
The umount command succeeds as long as no one is using the CD-ROM. If you get an error when trying to unmount the CD-ROM, check to see if the current working directory is on the CD-ROM. If you are currently in one of the CD-ROM's directories, that also qualifies as a use of the CD-ROM.
Examining the /etc/fstab File
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.
The Linux operating system uses the contents of the /etc/fstab file to mount various file systems automatically. During Red Hat Linux startup, the init process executes a shell script that runs the mount -a command. That command reads the /etc/fstab file and mounts all listed file systems (except those with the noauto option). The fourth field on each line of the /etc/fstab file shows a comma-separated list of options that apply to a specific device. Typically, you find the defaults option in this field. The defaults option implies-among other things-that the device mounts at boot time, that only root can mount the device, and that the device mounts for reading and writing. If the options include noauto , the device doesn't mount automatically as the system boots. The kudzu option in the fourth field of /etc/fstab entries indicates that these lines were added to the fstab file by the kudzu hardware detection utility-kudzu runs the updfstab command to add entries in the /etc/fstab file for each removable drive that it detects. You typically find that the entries for CD-ROM (/dev/cdrom ) and floppy drive (dev/fd0 ) have the kudzu option in the fourth field. On a PC with a IDE Zip drive, for instance, the /etc/fstab file has another entry set up by kudzu that associates the /mnt/zip mount point with the Zip drive device (/dev/hdd4 ), as follows:
/dev/hdd4 /mnt/zip auto noauto,owner,kudzu 0 0
Mounting a DOS/Windows File System
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. mount command.

Figure 12-8: Mounting a DOS/Windows FAT Partition on the /dosc Directory.
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 (/ ).
Mounting DOS Floppy Disks
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:
ls /mnt/floppy
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:
umount /dev/fd0
You can set up your Red Hat Linux system so that any user can mount a DOS floppy. To enable any user to mount a DOS floppy in the A drive on the /a directory, for example, perform the following steps:
Log in as root .
Create the /a directory (the mount point) by typing the following command in a terminal window:mkdir /a
Edit the /etc/fstab file in a text editor (such as vi or Emacs), insert the following line and then save the file and quit the editor:/dev/fd0 /a vfat noauto,user 0 0
If a line already exists for /dev/fd0 , simply edit that line to match what is shown previously. The first field in that line is the device name of the floppy drive (/dev/fd0 ), the second field is the mount directory (/a ), and the third field shows the type of file system (vfat ). The user option (which appears next to noauto ) is what enables all users to mount DOS floppy disks.
Log out and log in as a normal user.
To confirm that you can mount a DOS floppy as a normal user and not just as root, insert a DOS floppy in the A drive and type the following command:mount /a
The mount operation should succeed, and you should see a listing of the DOS floppy when you type the command ls /a .
To unmount the DOS floppy, type umount /a.
Mounting an NTFS Partition
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.
If you have installed Red Hat Linux on a Windows XP system and want to access files on the NTFS partition, you can download a ready-to-run version of the NTFS kernel module from the Linux NTFS Project at http://linux-ntfs.sourceforge .net/info/redhatl . Look for your version of Red Hat Linux, your kernel version (type uname -r to see your kernel version), and then download the RPM file for that version. The file you want has a name of the following form: kernel-ntfs- <VERSION >.i686.rpm , where <VERSION > is replaced by your kernel version number.After downloading the file, log in as root , and type the following command to install the NTFS kernel module:
rpm -Uvh kernel-ntfs*.rpm
Load the module with the following command:
modprobe ntfs
Create a mount point for the NTFS partition. For example, you might create a mount point in the /mnt directory with the following command:
mkdir /mnt/windows
Now, you can mount the NTFS partition with the following command:
mount /dev/hda2 /mnt/windows -t ntfs -r -o umask=0222
Replace /dev/hda2 with the device name for the NTFS partition on your system. On most PCs that come with Windows XP preinstalled, the NTFS partition is the second one (/dev/hda2 )-the first partition (/dev/hda1 ) is a hidden partition used to hold files used for Windows XP installation.