Section 4.2. Mounting and Filesystems


4.2. Mounting and Filesystems

We briefly touched on the concepts of devices, mount points and filesystems in Chapter 2. In Linux, when we insert removable media of any kind, we need to mount the filesystem stored on that media device. This concept is fairly unfamiliar to Windows users, but once you get the hang of it, it becomes second nature. In fact, Windows does the same thing; the difference is simply that the Windows operating system automates the mounting process, so users are usually unaware that it takes place. Nautilus largely automates this process, too, but it's still important for system administrators to know how devices are mounted, and how mounting is accomplished from the command line.

4.2.1. Mounting a Filesystem with the mount Command

Let's look at the process of mounting a floppy disk from the command line:

[kermit@swinetrek ~]$ su Password: [root@swinetrek kermit]# mount -t vfat /dev/fd0 /media/floppy [root@swinetrek kermit]# exit exit [kermit@swinetrek ~]$ 

The mount command loads a device's filesystem into our server's filesystem. In this case, the device is the floppy disk drive (/dev/fd0), and that device's filesystem is loaded into /media/floppythe mount point. We also need to tell Linux what kind of filesystem is can expect to find on the device. In this case, we're using a disk formatted as FAT32, and we've specified this with -t vfat.

Let's take a closer look at what's going on here. We're using a floppy disk from an old Windows machine; a couple of directories are stored on the disk, as shown in Figure 4-11.

Figure 4-11. Viewing the floppy disk's filesystem in Windows.


As we saw in Chapter 2, there is no A: drive in Linux; removable media devices appear as part of the filesystem within the /media directory. So, when we mount the floppy disk, it appears inside the /media/floppy directory, as depicted in Figure 4-12.

Figure 4-12. The floppy disk's filesystem displaying as part of the Linux filesystem.


4.2.2. Unmounting a Filesystem with the umount Command

Before removing the floppy disk, we should unmount it, thereby removing it from the filesystem. We can do so using the umount commandnote the missing "n"as shown below.

[kermit@swinetrek ~]$ umount /media/floppy [kermit@swinetrek ~]$ 

For some devices, the unmounting process is very important. A floppy disk is a good example of this. It can take a long time to save a file to a floppy disk; the unmounting process ensures that any programs that are writing to the disk complete their writes before the device is removed.

4.2.3. The Filesystem Table (fstab) File

Many of the configuration options for your server's filesystem are contained in a single text file, /etc/fstab. As this file is critical to the operation of your system, the file is owned by root and only root can write to the file. That ownership and permissions structure prevents any potentially catastrophic alteration to, or deletion of the file by non-root users. It's strongly advised that you refrain from adjusting these permissions, and treat the file with the respect it deserves when logged in as root.


Tip: There are numerous ways to edit a text file as root. Perhaps the easiest is to launch your preferred text editor from the command line after switching to the root user. The text editor will run as if you were logged in as root, but GNOME will insist on returning to the terminal an ugly looking warning message:There's absolutely no problem with using this approach to edit files. Kate, gedit, or the text editor of your choice will run without a problem. However, if you'd prefer to get rid of this warning, Bruce Wolk suggested the following script as a solution in the newsgroup linux.redhat.Save this file as xroot.sh in a directory named bin inside your home directory. You'll probably need to create this directory yourself, and you'll also need to give yourself execute permissions on this file. You can do so by running chmod u+x ~/bin/xroot.sh, or by changing the file's permissions in Nautilus.Because /home/username/bin is automatically included in the PATH environment variable, you should be able to run this from the command line simply by typing xroot.sh.

fstab, which is an abbreviation of "filesystem table," provides instructions to the operating system as to where devices should be mounted.

The /etc/fstab file will appear similar to the following:

/etc/fstab

 # This file is edited by fstab-sync - see 'man fstab-sync' for # details /dev/VolGroup00/LogVol00 /              ext3   defaults        1 1 LABEL=/boot              /boot          ext3   defaults        1 2 /dev/devpts              /dev/pts       devpts gid=5,mode=620  0 0 /dev/shm                 /dev/shm       tmpfs  defaults        0 0 /dev/proc                /proc          proc   defaults        0 0 /dev/sys                 /sys           sysfs  defaults        0 0 /dev/VolGroup00/LogVol01 swap           swap   defaults        0 0 /dev/fd0                 /media/floppy  auto   pamconsole,exec,                                                noauto,managed  0 0 /dev/hdc                 /media/cdrom   auto   pamconsole,exec,                                                noauto,managed  0 0 


Note: In most Linux configuration files, lines that start with # are comment lines, and are ignored by the operating system.

