Mounting Filesystems — Part 1 of 2

Today's Linux installation procedures are pretty slick. Even if you are installing Linux for the first time, you probably won't need to do more than take a quick glance at the installation manual, and you'll be up and running in no time. These days, the hard part is not installing Linux, it's getting Linux to do exactly what you want it to after you have installed it.

Figure One: This railroad track diagram shows the syntax of the mount command.

Today’s Linux installation procedures are pretty slick. Even if you are installing Linux for the first time, you probably won’t need to do more than take a quick glance at the installation manual, and you’ll be up and running in no time. These days, the hard part is not installing Linux, it’s getting Linux to do exactly what you want it to after you have installed it.

Most people come to Linux from a different operating system (like MacOS or Windows), and they are used to a certain way of doing things. Because Linux is so different from those systems, making the switch can be somewhat disorienting. One area that particularly trips up new users is the procedure for mounting filesystems — particularly filesystems associated with removable media (such as CD-ROM disks). Since this area is the cause of so much confusion, we’re going to spend this month and next month looking at the whys and hows of mounting filesystems.

Where Are the Drive Letters?

One of the first things users moving from Windows to Linux notice is that there are no drive letters under Linux. “How do I access the a: drive?” and “How do I access the d:drive?” are frequently heard questions. Actually, that’s how the questions start out. After a few hours, they sound more like “How am I supposed to use this stupid thing when it doesn’t even have a d: drive?”

Mounting Filesystems

Drive letters are merely the convention used by MS-DOS and Windows to provide access to filesystems. Filesystems organize the contents of data storage devices, including floppy drives, IDE and SCSI hard drives, and CD-ROM drives. Filesystems also let you create, access, and delete files.

In operating system lingo, the process of making a filesystem available is known as mounting the filesystem. This process generally involves making a quick sanity check of the filesystem’s contents and making an entry in a table that records the identity of each mounted filesystem.

Under Linux, this table is stored in the file /etc/mtab, which can be read by any user but altered by only the root user. Keep in mind, however, that you shouldn’t manually alter the contents of this file in an attempt to mount a filesystem; its contents are maintained by the operating system.

Under MS-DOS and Windows, a mounted filesystem is associated with a drive letter, which is also recorded in a table. However, Linux uses a different approach. Let’s start by looking at how the Linux approach works.

Identifying Filesystems the Linux Way

Linux (and Unix in general) identifies filesystems using a more straightforward and flexible approach than MS-DOS and Windows. Instead of automatically assigning a drive letter to a filesystem during boot up, Linux and Unix let you assign a directory name to a filesystem.

The main difference between MS-DOS/Windows and Linux is that Linux puts you in control. As usual, a burden goes with being in control; but, the flexibility you obtain is worth the small amount of extra expertise and effort required.

For example, suppose you’d like to be able to refer to your floppy drive by the directory name /floppy and to your CD-ROM drive by the directory name /cdrom. Linux lets you do exactly that. If you install, or remove, devices or filesystems, you can easily adjust the Linux configuration so that you can continue to refer to the floppy drive as /floppy and to the CD-ROM drive as /cdrom. The mechanism that implements this useful feature is the mount command. So, let’s take a look at that next.

The mount Command

The mount command is pretty straightforward; it lets you mount a filesystem. To use it, you must generally be logged in as root. This important restriction prevents ordinary users from tampering with the filesystems. As I’ll explain next month, system administrators can selectively allow ordinary users to mount filesystems — if they deem the risk to be acceptable.

Here’s an example mount command:

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

This mounts the filesystem contained on a CD-ROM to the directory /cdrom and ensures that programs will not try to write to the CD-ROM drive.

Okay, there’s no getting around it; at first glance, the mount command looks pretty hairy. But don’t despair. Later in this article, we’ll look at using
linuxconf to mount filesystems; if that’s not enough for you, next month we’ll go over how to use the GNOME desktop to mount filesystems. But it still always helps to understand the basics, so let’s dive into the mount command just for good measure. If your graphical system administration tool is not available, it’s important to know how to use the mount command. Once you get the hang of it, the mount command isn’t all that hard; it works just like other Linux commands.

