4.2. Mounting and FilesystemsWe 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 CommandLet'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 CommandBefore 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) FileMany 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
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.
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 PointUntil 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
We can now mount a floppy disk by just entering mount /floppy. 4.2.4.2. Automatically Mounting FilesystemsWe 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
Now, whenever you insert a CD-ROM, it will be mounted automatically. |