Each line of /etc/fstab contains five fields which, together, specify the configuration of a single device. Let's look at what each field means.

  1. The first element specifies the device.

    The second line, which starts with LABEL=/boot, is a special casethe label /boot is defined elsewhere in the system. You can treat this as a synonym for /dev/hda1.

  2. The second item identifies the mount point for the device. The last two lines/media/floppy and /media/cdromdefine the mount points for /dev/fd0 (the floppy disk drive) and /dev/hdc (the CD-ROM drive).

    The first line, which deals with the device /dev/VolGroup00/LogVol00 (this is the first partition on the first hard disk), tells the system to mount this disk as the root of the filesystem.

  3. The third element defines the type of filesystem Linux should expect. Here we can see that /dev/VolGroup00/LogVol00 has an ext3 filesystem.

  4. The fourth element lists mounting options for the device and the filesystem. Available options include:


    auto

    This device should be mounted automatically when the system is started.


    noauto

    This device should not be mounted automatically when the system is started.


    owner

    The device and filesystem may only be mounted by the owner of the device file.


    kudzu

    The device will be checked for changes by the Red Hat kudzu system .


    rw

    The filesystem will provide read and write access.


    ro

    The filesystem will provide read only access.

    There are several other options for mounting devices and filesystems, as you can see in the default fstab file, but these are the ones in which we're interested. In our example, many of the options are set to defaults. In a Fedora Core system, this is equivalent to auto,owner,kudzu,rw.

  5. The fifth column is used by the dump backup utility to determine if this filesystem should be included in its backupsthe 0 value tells dump to ignore this filesystem for backup purposes.

  6. The final column indicates whether the filesystem should be checked with the fsck (filesystem check) utility . ext3 filesystems very rarely benefit from such a check. If you do want to perform such checks, you should number the filesystems in the order in which you'd like them checked1 for the first, 2 for the second, and so on.

With a correctly formatted fstab file, using the mount command becomes much easier:

[kermit@swinetrek ~]$ su Password: [root@swinetrek kermit]# mount /media/floppy [root@swinetrek kermit]# exit exit [kermit@swinetrek ~]$ 

Here, we've specified only the mount point. mount is able to look in fstab to identify the device to which this mount point relates.

Whether or not you will be able to mount the device as a normal user depends upon the options noted in fstab, and the permissions on the device file. If the mount point is owned by root, and you attempt to mount a device on it as a normal user, you'll be presented with a Permission denied error.

4.2.4.1. Making a Mount Point

Until now, we've only talked about Fedora Core's conventions for mount points. Other Linux systems use different conventions, in order to make the mount point name slightly more recognizable. SuSE, for example, creates a /floppy mount point when the system is installed, as opposed to Fedora's /media/floppy. The fact that other distributions can use different conventions should tell you that the naming of mount points is not standard, nor should it be. Remember that a mount point is merely another directory on the system. If you're confused by the convention employed by the distribution you're using, use the convention you prefer.

For example, you can use the SuSE convention mentioned above on your Fedora system:

[kermit@swinetrek ~]$ su Password: [root@swinetrek kermit]# mkdir /floppy [root@swinetrek kermit]# exit exit [kermit@swinetrek ~]$ mount -t vfat /dev/fd0 /floppy [kermit@swinetrek ~]$ 

Here, we've mounted the floppy disk's filesystem at a new mount point: /floppy. We can edit fstab to make this change more permanent.

/etc/fstab

 # This file is edited by fstab-sync - see 'man fstab-sync' for # details /dev/VolGroup00/LogVol00 /              ext3   defaults        1 1 LABEL=/boot              /boot          ext3   defaults        1 2 /dev/devpts              /dev/pts       devpts gid=5,mode=620  0 0 /dev/shm                 /dev/shm       tmpfs  defaults        0 0 /dev/proc                /proc          proc   defaults        0 0 /dev/sys                 /sys           sysfs  defaults        0 0 /dev/VolGroup00/LogVol01 swap           swap   defaults        0 0 /dev/fd0                 /floppy        auto   pamconsole,exec,                                                noauto,managed  0 0 /dev/hdc                 /media/cdrom   auto   pamconsole,exec,                                                noauto,managed  0 0 

We can now mount a floppy disk by just entering mount /floppy.

4.2.4.2. Automatically Mounting Filesystems

We can use the auto option in fstab to make the mounting process automatic for some devices. To mount a CD-ROM automatically once it's inserted, change the options listed for /dev/hdc from noauto to auto.

/etc/fstab

 # This file is edited by fstab-sync - see 'man fstab-sync' for # details /dev/VolGroup00/LogVol00 /              ext3   defaults        1 1 LABEL=/boot              /boot          ext3   defaults        1 2 /dev/devpts              /dev/pts       devpts gid=5,mode=620  0 0 /dev/shm                 /dev/shm       tmpfs  defaults        0 0 /dev/proc                /proc          proc   defaults        0 0 /dev/sys                 /sys           sysfs  defaults        0 0 /dev/VolGroup00/LogVol01 swap           swap   defaults        0 0 /dev/fd0                 /media/floppy  auto   pamconsole,exec,                                                noauto,managed  0 0 /dev/hdc                 /media/cdrom   auto   pamconsole,exec,                                                auto,managed    0 0 

Now, whenever you insert a CD-ROM, it will be mounted automatically.




Run Your Own Web Server Using Linux & Apache
Run Your Own Web Server Using Linux & Apache
ISBN: 0975240226
EAN: 2147483647
Year: 2006
Pages: 92

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net