next up previous contents index
Next: Backup Tools Up: Filesystems Previous: Concepts   Contents   Index

Subsections

mount and /etc/fstab

This section describes how to mount a floppy or Zip disk, discusses the /dev directory, and addresses distributing the directory tree over multiple physical devices or partitions.

Mounting a Filesystem

On a GNU/Linux system there's no necessary correspondence between directories and physical devices as there is in Windows, in which each drive has its own directory tree beginning with a letter (such as C:\).

Instead, each physical device such as a hard disk or floppy disk has one or more filesystems on it. In order to make a filesystem accessible, it's assigned to a particular directory in another filesystem. To avoid circularity, the root filesystem (which contains the root directory /) is not stored within any other filesystem. You have access to it automatically when you boot Debian.

A directory in one filesystem that contains another filesystem is known as a mount point. A mount point is a directory in a first filesystem on one device (such as your hard disk) that ``contains'' a second filesystem, perhaps on another device (such as a floppy disk). To access a filesystem, you must mount it at some mount point.

So, for example, you might mount a CD at the mount point /cdrom. This means that if you look in the directory /cdrom, you'll see the contents of the CD. The /cdrom directory itself is actually on your hard disk. For all practical purposes, the contents of the CD become a part of the root filesystem, and when you type commands and use programs, it doesn't make any difference what the actual physical location of the files is. You could have created a directory on your hard disk called /cdrom and put some files in it, and everything would behave in exactly the same way. Once you mount a filesystem, there's no need to pay any attention to physical devices.

However, before you can mount a filesystem or actually create a filesystem on a disk that doesn't have one yet, it's necessary to refer to the devices themselves. All devices have names, which are located in the /dev directory. If you type ls /dev now, you'll see a pretty lengthy list of every possible device you could have on your Debian system. For a summary of some devices, see Table 2.1 on page [*]. A more thorough list can be found on your system in the file /usr/src/linux/Documentation/devices.txt.

To mount a filesystem, we want to tell Linux to associate whatever filesystem it finds on a particular device with a particular mount point. In the process, we might have to tell Linux what kind of filesystem to look for.

Example: Mounting a CD-ROM

As a simple demonstration, we'll go through mounting a CD-ROM, such as the one you may have used to install Debian. You'll need to be root to do this, so be careful; whenever you're root, you have the power to manipulate the whole system, not just your own files. Also, these commands assume there's a CD in your drive; you should put one in the drive now. Then start with the following command:

su
If you haven't already, you need to either log in as root or gain root privileges with the su (super user) command. If you use su, enter the root password when prompted.

ls /cdrom
Use this command to see what's in the /cdrom directory before you start. If you don't have a /cdrom directory, you may have to make one using mkdir /cdrom.

mount
Simply typing mount with no arguments lists the currently mounted filesystems.

mount -t iso9660 CD-device /cdrom
For this command, you should substitute the name of your CD-ROM device for CD-device in the above command line. If you aren't sure, /dev/cdrom is a good guess because the install process should have created this symbolic link on the system. If that fails, try the different IDE devices: /dev/hdc, etc. You should see a message like this: mount: block device /dev/hdc is write-protected, mounting read-only.

The -t option specifies the type of the filesystem, in this case iso9660. Most CDs are iso9660. The next argument is the name of the device to mount, and the final argument is the mount point. There are many other arguments for mount; see the manual page for details.

Once a CD is mounted, you may find that your drive tray will not open. You must unmount the CD before removing it.

ls /cdrom
Confirms that /cdrom now contains whatever is on the CD in your drive.

mount
Displays the list of filesystems again; notice that your CD drive is now mounted.

umount /cdrom
This unmounts the CD. It's now safe to remove the CD from the drive. Notice that the command is umount with no ``n,'' even though it's used to unmount the filesystem.

exit
Don't leave yourself logged on as root. Log out immediately, just to be safe.

/etc/fstab: Automating the Mount Process

The file /etc/fstab (it stands for ``filesystem table'') contains descriptions of filesystems that you mount often. These filesystems can then be mounted with a shorter command, such as mount /cdrom. You can also configure filesystems to mount automatically when the system boots. You'll probably want to mount all of your hard disk filesystems when you boot, so Debian automatically adds entries to fstab to do this for you.

Look at this file now by typing more /etc/fstab. It will have two or more entries that were configured automatically when you installed the system. It probably looks something like this:

# /etc/fstab: static file system information.

#

# <file system> <mount point> <type> <options> #<dump > <pass>

/dev/hda1 / ext2 defaults 0 1

/dev/hda3 none swap sw 0 0

proc /proc proc defaults 0 0

/dev/hda5 /tmp ext2 defaults 0 2

/dev/hda6 /home ext2 defaults 0 2

/dev/hda7 /usr ext2 defaults 0 2

/dev/hdc /cdrom iso9660 ro,noauto 0 0

/dev/fd0 /floppy auto noauto,sync 0 0

The first column lists the device the filesystem resides on. The second lists the mount point, the third indicates the filesystem type. The line beginning by proc is a special filesystem. Notice that the swap partition (/dev/hda3 in the example) has no mount point, so the mount point column contains none.

The last three columns may require some explanation.

The fifth column is used by the dump utility to decide when to back up the filesystem. In most cases, you can put 0 here.

The sixth column is used by fsck to decide in what order to check filesystems when you boot the system. The root filesystem should have a 1 in this field, filesystems that don't need to be checked (such as the swap partition) should have a 0, and all other filesystems should have a 2. It's worth noting that the swap partition isn't exactly a filesystem in the sense that it does not contain files and directories but is just used by the Linux kernel as secondary memory. However, for historical reasons, the swap partitions are still listed in the same file as the filesystems.

Column four contains one or more options to use when mounting the filesystem. You can check the mount manpage for a summary; see section 5.1 on page [*].


Removable Disks (Floppies, Zip Disks, Etc.)

Add the following lines to your /etc/fstab file:

/dev/sda1 /mnt/zip ext2 noauto,user 0 0 

/dev/sda4 /mnt/dos msdos noauto,user 0 0 

From now on, you'll be able to mount the DOS-formatted Zip disks with the command mount /mnt/dos, and you be able to mount Linux-formatted Zip disks with the command mount /mnt/zip.

If you have SCSI hard disks in your system, you'll have to change sda to sdb or sdc in the example above.


next up previous contents index
Next: Backup Tools Up: Filesystems Previous: Concepts   Contents   Index
John Goerzen / Ossama Othman