Figure One shows the general form of the mount command, using what’s known as a railroad track diagram. Think of the diagram as a recipe for constructing syntactically valid mount commands. Start at the left, and take any path through the diagram as directed by the arrows. Ovals contain text that must be typed exactly as shown. Rectangles contain arguments, which I’ll explain in detail. When you reach the right edge of the diagram, your mount command is done.

The argument type tells mount what type of filesystem you are mounting. This argument is optional, as indicated by the path that bypasses the argu-ment. Some of the more commonly used values are:

  • ext2, the standard Linux filesystem. If you omit the type argument, the filesystem is assumed to be an ext2 filesystem.
  • iso9660, the standard filesystem used for CD-ROMs.
  • msdos, the standard filesystem used by MS-DOS.
  • vfat, the standard filesystem used by Windows 3.x and 9x. This filesystem type also supports the vfat32 filesystems used by Windows 9x.

The argument device specifies the device file associated with this filesystem. This argument is required, as indicated by the absence of a bypass. Examples of some device files are:

  • /dev/fd0, the primary floppy drive
  • /dev/fd1, the secondary floppy drive
  • /dev/hda1, the first partition of the primary IDE hard drive
  • /dev/hda2, the second partition of the primary IDE hard drive
  • /dev/hdb1, the first partition of the secondary IDE hard drive
  • /dev/hdb, the secondary IDE device, which is often a CD-ROM drive
  • /dev/cdrom, often configured to refer to the CD-ROM drive
  • /dev/sda1, the first partition of the SCSI device having ID 1
  • /dev/sdb1, the first partition of the SCSI device having ID 2

The argument directory specifies the directory name that will be given to the mounted filesystem (this is also commonly referred to as the mount point). You must create this directory before issuing the mount command. This argument is required, as indicated by the absence of a way to bypass it (See Figure One, pg. 24).

Finally, the argument options lets you specify how the filesystem is mounted. This argument is optional, as indicated by the path that bypasses the argument. Some commonly used values are:

  • ro, which specifies that the filesystem can be read from but cannot be written to. Note that this option should always be specified for CD-ROM filesystems.
  • rw, which specifies that the filesystem can be both read from and written to.

When you’re done using a filesystem, you should unmount it. As you have probably guessed, there’s a unique way to do that under Linux. So, let’s check it out.

The umount Command

The umount command lets you unmount a filesystem (this is something you don’t really need to do under MS-DOS or Windows, but there are actually good reasons for it, as we’ll see). Once a filesystem is unmounted, it can’t be accessed or modified. So, unmounting a filesystem is one way to preserve its contents.

When using removable media, you should unmount the filesystem before removing the media. Doing so ensures that all your changes are properly written. If you remove the media without unmounting the filesystem, the filesystem may become corrupted. Windows doesn’t care whether you corrupt your filesystems or not, so you can yank your disks out any time.

To unmount a filesystem, issue the command:

umount dir

where dir is the mount point of the filesystem. For example, the command:

umount /floppy

unmounts the file system mounted as /floppy. If you prefer, you can unmount a filesystem by specifying its associated device file:

umount device

where device is the device file associated with the filesystem that you are unmounting. For example, the command:

umount /dev/hdb1

unmounts the filesystem associated with the device file /dev/hdb1 (which happens to represent a partition on your hard disk).

Generally, you must be logged in as root to unmount a filesystem. Moreover, you cannot unmount a filesystem that is active. For example, if a file that resides on the filesystem is open, that filesystem cannot be unmounted. Similarly, running a program that resides on the filesystem prevents the filesystem from being unmounted.

The most common problem that you will probably run into when trying to unmount a filesystem is attempting to unmount a filesystem that contains the current working directory. To avoid this error, always make sure that you cd to a directory that is outside the filesystem before attempting to unmount the filesystem.

