Mounting Filesystems — Part 2 of 2

In last month's column, we looked at mounting filesystems using either the mount command or Linuxconf. This month, we'll wrap up this two-part series by explaining the etc/ fstab file and how to mount filesystems by using KDE. So, let's boot up and get going.

Newbies KDE Icon
Figure Two: You can use this dialog box to create CD-ROM and floppy disk icons.

In last month’s column, we looked at mounting filesystems using either the mount command or Linuxconf. This month, we’ll wrap up this two-part series by explaining the etc/ fstab file and how to mount filesystems by using KDE. So, let’s boot up and get going.

Dissecting the /etc/fstab File

As we saw last month, you can mount a CD-ROM by issuing a command such as the following:

mount -t iso9660 /dev/cdrom
mnt/cdrom -o ro

If you frequently mount a particular filesystem, typing in all the mount command options gets old pretty fast. So, as you might expect, Linux provides a better way. The mount command has the associated /etc/fstab configuration file. Whenever you issue the mount command, the command checks its configuration file to obtain default options for the filesystem you are mounting. If you properly configure /etc/fstab, mounting a CD-ROM can be as simple as typing the command:

mount /dev/cdrom

Let’s see how this file works. Like most Linux configuration files, /etc/fstab is a plain text file. Figure One shows the contents of a typical /etc/fstab file.

Figure One: A Typical /etc/fstab File

/dev/hda1 /dos msdos defaults 0 3
/dev/hda5 /boot ext2 defaults 1 2
/dev/hda6 / ext2 defaults 1 1
/dev/hda7 swap swap defaults 0 0
/dev/fd0 /mnt/floppy ext2 user,noauto 0 0
/dev/hdc /cdrom iso9660 user,ro,noauto 0 0
none /proc proc defaults 0 0
none /dev/pts devpts gid=5,mode=620 0 0

Each line of the file describes a single filesystem. The description consists of six fields that are separated from other fields by one or more spaces. The first four fields are:

  • Device file, which specifies the device file.
  • Mount point, which specifies the directory where the filesystem should be mounted.
  • Filesystem type, which specifies the type of the filesystem.
  • Mount options, which specifies the options used in mounting.

These fields correspond to the arguments of the mount command (and were explained in detail in last month’s column). When you issue a mount command, the command scans the /etc/fstab file looking for a line that matches the device file or mount point you specified. If it finds such a line, it fills in any information missing from the command by using the information in that line. For example, if you issue the command:

mount /dev/cdrom

and the /etc/fstab contains the lines shown in Figure One, the command works just as though you’d typed the considerably more tedious command:

mount -t iso9660 /dev/cdrom
/cdrom -o user,ro,noauto

In addition to the four fields that correspond to arguments of the mount command, the /etc/fstab file contains two additional fields:

  • Dump flag
  • Check sequence

The dump flag is used by the dump command to determine which filesystems should be included in a backup. Unless you use dump to backup your system, you don’t need to be concerned with the dump flag. The check sequence is used during system boot to determine how to check filesystems. The root filesystem should have a check sequence value of 1. Other Linux filesystems should have a value of 2. Swap partitions and non-Linux filesystems should have a value of 0.

I Think Icon

Desktop managers, such as GNOME and KDE, provide convenient ways to mount filesystems. For example, both KDE and GNOME let you create desktop icons for a CD-ROM or floppy that can be double-clicked to mount, or right-clicked to unmount. In fact, if you’re lucky you already have such icons. If not, here’s how to create them.

First, be sure the filesystem is specified in /etc/fstab and that the user option is specified. Make sure that the directory that serves as the mount point exists. Next, right-click the desktop and select Create New -> CD-ROM Device or Create New -> Floppy Device. The dialog box shown in Figure Two appears. Select the device file and the desired mount point. Click OK. The new icon appears on the desktop. Click it to mount the filesystem; right click it and select Unmount to unmount the filesystem. Notice that you can determine whether the filesystem is mount-ed by inspecting the icon, which changes appearance to indicate the state of the filesystem.

Creating a GNOME Panel Applet

Newbies GNOME Panel
Figure Three: The Drive Mount Settings dialog box.

If you prefer GNOME applets to icons, you can easily create a GNOME panel applet that lets you mount and unmount filesystems. Select Panel -> Add Applet -> Utility -> Drive Mount. The Drive Mount Settings dialog box appears, as shown in Figure Three.

Select the desired icon and mount point and click OK. The drive mount applet appears in the GNOME panel. Simply click the applet to mount or unmount the filesystem.

What Filesystem Is That?

Floppies present a common problem to would-be mounters of filesystems. One floppy disk may contain an ext2 filesystem, whereas another may contain a VFAT filesystem. If you know the filesystem type you can specify it as an argument to the mount command. But if you’re using a desktop icon or panel applet, how would you cope? Do you have to click two times for ext2 and three times for VFAT?

No, the trick is to specify auto as the filesystem type in /etc/fstab. When you attempt to mount a filesystem specified as type auto, Linux automatically probes the filesystem to determine its type. ext2,ISO9660, and several somewhat obscure filesystem types are supported by default. You can specify that additional filesystem types be tried by simply listing them in the file /etc/filesystems.

For example, you might want to add the VFAT filesystem type to your /etc/ filesystems file. The system will then be able to automatically determine the filesystem type of disks containing ext2,ISO9660, and VFAT filesystems.

Never a Dull Moment

There’s certainly much more that can be said about filesystems and mounting them than we have covered here. For instance, there’s the automount daemon, which automatically mounts filesystems when you insert removable media and automatically unmounts filesystems after they have remained idle for a specified period. Of course, there’s always more to say about all of these commands, and we refer you to the man pages for more information about what we’ve covered here. Besides, if we give away all of Linux’s secrets at once, we won’t have anything left to tell you next time.

Special /etc/fstab Options

You may notice that our example /etc/fstab file contains two unfamiliar options — user and noauto . They weren’t explained in last month’s column because they’re generally used only in the /etc/fstab file (rather than with the mount command).

The user option allows users other than root to mount the associated filesystem. Without this option, users attempting to mount a filesystem (even a CD-ROM or floppy) will receive an error message.

The noauto option prevents the system from automatically mounting the associated filesystem when the system boots. It’s especially useful for CD-ROMs and floppies, because a CD-ROM or floppy drive may be empty when the system boots. But, this option can also be associated with a filesystem on a hard disk if you don’t want the filesystem mounted when the system boots.

Bill McCarty is an associate professor at Azusa Pacific University. He can be reached at bmccarty@apu.edu.

Comments are closed.