-->
Previous | Table of Contents | Next |
File systems are not available until they are mounted onto the Linux main file system. Even hard drives must be mounted, because only the root file system is available in the / directory until the rest are mounted. The mount command is used to mount a file system.
During the boot process, the mount command is used from the startup files (such as the /etc/rc file or files under the /etc/rc.d directory) to mount all the file systems maintained in the file /etc/fstab. You can look at the file to see the type of information maintained there. Every file system that is mounted during the boot process has an entry giving its device name, its mount directory (called the mount point), the type of file system it is, and any options that apply.
You can add a new file system from a hard disk, a CD-ROM, a floppy, or any other type of device that provides a file system supported by Linux, using the mount command. The format is as follows:
mount filesystem mountpoint
filesystem is the name of the device and mountpoint is where in the Linux file system it should be mounted. For example, if you want to mount a SCSI CD-ROM to the file system as /usr/cdrom, issue the following command:
mount /dev/cd0 /usr/cdrom
The directory /usr/cdrom must be created before the command is given, or the mount command generates an ambiguous error. You should replace /dev/cd0 with the name of your CD-ROM device driver (/dev/cd0 for most non-SCSI CD-ROM drives and /dev/cd0 for SCSI CD-ROM drives). When the file system is mounted properly, changing to /usr/cdrom lets you access all the files on the CD-ROM as if they were part of the normal file system.
If your /etc/fstab file doesnt have any entries in it already, you have to mount the file system with a slightly different syntax:
mount -t fstypefilesystem mountpoint
fstype is the type of file system (such as ISO9660, MSDOS, and so on). The rest of the arguments are the same as the example above. The -t option is used when the file system to be mounted doesnt already have an entry in the /etc/fstab file.
You can mount a floppy disk with a command similar to the one in the CD-ROM example just discussed. To mount a floppy in the first floppy drive on the directory /mnt, issue the following command:
mount /dev/fd0 /mnt
Most floppy drive device names start with fd to make it clear which kind of device they are (just like most hard disks start with hd). If the file system is not the default value used by Linux, the type of file system must be specified. For example, to mount a floppy using the ext2 file system, use the -t option of the mount command:
mount -t ext2 /dev/fd0 /mnt
To create a file system on a floppy (so it can be mounted), you should use the utility mke2fs or the command mkdev fs, depending on the version of Linux. To use mke2fs, for example, issue the following command to create a floppy file system on a 1.44MB 3.5-inch disk:
mke2fs /dev/fd0 1440
To detach a mounted file system from your Linux file system, use the umount command with the name of the device. For example, to unmount a floppy in /dev/fd0, issue the following command:
umount /dev/fd0
The floppy is removed from the mounted point. Be sure to type umount instead of unmount!
If you want to remove the current floppy and replace it with another, you cant simply swap them. The current floppy must be unmounted and then the new one must be mounted. Failure to follow this process can result in corruption or erroneous directory listings.
Every now and again a file might get corrupted or a file systems inode table might get out of sync with the disks contents. For these reasons, it is a good idea to check the file system at regular intervals. Several utilities can check file systems, depending on the version of Linux. The utility fsck is available for some systems, while the utility e2fsck is designed for Linuxs ext2fs file system. Many Linux versions include other utilities such as xfsck and efsfck for different file systems. In many cases, the fsck command is linked to the individual file system versions.
To use e2fsck to check a file system, issue the command with the device name and the options a (automatically correct errors) and v (verbose output):
e2fsck -av /dev/hda1
This command checks and repairs any problems on the /dev/hda1 (or whatever device driver you specify) partition. If any corrections are made to a partition, you should reboot the machine as soon as possible to allow the system to resync its tables.
Whenever possible, it is a good idea to unmount the file system before checking it, because this can prevent problems with open files. Of course, you cant unmount the primary root partition while running from it, but you can boot from a boot floppy which contains the check utilities and start them from the floppy.
Previous | Table of Contents | Next |