Okay, now that we’ve done this the hard way (using the mount and umount commands to mount and unmount filesystems), let’s see how you can perform these operations by using linuxconf.

Mounting Filesystems Using Linuxconf

If you prefer to use graphical tools rather than the command line, you can mount and unmount filesystems by using linuxconf, a system administration tool compatible with several leading Linux distributions.

To mount or unmount a drive by using linuxconf, log in as the root user and launch the utility by simply issuing the following command:

# linuxconf

The linuxconf screen should now appear; its contents will vary depending on whether or not you are running X. Select Control->Mount/Unmount File Systems->Control Configured Local Drives. Under X, you can do so by clicking the tree control in the left pane of the linuxconf window. If you are not running X, you can use the TAB key to navigate the tree control and the ENTER key to select an item.

Newbies linuxconf
Figure Two: If you don’t like to use the command line, you can mount and unmount using the linuxconf utility.

The right-hand pane of the linuxconf window should display the “Control Configured Local Drives” screen, as shown in Figure Two. Each row describes one filesystem. The left column indicates the device file, and the adjacent column indicates the mount point. The right column indicates whether the filesystem is currently mounted. Other columns indicate the type, size, and partition type of each mounted filesystem.

To mount a filesystem when running linuxconf under X, simply click on the filesystem. If you’re not running under X, use the TAB key to highlight the desired filesystem and press ENTER. A dialog box asks you to confirm the operation. Select OK to mount the filesystem.

To unmount a filesystem, select a mounted filesystem by clicking it or by using the TAB and ENTER keys. A dialog box asks you to confirm the operation. Select OK to unmount the filesystem.

Depending on your system configuration, you may want to mount a filesystem that’s not listed by linuxconf. Don’t fret; this problem is easily solved. However, we’re out of space, and so the solution must wait until next month’s column.


Next month, we’ll wrap up this topic by explaining how to mount filesystems not listed by linuxconf. We’ll also explain how to use a desktop manager (such as GNOME or KDE) to mount filesystems.

As a bonus, we’ll even look at the /etc/fstab configuration file, which lets you configure filesystems to be automatically mounted at system startup, and lets you authorize ordinary users to mount and unmount selected filesystems. Until then, have fun playing with mount!

The autofs Service

The autofs service lets you configure filesystems so that they’re automatically mounted when accessed. The autofs service also automatically unmounts configured filesystems after they’ve been unused for a specified period of time. You can obtain this service by installing the autofs package available for most Linux distributions. You’ll need to configure the service by revising the file /etc/auto.master. You’ll also usually need to configure the file /etc/auto.misc as well. To learn how to configure the service, consult the following manpages:

  • automount
  • autofs
  • auto.master

How MS-DOS and Windows Mount Filesystems

MS-DOS and Windows take a rather simplistic approach to mounting filesystems. They scan for devices that support filesystems and sequentially assign a drive letter to each filesystem as it is found. The most intelligent thing that Windows does during this assignment processes is that it skips drive letter b: when only a single floppy drive is found, thus ensuring that the filesystem on the active (bootable) hard disk partition is always assigned the drive letter c: .

If you’ve repartitioned your hard disk or installed a new hard disk, you’ve possibly run into some of the limitations inherent in this approach. Drive letters are not assigned to filesystems indefinitely; when you boot the system, the drive letter assigned to a filesystem can change if new filesystems are found or existing filesystems are not found. Here’s the rub; the result of a changed drive letter can be catastrophic, because many Windows system registry entries include drive letters. After repartitioning your hard disk, installing a new hard disk, or even removing a hard disk, you may find that applications no longer operate properly. In some cases, your system may even refuse to boot up. In all fairness, there are utilities that can help you adjust the registry to compensate for such changes. And Windows NT/200 uses a much more sophisticated approach.

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

Comments are closed.