8.4. The /etc/fstab File

The /etc/fstab file makes it possible to automate the mounting of certain file systems, especially at system startup. It contains a series of lines describing the file systems, their mount points and other options. Here is an example of an /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:

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. As to /proc, we will return to it in greater detail in "The /proc filesystem". An other special filesystem is /dev/pts.

Let's get back to the subject. You moved the whole /usr hierarchy to /dev/hdb1 and so you want this partition to be mounted as /usr 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 file system should not be mounted at startup but is to be mounted only when you tell it to. The user option specifies that any user can mount and unmount the filesystem. These two options are typically used for the CD-ROM drive and floppy drive. There are other options, and /etc/fstab even has its own man page (fstab(5)).

Not least of the advantages of this file is that it simplifies the mount command syntax. To mount a file system referenced in it, you can either reference the mount point or the device. 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 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 goal). To do so, you first need to go to single user mode (by issuing the telinit 1 command on the command-line), and then:

and that's it. Now, go back to multiuser mode (telinit 3 or telinit 5), and 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. 2001.
http://www.mandrakelinux.com/