When Linux starts, it automatically mounts the file systems specified in the file /etc/fstab. By revising this file, you can customize the operation of your system.
When you install Linux, the installation program configures the file /etc/fstab to specify what filesystems are to be mounted when the system is started. Here's a typical /etc/fstab file:
# /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> /dev/hda2 / ext2 defaults 0 1 /dev/hda3 none swap sw 0 0 proc /proc proc defaults 0 0
The first three lines, those beginning with a hash mark (#), are comments that are ignored by the system; they merely help human readers identify and understand the file. The next three lines each specify a filesystem to be mounted at system startup. Six columns of information appear:
- Filesystem
-
The device that contains the filesystem.
- Mount point
-
The system directory that will hold the filesystem.
- Filesystem type
-
Specifies the type of the filesystem. Popular types include:
- ext2
-
the standard Linux filesystem
- swap
-
the standard Linux swap filesystem
- proc
-
a special filesystem provided by the kernel, used by system components to obtain system information in a standard way
- iso9660
-
the standard filesystem used on CD-ROM
- msdos
-
the standard MS-DOS filesystem
See the man page for mount for other filesystem types.
- Mount options
-
Specifies the options given when the filesystem is mounted. If multiple options are given, each is separated from the next by a comma (,); no spaces appear within the list of options. Popular options include:
- defaults
-
Specifies a series of options appropriate for most filesystems. For details, see the man page for mount.
- errors=remount-ro
-
Specifies that if errors are found when the filesystem is checked, the filesystem will be remounted in read-only mode so that the system administrator can analyze the errors without risking further damage.
- sw
-
Specifies that the filesystem will be mounted as a swap partition.
- ro
-
Specifies that the filesystem will be mounted for read access only. This option is always specified for CD-ROM devices and may be specified for other devices.
- noauto
-
Specifies that the filesystem will not be automatically mounted at system startup.
In addition, the user option can be specified. This option allows any user - not only root
- to mount the filesystem.
- Dump flag
-
Specifies whether the dump command will create a backup of the filesystem. Filesystems with no value or a value of zero will not be dumped.
- Pass
-
Specifies the order in which filesystems are checked at boot time. No value or a value of zero specifies that the filesystem will not be checked.
You can modify the lines within the /etc/fstab file and add new lines as you see fit. For example, here's a line that specifies a CD-ROM drive:
/dev/cdrom /cdrom iso9660 ro
By adding this file to the /etc/fstab file, you instruct the system to mount the CD-ROM filesystem when the system starts. If you don't want the filesystem automatically mounted, you can specify this line:
/dev/cdrom /cdrom iso9660 ro,noauto
The system will not automatically mount the CD-ROM filesystem described by this line, but you can mount the CD-ROM by using the mount command. Because the system already knows the device, mount point, filesystem type, and options, you can abbreviate the mount command to:
mount /cdrom
or:
mount /dev/cdrom
Either of these is equivalent to:
mount -t iso9660 -o ro /dev/cdrom /cdrom
You can automatically mount additional hard disk partitions by describing them in the /etc/fstab file:
/dev/hdb1 /home ext2 defaults
Another tip is to use an entry in the /etc/fstab file to allow users other than root
to mount a floppy disk:
/dev/fd0 /floppy auto noauto,user
Just as you can use the mount and unmount commands to explicitly mount and unmount filesystems, you can control the operation of swap partitions by using the swapoff and swapon commands.
If you want to modify your swap partition, you may need to temporarily turn off swapping. To do so, enter the command:
swapoff -a
This command turns off swapping on every swap device mentioned in /etc/fstab. If you want to turn off swapping on a particular device, enter the command:
swapoff /dev/ device
where device
specifies the swap device; for example, hda3.
To turn on swapping, enter the command:
swapon -a
This command turns on swapping for all swap devices mentioned in /etc/fstab. If you want to turn on swapping on a particular device, enter the command:
swapon /dev/ device
where device
specifies the swap device; for example, hda3.