|< Day Day Up >|| |
Before you can use the files in a directory, you need to mount that directory on a partition formatted to some readable filesystem. Linux normally automates this process using the /etc/fstab configuration file. When you boot Linux, specified directories are mounted on configured partitions. The mount options require some explanation, especially for removable media.
But there may be problems if connections are lost or media is removed. When you configure a server, you could be mounting directories from a number of remote computers. You could also want temporary access to removable media such as floppies or Zip drives. The automount daemon, also known as the Automounter or autofs, can help. It can automatically mount specific directories as needed. It can unmount a directory automatically after a fixed period of time.
Linux stores information about your local and remotely mounted filesystems in /etc/fstab. Open this file in the text editor of your choice. As you can see, different filesystems are configured on each line. A sample /etc/fstab might look like the following:
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 proc tmpfs 0 0 /dev/hda3 swap swap defaults 0 0 LABEL=/usr /usr ext3 defaults 1 2 LABEL=/tmp /tmp ext3 defaults 1 2 LABEL=/var /var ext3 defaults 1 2 LABEL=/home /home ext3 defaults 1 2 /dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0 /dev/floppy /mnt/floppy auto noauto,owner,kudzu 0 0
As you can see, there are six fields associated with each filesystem, which I describe from left to right in Table 4-8. Remember, this is a configuration file. You can verify partitions that are actually mounted in /etc/mtab.
The default filesystem for RHEL 3.
JFS is IBM's journaled filesystem. This is commonly used on IBM enterprise servers.
The Reiser File System is resizable and supports fast journaling. It's more efficient when most of the files are very small and very large. It's based on the concept of 'balanced trees.' While supported by RHEL 3, it is not the default Red Hat filesystem and is explicitly cited only in the RHCT course (RH133) syllabus. For more information, see www.namesys.com.
Developed by Silicon Graphics as a journaling filesystem. Supports very large files; as of this writing, xfs files are limited to 9 x 1018 bytes. Do not confuse this filesystem with the X Font Server; both use the same acronym.
Although defaults is the right mount option for most /etc/fstab filesystems, there are other options, as listed in Table 4-9. If you want to use multiple options, separate them by commas. Don't use spaces between options. The list in Table 4-9 is not comprehensive. You can find out more from the mount manual, which you can read by running the following command:
# man mount
Data is read and written asynchronously.
The inode associated with each file is updated each time the file is accessed.
Searches through /etc/filesystems for the appropriate format for the partition; normally associated with a floppy or removable drive.
Uses default mount options: rw, suid, dev, exec, auto, nouser, and async.
Permits access to character devices such as terminals or consoles and block devices such as drives.
Allows binaries (compiled programs) to be run on this filesystem.
The inode associated with each file is not updated when accessed.
Requires explicit mounting. Common option for CD and floppy drives.
Devices on this filesystem are not read or interpreted.
Binaries (compiled programs) cannot be run on this filesystem so mounted.
Disallows setuid or setgid permissions on this filesystem.
Only root users are allowed to mount the specified filesystem.
Remounts a currently mounted filesystem. Also an option for the mount command.
Mounts the filesystem as read-only.
Mounts the filesystem as read/write.
Allows setuid or setgid permissions on programs on this filesystem.
Reads and writes are done at the same speed (synchronously) on this filesystem.
Allows nonroot users to mount this filesystem. By default, this also sets the noexec, nosuid, and nodev options.
To read floppy disks and other removable media, you need to mount the device. If RHEL detects your hardware, it adds the proper settings to /etc/fstab and default mount points to the /mnt directory. The default mount points are straightforward; for example, floppy disks are mounted on /mnt/floppy, CDs are mounted on /mnt/cdrom. If you're mounting an MS-DOS-formatted floppy, you can do so with the following command:
# mount -t vfat /dev/fd0 /mnt/floppy
The -t switch specifies the type of filesystem (vfat). The device file /dev/fd0 represents the first floppy drive; /mnt/floppy is the directory through which you can access the files on the floppy after mounting.
But the command that you actually need may be simpler. Take a look at your /etc/fstab configuration file. You'll probably see something like the following line:
/dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0
This /etc/fstab line sets the default configuration for the first floppy drive (/dev/fd0). Normally, it's mounted on the /mnt/floppy directory. The format is auto, which means that the mount command searches through the /etc/filesystems configuration file. As long as vfat is part of this file, you do not need to specify the filesystem type. The mount command reads the filesystem on the floppy and mounts it with the correct filesystem automatically. So all you really need to mount the floppy is the following command:
# mount /dev/fd0 /mnt/floppy
But wait-if you know something about /etc/fstab, you know that the device and mount points are effectively linked. If you specify either, mount looks through /etc/fstab for the appropriate device, label, or mount point. Therefore, all you actually need to mount the floppy is either one of the following two commands:
# mount /dev/fd0 # mount /mnt/floppy
Similarly, the device for your CD-ROM is normally /dev/cdrom. To mount an ISO 9660 CD-ROM, run the following command:
# mount -rt iso9660 /dev/cdrom /mnt/cdrom
Now you can read the contents of /mnt/cdrom as if it were a normal filesystem on your system. You don't have to use the /mnt/floppy or /mnt/cdrom directories. They're part of the standard Linux filesystem as a matter of convenience. You can mount a floppy or CD on an empty directory of your choice.
But as with a floppy disk, the actual command that you need is simpler. Take a look at the relevant default line from /etc/fstab:
/dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0
As you can see, iso9660 is already specified as the default CD filesystem, and CDs are mounted as read-only (ro) by default. Therefore, all you actually need to mount the CD is either one of the following two commands:
# mount /dev/cdrom # mount /mnt/cdrom
To unmount a floppy or CD-ROM, use the umount command with the mount point as an argument. Remember, the command is umount, not unmount.
The following commands unmount both our floppy and our CD-ROM:
# umount /mnt/floppy # umount /mnt/cdrom
It is important you unmount floppy disks before removing them. Otherwise, the data that you thought you wrote to the disk might still be in the cache. In that case, you would lose that data.
|On The Job|| |
Here's another example that I think you're unlikely to see on the Red Hat exams. Assume you're working with a Zip drive of 100MB. The device is set as /dev/hdd and formatted as a single partition (/dev/hdd1) with the Linux Native (ext3) filesystem. The directory /mnt/zip was created and an entry added to /etc/fstab. You can now manually mount, unmount, and eject the zip drive with the following commands: # mount /dev/hdd1 /mnt/zip
The command to manually unmount the Zip drive: # umount /dev/hdd1
The command to eject the Zip drive (which automatically unmounts it): # eject /dev/hdd1
Once you run the mount command on a partition, it stays mounted until you unmount it or shut down or reboot your computer. This can cause problems. For example, if you've mounted a floppy and then physically removed the disk, Linux may not have had a chance to write the file to the disk. This situation also applies to Zip or other 'hot-swap' removable drives.
Another example is with mounted NFS directories. If the remote computer fails or the connection is lost, your system may become slow or even hang as it looks for the mounted directory.
This is where the Automounter can help. It relies on the autofs daemon to mount configured directories as needed, on a temporary basis. In RHEL 3, the relevant configuration files are /etc/auto.master and /etc/auto.misc. If you use the Automounter, keep the /misc directory free. Red Hat configures automounts on this directory by default, and they won't work if there are local files or directories stored there.
The standard /etc/auto.master file includes just a series of comments, with one sample command:
# /misc /etc/auto.misc --timeout=60
You can activate the Automounter by activating this command (or adding a similar command). As you should already know as a Linux expert, the pound sign (#) is a comment character. When you delete the #, the command is activated. This command:
Configures automounted filesystems on the /misc directory
Points to /etc/auto.misc for detailed configuration
Sets a timeout of 60 seconds; if the automounted directory is not used or accessed in this time, it is automatically unmounted
You can set up the Automounter on other directories. One popular option is to set up the Automounter on the /home directory. In this way, you can configure user home directories on remote servers, mounted on demand. Users are given access to their home directories upon login, and with the following command in /etc/auto.master, the home directory is automatically unmounted 60 seconds after that user logs off the system:
# /home /etc/auto.home --timeout=60
This works only if you don't have a /home directory on your computer. You'll get a chance to test a variation of this in a lab at the end of this chapter.
Red Hat conveniently provides standard automount commands in comments in the /etc/auto.misc file. It's helpful to analyze this file in detail. I use the default RHEL 3 version of this file. The first four lines are comments, which I skip. The first command is:
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
In RHEL, this command is active by default. In other words, if you have a CD in the /dev/cdrom drive, you can access its files through the Automounter with the ls /misc/cd command. The Automounter accesses it using the ISO9660 filesystem. It's mounted read-only (ro); set user ID permissions are not allowed (nosuid), and devices on this filesystem are not used.
With the command from /etc/auto.master, the CD is unmounted 60 seconds after the last time it's accessed. There are a number of other sample commands in comments. The first command allows you to set up a /misc/linux mount point from a shared NFS directory, /pub/linux, on the ftp.example.org computer.
#linux -ro,soft,intr ftp.example.org:/pub/linux
The next command assumes that the /boot directory is stored on the /dev/hda1 partition. With this command, you don't need to mount /boot when you start Linux. Instead, this command allows you to automount it with the mount /misc/boot command.
#boot -fstype=ext2 :/dev/hda1
The following three commands apply to a floppy disk drive on your computer. The first command searches through /etc/filesystems to try to match what's on your floppy. The last two commands assumes that the floppy is formatted to the Second Extended (ext2) filesystem.
#floppy -fstype=auto :/dev/fd0 #floppy -fstype=ext2 :/dev/fd0 #e2floppy -fstype=ext2 :/dev/fd0
The next command points to the first partition on the third SCSI drive. The 'jaz' at the beginning suggests this is suitable for an Iomega type 'Jazz' drive.
#jaz -fstype=ext2 :/dev/sdc1
Finally, the last command assumes that you want to apply the Automounter to the IDE drive connected as the slave on the secondary controller. The 'removable' at the beginning suggests this is suitable for removable hard drives.
#removable -fstype=ext2 :/dev/hdd
With the possible exception of the floppy commands, you'll probably need to modify these lines before activating them for your own hardware.
Once you've configured the /etc/auto.master and related /etc/auto.misc configuration files, you can activate the Automounter. As it is governed by the autofs daemon, you can activate it with the following command:
# service autofs restart
With the default command in the /etc/auto.misc file, you should now be able to mount a CD on the /misc/cd directory, automatically, just by accessing the configured directory. Once you have a CD in the drive, the following command should work:
# ls /misc/cd
If you were to make /misc/cd your current directory, the Automounter would ignore any timeouts. Otherwise, /misc/cd is automatically unmounted according to the timeout, which according to the command in /etc/auto.master, is 60 seconds.
Exercise 4-2: Configuring the Automounter
In this exercise, you'll test the Automounter. You'll need at least a CD. Ideally, you should also have a floppy disk. But there are some preliminaries. You need to make sure that the autofs daemon is in operation, modify the appropriate configuration files, and then restart autofs. You can then test the Automounter for yourself.
Part of this exercise may be confusing. Where it refers to commands within a configuration file, a pound sign (#) in front indicates it's a comment. If it's on the command line interface, it refers to a command run by the root user, which I've signified in this section with the [root]# prompt. As with other exercises, I'm assuming that you've logged in as the root user.
From the command line interface, run the following command to make sure the autofs daemon is running:
[root]# service autofs start
Open the /etc/auto.master configuration file in a text editor. Modify it if required to include the following line. If there's a pound sign (#) in front of the line, delete it. Save and exit from /etc/auto.master.
/misc /etc/auto.misc --timeout=60
Check the /etc/auto.misc configuration file in a text editor. Make sure it includes the following line (which should already be there by default). Save and exit from /etc/auto.misc.
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
Now restart the autofs daemon. (I know, this isn't the most efficient method, but it's a good habit to check the status of a service.)
[root]# service autofs restart
The Automounter service is now active. Insert a CD into the drive on your computer and when you run the following command, you should see the contents of your CD:
[root]# ls /misc/cd
Run the ls /misc command immediately. You should see the cd directory in the output.
Wait at least one minute, and repeat the previous command. What do you see?
Exercise 4-3: A Floppy Disk and the Automounter (Optional Exercise)
Now that you're more familiar with the Automounter, try using it on a floppy drive. If you don't have a floppy drive, experiment with some of the other commented commands in /etc/auto.misc.
|< Day Day Up >|| |