9.4. The /etc/fstab file

The /etc/fstab file makes it possible to automate mounting of certain filesystems, especially at system startup. It contains a series of lines describing the filesystems, their mount points and other options. Here is an example of a /etc/fstab file:

/dev/hda1   /           ext2    defaults        1 1
/dev/hda5   /home       ext2    defaults        1 2
/dev/hda6   swap        swap    defaults        0 0
/dev/fd0    /mnt/floppy auto    sync,user,noauto,nosuid,nodev,unhide 0 0
/dev/cdrom  /mnt/cdrom  auto    user,noauto,nosuid,exec,nodev,ro 0 0
none        /proc       proc    defaults        0 0
none        /dev/pts    devpts  mode=0622       0 0

A line contains, in order:

Surprise, surprise, there is always an entry for the root filesystem. The swap partitions are special since they are not visible in the tree structure, and the mount point field for these partitions contains the keyword swap. We will return to /proc in greater detail.

Let's get back to the subject. You have moved the whole /usr hierarchy to /dev/hdb1 and so you want this partition to be mounted at boot time. In that case you need to add an entry to the file:

/dev/hdb1 /usr ext2 defaults 1 2

Now the partition will be mounted at each boot. It will also be checked if necessary.

There are two special options: noauto and user. The noauto option specifies that the filesystem should not be mounted at startup but is to be mounted explicitly. The user option specifies that any user can mount and unmount the filesystem. As you can see, these two options are logically used for the CDROM drive and floppy drive. There are other options, and /etc/fstab even has its own manual page: man 5 fstab.

Last but not least of the advantages of this file is that it simplifies the mount command syntax. To mount a filesystem referenced in it, you can either reference the mount point or the device. So, to mount a floppy disk, you can type:

$ mount /mnt/floppy

or:

$ mount /dev/fd0

To finish with our example of moving a partition: we have copied the /usr hierarchy and completed /etc/fstab, so that the new partition is mounted at startup. But for the moment the old /usr files are still there! We therefore need to delete them to free up space (which was, after all, our initial aim). To do this, you need to:

and you are finished. If there is no further administrative work left, you should now log off the root account.


Tux on Star from MandrakeSoft Linux is a registered trademark of Linus Torvalds. All other trademarks and copyrights are the property of their respective owners.
Unless otherwise stated, all the content of these pages and all images are Copyright MandrakeSoft S.A. and MandrakeSoft Inc. 2000.
http://www.linux-mandrake.com/