You are on page 1of 21

/etc/fstab

What is fstab and why it's useful >

fstab is a configuration file that contains information of all the partitions and
storage devices in your computer. The file is located under /etc, so the full
path to this file is /etc/fstab.

/etc/fstab contains information of where your partitions and storage devices


should be mounted and how. If you can't access your Windows partition
from Linux, aren't able to mount your CD or write to your floppy as a
normal user, or have problems with your CD-RW, you probably have a
misconfigured /etc/fstab file. So, you can usually fix your mounting
problems by editing your fstab file.

/etc/fstab is just a plain text file, so you can open and edit it with any text
editor you're familiar with. However, note that you must have the root
privileges before editing fstab. So, in order to edit the file, you must either
log in as root or use the su command to become root.

< Overview of the file >

Of course everybody has a bit different /etc/fstab file because the partitions,
devices and their properties are different on different systems. But the basic
structure of fstab is always the same. Here's an example of the contents of
/etc/fstab:

1
/dev/hda2 / ext2 defaults
1
1
/dev/hdb1 /home ext2 defaults
2
0
/dev/cdrom /media/cdrom auto ro,noauto,user,exec
0

1
/ 0
/dev/fd0 auto rw,noauto,user,sync
media/floppy 0
0
proc /proc proc defaults
0
0
/dev/hda1 swap swap pri=42
0

What does all this gibberish mean? As you see, every line (or row) contains
the information of one device or partition. The first column contains the
device name, the second one its mount point, third its filesystem type, fourth
the mount options, fifth (a number) dump options, and sixth (another
number) filesystem check options. Let's take a closer look at this stuff.

--------------------------------------------------------------------------------------------

< 1st and 2nd columns: Device and default mount point >

The first and second columns should be pretty straightforward. They tell the
mount command exactly the same things that you tell mount when you
mount stuff manually: what is the device or partition, and what is the mount
point. The mount point specified for a device in /etc/fstab is its default
mount point. That is the directory where the device will be mounted if you
don't specify any other mount point when mounting the device.

Like you already learned from the Mounting tuXfile, most Linux distros
create special directories for mount points. Most distros create them under
/mnt, but some (at least SuSE) under /media. As you probably noticed when
looking at the example fstab, I use SuSE's mount points as an example.

What does all this mean? If I type the following command:


$ mount /dev/fd0
... my floppy will be mounted in /media/floppy, because that's the default
mount point specified in /etc/fstab. If there is no entry for /dev/fd0 in my
fstab when I issue the command above, mount gets very confused because it
doesn't know where to mount the floppy.

You can freely change the default mount points listed in /etc/fstab if you're
not satisfied with the defaults your distro has given you. Just make sure the

2
mount point is a directory that already exists on your system. If it doesn't,
simply create it.

Some partitions and devices are also automatically mounted when your
Linux system boots up. For example, have a look at the example fstab above.
There are lines that look like this:

/dev/hda2 / ext2 defaults 1 1


/dev/hdb1 /home ext2 defaults 1 2

As you've learned, these lines mean that /dev/hda2 will be mounted to / and
/dev/hdb1 to /home. This is done automatically when your Linux system
boots up... if it wouldn't, you'd have a hard time using your cool Linux
system because all the programs you use are in / and you wouldn't be able to
run them if / wasn't mounted! But how does the system know where you
want to mount /dev/hda2 and /dev/hdb1? By looking at the /etc/fstab file of
course.

< 3rd column: Filesystem type >

The third column in /etc/fstab specifies the filesystem type of the device or
partition. Many different filesystems are supported but we'll take a look at
the most common ones only.

ext2 and ext3 Very likely your Linux partitions are Ext3. Ext2 used to be
the standard filesystem for Linux, but these days, Ext3 and ReiserFS are
usually the default filesystems for almost every new Linux distro. Ext3 is a
newer filesystem type that differs from Ext2 in that it's journaled, meaning
that if you turn the computer off without properly shutting down, you
shouldn't lose any data and your system shouldn't spend ages doing
filesystem checks the next time you boot up.

reiserfs Your Linux partitions may very well be formatted as ReiserFS. Like
Ext3, ReiserFS is a journaled filesystem, but it's much more advanced than
Ext3. Many Linux distros (including SuSE) have started using ReiserFS as
their default filesystem for Linux partitions.

swap The filesystem name is self-explanatory. The filesystem type "swap" is


used in your swap partitions.

3
vfat and ntfs Your USB stick is most likely formatted as Vfat (more widely
known as FAT32). Your Windows partitions are probably either Vfat or
NTFS. The 9x series (95, 98, ME) all use Vfat, and the NT series (NT, 2000,
XP, Vista, 7) use NTFS but they may be formatted as Vfat, too.

auto No, this isn't a filesystem type :-) The option "auto" simply means that
the filesystem type is detected automatically. If you take a look at the
example fstab above, you'll see that the floppy and CD-ROM both have
"auto" as their filesystem type. Why? Their filesystem type may vary. One
floppy might be formatted for Windows and the other for Linux's Ext2.
That's why it's wise to let the system automatically detect the filesystem type
of media such as floppies and cdroms.

< 4th column: Mount options >

The fourth column in fstab lists all the mount options for the device or
partition. This is also the most confusing column in the fstab file, but
knowing what some of the most common options mean, saves you from a
big headache. Yes, there are many options available, but I'll take a look at
the most widely used ones only. For more information, check out the man
page of mount.

auto and noauto With the auto option, the device will be mounted
automatically (at bootup, just like I told you a bit earlier, or when you issue
the mount -a command). auto is the default option. If you don't want the
device to be mounted automatically, use the noauto option in /etc/fstab. With
noauto, the device can be mounted only explicitly.

user and nouser These are very useful options. The user option allows
normal users to mount the device, whereas nouser lets only the root to mount
the device. nouser is the default, which is a major cause of headache for new
Linux users. If you're not able to mount your cdrom, floppy, Windows
partition, or something else as a normal user, add the user option into
/etc/fstab.

exec and noexec exec lets you execute binaries that are on that partition,
whereas noexec doesn't let you do that. noexec might be useful for a
partition that contains binaries you don't want to execute on your system, or

4
that can't even be executed on your system. This might be the case of a
Windows partition.

exec is the default option, which is a good thing. Imagine what would
happen if you accidentally used the noexec option with your Linux root
partition...

ro Mount the filesystem read-only.

rw Mount the filesystem read-write. Again, using this option might cure the
headache of many new Linux users who are tearing their hair off because
they can't write to their floppies, Windows partitions, or something else.

sync and async How the input and output to the filesystem should be done.
sync means it's done synchronously. If you look at the example fstab, you'll
notice that this is the option used with the floppy. In plain English, this
means that when you, for example, copy a file to the floppy, the changes are
physically written to the floppy at the same time you issue the copy
command.

However, if you have the async option in /etc/fstab, input and output is done
asynchronously. Now when you copy a file to the floppy, the changes may
be physically written to it long time after issuing the command. This isn't
bad, and may sometimes be favorable, but can cause some nasty accidents: if
you just remove the floppy without unmounting it first, the copied file may
not physically exist on the floppy yet!

async is the default. However, it may be wise to use sync with the floppy,
especially if you're used to the way it's done in Windows and have a
tendency to remove floppies before unmounting them first.

defaults Uses the default options that are rw, suid, dev, exec, auto, nouser,
and async.

< 5th and 6th columns: Dump and fsck options >

Dump and, uh, what options? Well, dump is a backup utility and fsck is a
filesystem check utility. I won't discuss them in great length here (they
would both need their own tuXfile), but I'll mention them, because otherwise

5
you'd spend the rest of the day wondering what on God's green Earth do
these things mean.

The 5th column in /etc/fstab is the dump option. Dump checks it and uses
the number to decide if a filesystem should be backed up. If it's zero, dump
will ignore that filesystem. If you take a look at the example fstab, you'll
notice that the 5th column is zero in most cases.

The 6th column is a fsck option. fsck looks at the number in the 6th column
to determine in which order the filesystems should be checked. If it's zero,
fsck won't check the filesystem.

< Example /etc/fstab entries >

As an example, we'll take a look at a couple of fstab entries that have been a
source of endless frustration for new Linux users: floppy and CD-ROM
(although these days floppies aren't that important anymore).

/dev/fd0 /media/floppy auto rw,noauto,user,sync 0 0

This line means that the floppy is mounted to /media/floppy by default and
that its filesystem type is detected automatically. This is useful because the
type of the floppy may wary. Note especially the rw and user options: they
must be there if you want to be able to mount and write to the floppy as a
normal user. If you have trouble with this, check your fstab file to see if
these options are there. Also note the sync option. It can be async just as
well, but it's sync because of reasons discussed a bit earlier.

/dev/cdrom /media/cdrom auto ro,noauto,user,exec 0 0

Note, again, the user option that enables you to mount the CD as a normal
user. The CD-ROM has the ro option because it's no use mounting a CD-
ROM read-write because you wouldn't be able to write to it anyway. Also
note the exec option. It's especially useful if you'd like to be able to execute
something from your CD.

Also note that the noauto option is used with the floppy and CD-ROM. This
means that they won't be automatically mounted when your Linux system
boots up. This is useful for removable media, because sometimes there won't

6
be any floppy or CD-ROM when you boot up your system, so there isn't any
reason to try to mount something that doesn't even exist.

What is fstab file?

fstab is a configuration file that contains information of all the partitions and
storage devices in your computer. The file is located under /etc, so the full path to
this file is /etc/fstab.

/etc/fstab contains information of where your partitions and storage devices


should be mounted and how. If you can't access your Windows partition from Linux,
aren't able to mount your CD or write to your floppy as a normal user, or have
problems with your CD-RW, you probably have a misconfigured /etc/fstab file. So,
you can usually fix your mounting problems by editing your fstab file.

/etc/fstab is just a plain text file, so you can open and edit it with any text editor
you're familiar with. However, note that you must have the root privileges before
editing fstab. So, in order to edit the file, you must either log in as root or use the su
command to become root.

Sample fstab file looks like this

#
# /etc/fstab
#
# <device> <mountpoint> <filesystemtype><options> <dump> <fsckorder>

/dev/hdb5 / ext2 defaults 1 1


/dev/hdb2 /home ext2 defaults 1 2
/dev/hdc /mnt/cdrom iso9660 noauto,ro,user 0 0
/dev/hda1 /mnt/dos/c msdos defaults 0 0
/dev/hdb1 /mnt/dos/d msdos defaults 0 0
/dev/fd0 /mnt/floppy ext2 noauto,user 0 0
/dev/hdb4 none ignore defaults 0 0

none /proc proc defaults


/dev/hdb3 none swap sw

Note that this system has two IDE partitions, one which is used as /, and the other
used as /home. It also has two DOS partitions which are mounted under /mnt. Note
the user option provided for the cdrom, and the floppy drive. This is one of the many
default parameters you can specify. In this case it means that any user can mount a
cdrom, or floppy disk. Other options will be dealt with later.

7
fstab file format explination

fstab consists of a number of lines (one for each filesystem) seperated into six fields.
Each field is seperated from the next by whitespace (spaces/tabs).

So from the example given previously:

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

first field (/dev/hdc) is the physical device/remote filesystem which is to be


described.

second field (/mnt/cdrom) specifies the mount point where the filesystem will be
mounted.

third field (iso9660) is the type of filesystem on the device from the first field.

fourth field (noauto,ro,user) is a (default) list of options which mount should use
when mounting the filesystem.

fifth field (0) is used by dump (a backup utility) to decide if a filesystem should be
backed up. If zero then dump will ignore that filesystem. The sixth field (0) is used
by fsck (the filesystem check utility) to determine the order in which filesystems
should be checked.

If zero then fsck won't check the filesystem.

(as the example line above is a cdrom there is very little point in doing a fsck on it,
so the value is zero).

File system mount options

As the filesystems in /etc/fstab will eventually be mounted using mount(8) it isn't


surprising that the options field simply contains a comma-seperated list of options
which will be passed directly to mount when it tries to mount the filesystem.

The options common to all filesystems are:

sync / async

All I/O to the file system should be done (a)synchronously.

auto

The filesystem can be mounted automatically (at bootup, or when mount is passed
the -a option). This is really unnecessary as this is the default action of mount -a
anyway.

noauto

8
The filesystem will NOT be automatically mounted at startup, or when mount passed
-a. You must explicitly mount the filesystem.

dev / nodev

Permit any user to mount the filesyste. This automatically implies noexec,

exec / noexec

Permit/Prevent the execution of binaries from the filesystem.

suid / nosuid

Permit/Block the operation of suid, and sgid bits.

ro

Mount read-only.

rw

Mount read-write.

user

Permit any user to mount the filesystem. This automatically implies noexec,
nosuid,nodev unless overridden.

nouser

Only permit root to mount the filesystem. This is also a default setting.

defaults

Use default settings. Equivalent to rw,suid,dev,exec,auto,nouser,async.

There are numerous options for the specific filesystes supported by mount.
However these are some of the more useful, for the full list check out the man page
for `mount`.

ext2

check={none, normal, strict}


Sets the fsck checking level.

debug

print debugging info on each remount.

sb=n

9
n is the block which should be used as the superblock for the fs.

fat

check={r[elaxed], n[ormal], s[trict]}

Not the same as ext2. Rather deals with allowed filenames. See mount man page.

conv={b[inary], t[ext], a[uto]}

Performs DOS<->UNIX text file conversions automatically. See mount man page.

uid=n, gid=n

iso9660

norock

Disables Rock Ridge extensions.

fstab file Supported file systems list

affs - I have know idea what this is, if anyone else does please enlighten me.

coherent

ext - Don't use this. ext has been superseded by ext2.

ext2 - The standard Linux filesystem. (NB, this has nothing to do with extended
partitions.)

fat - DOS.

hpfs - OS/2 High Performance File System.

iso9660 - CD-ROM's. Supports Rock Ridge extensions by default.

minix - can be useful for floppy disks.

msdos - Just fat with some addtional error checking.

nfs - Network FileSystem. Dealt with later.

proc - The process psudeo-filesystem now standard in Linux.

smb - Another network filesystem. Compatable with WFW, and NT. See Samba.

ufs - Unix FileSystem.

unsdos - Unix filesystem on a FAT partition.

10
vfat - MS's kludge of FAT to provide long filenames.

xenix

xiafs

If you want to know how to mount NFS in fstab file click here and this will explain
how to setup NFS server.

What is fstab and why it's useful

fstab is a configuration file that contains information of all the partitions and storage devices in
your computer. The file is located under /etc, so the full path to this file is /etc/fstab.

/etc/fstab contains information of where your partitions and storage devices should be
mounted and how. If you can't access your Windows partition from Linux, aren't able to mount
your CD or write to your floppy as a normal user, or have problems with your CD-RW, you
probably have a misconfigured /etc/fstab file. So, you can usually fix your mounting problems
by editing your fstab file.

/etc/fstab is just a plain text file, so you can open and edit it with any text editor you're
familiar with. However, note that you must have the root privileges before editing fstab. So, in
order to edit the file, you must either log in as root or use the su command to become root.

Overview of the file

Of course everybody has a bit different /etc/fstab file because the partitions, devices and their
properties are different on different systems. But the basic structure of fstab is always the
same. Here's an example of the contents of /etc/fstab:

Device Mount File Mount Dump fsck


point system options y/n order
/dev/hda2 / ext2 defaults 1 1
/dev/hdb1 /home ext2 defaults 1 2
/dev/cdrom /media/cdrom auto ro,noauto,user,exec 0 0
/dev/fd0 /media/floppy auto rw,noauto,user,sync 0 0
/proc /proc proc defaults 0 0
/dev/hda1 swap swap pri=42 0 0

What does all this gibberish mean? As you see, every line (or row) contains the information of
one device or partition. The first column contains the device name, the second one its mount
point, third its filesystem type, fourth the mount options, fifth (a number) dump options,
and sixth (another number) filesystem check options. Let's take a closer look at this stuff.

1st and 2nd columns: Device and default mount point

The first and second columns should be pretty straightforward. They tell the mount command
exactly the same things that you tell mount when you mount stuff manually: what is the
device or partition, and what is the mount point. The mount point specified for a device in
/etc/fstab is its default mount point. That is the directory where the device will be mounted if
you don't specify any other mount point when mounting the device.

Like you already learned from the Mounting tuXfile, most Linux distros create special
directories for mount points. Most distros create them under /mnt, but some (at least SuSE)

11
under /media. As you probably noticed when looking at the example fstab, I use SuSE's mount
points as an example.

What does all this mean? If I type the following command:

$ mount /dev/fd0

... my floppy will be mounted in /media/floppy, because that's the default mount point
specified in /etc/fstab. If there is no entry for /dev/fd0 in my fstab when I issue the command
above, mount gets very confused because it doesn't know where to mount the floppy.

You can freely change the default mount points listed in /etc/fstab if you're not satisfied with
the defaults your distro has given you. Just make sure the mount point is a directory that
already exists on your system. If it doesn't, simply create it.

Some partitions and devices are also automatically mounted when your Linux system boots
up. For example, have a look at the example fstab above. There are lines that look like this:

/dev/hda2 / ext2 defaults 1 1


/dev/hdb1 /home ext2 defaults 1 2

As you've learned, these lines mean that /dev/hda2 will be mounted to / and /dev/hdb1 to
/home. This is done automatically when your Linux system boots up... if it wouldn't, you'd
have a hard time using your cool Linux system because all the programs you use are in / and
you wouldn't be able to run them if / wasn't mounted! But how does the system know where
you want to mount /dev/hda2 and /dev/hdb1? By looking at the /etc/fstab file of course.

3rd column: Filesystem type

The third column in /etc/fstab specifies the filesystem type of the device or partition. Many
different filesystems are supported but we'll take a look at the most common ones only.

• ext2 and ext3

Very likely your Linux partitions are Ext3. Ext2 used to be the standard filesystem for Linux,
but these days, Ext3 and ReiserFS are usually the default filesystems for almost every new
Linux distro. Ext3 is a newer filesystem type that differs from Ext2 in that it's journaled,
meaning that if you turn the computer off without properly shutting down, you shouldn't lose
any data and your system shouldn't spend ages doing filesystem checks the next time you
boot up.

• reiserfs

Your Linux partitions may very well be formatted as ReiserFS. Like Ext3, ReiserFS is a
journaled filesystem, but it's much more advanced than Ext3. Many Linux distros (including
SuSE) have started using ReiserFS as their default filesystem for Linux partitions.

• swap

The filesystem name is self-explanatory. The filesystem type "swap" is used in your swap
partitions.

• vfat and ntfs

12
Your Windows partitions are probably either Vfat or NTFS. The 9x series (95, 98, ME) all use
Vfat (more widely known as FAT32), and the NT series (NT, 2000, XP) use NTFS. In 2000 and
XP you can choose the filesystem type, so 2000 and XP partitions may be formatted as Vfat,
too. If you want to be able to write to your Windows partitions from Linux, I suggest
formatting them as Vfat, because Linux's support for writing to NTFS partitions is a bit shabby
at this moment.

• auto

No, this isn't a filesystem type :-) The option "auto" simply means that the filesystem type is
detected automatically. If you take a look at the example fstab above, you'll see that the
floppy and CD-ROM both have "auto" as their filesystem type. Why? Their filesystem type may
vary. One floppy might be formatted for Windows and the other for Linux's Ext2. That's why
it's wise to let the system automatically detect the filesystem type of media such as floppies
and cdroms.

4th column: Mount options

The fourth column in fstab lists all the mount options for the device or partition. This is also
the most confusing column in the fstab file, but knowing what some of the most common
options mean, saves you from a big headache. Yes, there are many options available, but I'll
take a look at the most widely used ones only. For more information, check out the man page
of mount.

• auto and noauto

With the auto option, the device will be mounted automatically (at bootup, just like I told you
a bit earlier, or when you issue the mount -a command). auto is the default option. If you
don't want the device to be mounted automatically, use the noauto option in /etc/fstab. With
noauto, the device can be mounted only explicitly.

• user and nouser

These are very useful options. The user option allows normal users to mount the device,
whereas nouser lets only the root to mount the device. nouser is the default, which is a major
cause of headache for new Linux users. If you're not able to mount your cdrom, floppy,
Windows partition, or something else as a normal user, add the user option into /etc/fstab.

• exec and noexec

exec lets you execute binaries that are on that partition, whereas noexec doesn't let you do
that. noexec might be useful for a partition that contains binaries you don't want to execute on
your system, or that can't even be executed on your system. This might be the case of a
Windows partition.

exec is the default option, which is a good thing. Imagine what would happen if you
accidentally used the noexec option with your Linux root partition...

• ro

Mount the filesystem read-only.

• rw

13
Mount the filesystem read-write. Again, using this option might cure the headache of many
new Linux users who are tearing their hair off because they can't write to their floppies,
Windows partitions, or something else.

• sync and async

How the input and output to the filesystem should be done. sync means it's done
synchronously. If you look at the example fstab, you'll notice that this is the option used with
the floppy. In plain English, this means that when you, for example, copy a file to the floppy,
the changes are physically written to the floppy at the same time you issue the copy
command.

However, if you have the async option in /etc/fstab, input and output is done asynchronously.
Now when you copy a file to the floppy, the changes may be physically written to it long time
after issuing the command. This isn't bad, and may sometimes be favorable, but can cause
some nasty accidents: if you just remove the floppy without unmounting it first, the copied file
may not physically exist on the floppy yet!

async is the default. However, it may be wise to use sync with the floppy, especially if you're
used to the way it's done in Windows and have a tendency to remove floppies before
unmounting them first.

• defaults

Uses the default options that are rw, suid, dev, exec, auto, nouser, and async.

5th and 6th columns: Dump and fsck options

Dump and, uh, what options? Well, dump is a backup utility and fsck is a filesystem check
utility. I won't discuss them in great length here (they would both need their own tuXfile), but
I'll mention them, because otherwise you'd spend the rest of the day wondering what on God's
green Earth do these things mean.

The 5th column in /etc/fstab is the dump option. Dump checks it and uses the number to
decide if a filesystem should be backed up. If it's zero, dump will ignore that filesystem. If you
take a look at the example fstab, you'll notice that the 5th column is zero in most cases.

The 6th column is a fsck option. fsck looks at the number in the 6th column to determine in
which order the filesystems should be checked. If it's zero, fsck won't check the filesystem.

Example /etc/fstab entries

As an example, we'll take a look at a couple of fstab entries that have been a source of endless
frustration for new Linux users: floppy and CD-ROM (although these days floppies aren't that
important anymore).

/dev/fd0 /media/floppy auto rw,noauto,user,sync 0 0

14
This line means that the floppy is mounted to /media/floppy by default and that its filesystem
type is detected automatically. This is useful because the type of the floppy may wary. Note
especially the rw and user options: they must be there if you want to be able to mount and
write to the floppy as a normal user. If you have trouble with this, check your fstab file to see
if these options are there. Also note the sync option. It can be async just as well, but it's sync
because of reasons discussed a bit earlier.

/dev/cdrom /media/cdrom auto ro,noauto,user,exec 0 0

Note, again, the user option that enables you to mount the CD as a normal user. The CD-ROM
has the ro option because it's no use mounting a CD-ROM read-write because you wouldn't be
able to write to it anyway. Also note the exec option. It's especially useful if you'd like to be
able to execute something from your CD. Also note that the noauto option is used with the
floppy and CD-ROM. This means that they won't be automatically mounted when your Linux
system boots up. This is useful for removable media, because sometimes there won't be any
floppy or CD-ROM when you boot up your system, so there isn't any reason to try to mount
something that doesn't even exist.

The file /etc/fstab is central to getting your GNU/Linux operating system booted and
running. fstab stands for file system table. It is a plain text file containing the list of all
the regular filesystems and other standard block devices that are to be attached to your
root filesystem. Most removable media devices, such as flash drives and USB hard disk
drives, are not covered by the fsab. They are handled by a separate process, udev.

When your Linux OS boots, it reads the fsab, and it mounts the listed filesystems
according to the specifications and options written in this file. One option is not to mount
the partition or device at boot-time, but to reserve the option to be mounted at a later time
without rebooting. For example: suppose you have a separate HDD that you use only to
back up certain data files. There is no reason to have this HDD spinning and accessible
every time you boot, becuase [say] you only do backups on Fridays night. But there may
be several partitions on another HDD that hold your music, web-projects, development
projects, whatever: they need to be automatically mounted and be ready at all times.

Most modern Linux systems set up a basic /etc/fstab file for you at the time of
installation. But many times the defaults are not optimal for individual circumstances like
yours. Editing the /etc/fstab is perhaps the easiest way of tweaking the filesystem so your
machine boots with the right partitions automatically mounted and with the correct file
permissions in place to suit your needs.

This Guide will focus on the most useful options for a computer system that has multiple
data partitions in addition to the main partitions in a typical GNU/Linux operating
system.

The Essentials

15
Every fstab is going to have a few common entries:

/ - the root partition, where the OS is installed.


/home - the directory where user configuration files are stored. Linux currently employs
the old Unix tradition and also stores all user data files here: documents, downloads,
pictures, etc. that you accumulate. If you chose not to have /home on a separate partition
when you installed the Linux OS there will be no need for an additional fstab entry to
mount it: it will mount along with the root filesystem.
swap - a partition the OS can use as “virtual memory” if it runs out of RAM. In a
modern system, it is typically 1 GB in size. It needs to be on separate partition from /root
or /home or any others.

Read the the fstab man page

It would probably be helpful to right-click and open this page in a new browser tab, so
you can refer to it for more detailed information: fstab(5) - Linux man page

fstab overview

Editing configuration files may seem intimidating to new GNU Linux users. . . but with a
little effort to understand the simple structure of the /etc/fstab file, you can safely make
changes to customise your operating system just right. Much of the power of Linux is in
the ability to use simple text configuration files to change things that users of a
proprietary OS like MS WindowsXP, Vista, or Mac OS X just have to learn to accept. A
configuration file is a tool, and here at SBLinux.org we like our tools sharp and shining.
Here's how to buff a Silver polish to the tool that controls the way your partitions are
added to your OS's root filesystem at boot time.

Structure of the /etc/fstab file

The /etc/fstab is a plain text file comprised of six columns. Here is the layout:

name => fs_spec fs_file fs_vfstype fs_mntops fs_freq fs_passno

specifies: the block the mount the type of the mount to be used used by the
special point for the filesystem. options to by the fsck(8)
device or filesystem e.g.: be dump(8) program to
remote ext2 associated command set the order
filesystem [notes] ext3 with the in which
to be jfs filesystem [notes] filesystem
mounted reiserfs checks are

16
done at
vfat
reboot
xfs
values:
auto [notes]
[notes] 0,1,2
[notes]
[notes]

Example of some lines from my /etc/fstab:


# ######### system essentials ############
/dev/sda3 / ext3 defaults,noatime 1 1
/dev/sdc2 swap swap sw,pri=1 0 0
none /proc proc defaults 0 0
none /proc/bus/usb usbfs devmode=0666 0 0
none /dev/pts devpts mode=0622 0 0
none /sys sysfs defaults 0 0
/dev/sda11 /home ext3 defaults,noatime 1 2
# ########### data partitions #############
# ######## sdb data disk SATA2
/dev/sdb1 /mnt/sdb1 ext3 auto,users,exec 0 0
/dev/sdb2 /mnt/sdb2 ext3 auto,users,exec 0 0
/dev/sdb3 /mnt/sdb3 ext3 auto,users,exec 0 0
/dev/sdb5 /mnt/sdb5 ext3 auto,users,exec 0 0
/dev/sdb6 /mnt/sdb6 ext3 auto,users,exec 0 0
/dev/sdb7 /mnt/sdb7 ext3 auto,users,exec 0 0
/dev/sdb8 /mnt/sdb8 ext3 auto,users,exec 0 0
/dev/sdb9 /mnt/sdb9 ext3 auto,users,exec 0 0
/dev/sdb10 /mnt/sdb10 ext3 auto,users,exec 0 0
/dev/sdb11 /mnt/sdb11 ext3 auto,users,exec 0 0
/dev/sdb12 /mnt/sdb12 ext3 auto,users,exec 0 0
/dev/sdb13 /mnt/sdb13 ext3 auto,users,exec 0 0
/dev/sdb14 /mnt/sdb14 ext3 auto,users,exec 0 0

By the time you finish studying this article, you should be able to understand everything
in my sample. Perhaps the most important thing to understand is what you can safely
change, and what you must not change!

Rule number one:

Before you open your /etc/fstab file as root to edit it, back
it up for safekeeping.

As a regular user you can save it to your /home /user directory by issuing this command.
Change the destination to suit your own data storage setup:

cp /etc/fstab /home/silverbear/backups/fstab-080516.txt

This copies my /etc/fstab file into a new file named fstab-080516.txt located in my
backups subdirectory in my /home/silverbear directory. I chose this filename to indicate

17
that the date of the backup was 2008-05-16. You might choose the name fstab-orig.txt or
use the current date like I did. Whatever you do, do something to help you keep it
available and easy to identify. If you save it as simply “fstab” it could get confusing. . .
and if you back it up again in the future, you'll overwrite the older backup of the same
name.

Notes on the 6 fstab columns

Column 1: fs_spec

The first field describes the block special device or remote filesystem to be mounted.

In Unix/Linux everything is a file. This includes devices like your hard disk drives and
cd-rom, as well as the more usual type of things we usually mean when we usually say
“file!” For a better understanding of the Seven Types of File in Unix/Linux, right-click
and open in a new browser tab this local url: The Seven Unix/Linux File Types

Right now we are going to only concentrate on what we are going to change in our fstab.
This means that fs_spec will refer to the device name of the partition we want to mount.
In current usage, there are two main ways to denote a hard disk drive partition in the
fs_spec field: by partition number and by UUID.

Example fs_spec by partition number:


/dev/sda5

This is easily understood by humans as referring to the fifth partition on the first HDD.
That's the advantage of the partition number method.

Example fs_spec by UUID:


UUID=eddf7d72-c1ba-42fa-b8e2-bc1fd94d4ce2

This is not easily understood by humans. But it is a unique identifier that precludes all
ambiguity as to which partition is meant. That's the advantage of the UUID method.

On my desktop system at this time, these two entries both refer to the same partition. But
if I repartition sda, the UUIDs will change and the fstab will need to be manually edited.
To discover the current UUIDs for your partitions, issue this command:

ls /dev/disk/by-uuid -l

All your partitions will be listed in order of UUID, with the last column denoting the
partition number designation.

18
I recommend using the partition number designation, unless you have a situation where
that designation might be ambiguous. For example, an external HDD that gets plugged in
and assigned a different sdx designation depending on other factors. In that case,
partitions on that external HDD would best be listed by UUID. Another situation that
could call for using UUIDs is if you have both SATA and PATA hard disk drives.
Fortunately, the /etc/fstab file will accept both designations: you don't need to do
them all one way or all the other.

Column 2: fs_file

Column 3: fs_vfstype

Column 5: fs_freq

Column 6: fs_passno

Column 4: fs_mntops

For now we will focus only on the fourth field [column], fs_mntops, the mount options.
There is a standard defaults option which includes all of these options: auto, nouser, rw,
exec, suid, dev, async

19
The meaning of the allowed mounting options, in
mutually-exclusive groups:
auto Partition is automatically mounted at boot time.
Precision
Partition is not automatically mounted, but can counts!
noauto
be mounted with the mount command.
Partition cannot be mounted by a mount Be sure to set only one
nouser option from each of the
command from a regular user, only root.
groups: the other[s] are
A Partition can be mounted by a mount
the opposite! At the same
command from a regular user. The name of the
time, if one option that
mounting user is written to /etc/mtab so that
user you set carries with it
s/he can unmount the file system again. ‡ This
certain defaults for other
automatically implies noexec, nosuid, nodev
options, you must
unless overridden.
explicitly set the
Allow every user to mount and unmount the file countermanding options
users system. ‡ This automatically implies noexec, or the default ones will
nosuid, nodev unless overridden. rule.
Read and write privileges are established for
rw Example: the users
this partition.
option implies [for
ro All files are Read Only. security] the default
noexec. To allow binaries
Binaries and scripts located on the partition
exec on this partition to be
may be executed.
executed by users who
Binaries and scripts located on the partition mount it, the line would
noexec
may be not executed. need to have the
countermanding option
Allow set-user-identifier or set-group-identifier
suid like this:
bits to take effect.
auto,users,exec
Do not allow set-user-identifier or set-group-
nosuid
identifier bits to take effect.
Interpret character or block special devices on
dev the file system. Essential for the OS root
partition and its system directories.
Do not set character or special devices access
nodev
on this partition.
All I/O to the file system should be done
async
asynchronously. Better for fixed disks.
All I/O to the file system should be done
sync synchronously. Better for removable devices
like floppies and USB drives.
Update inode access time for each access. This
atime
is the default.
Do not update inode access times on this file
noatime system (e.g, for faster access on the news spool 20
to speed up news servers).
THE UMASK CODE
FOR PERMISSIONS

Here is a simple table that illustrates what to enter after the initial zero in your 4-digit
umask option. Plus (+) indicates a positve permission, minus (-) indicates no permission
for each power: read, write execute.

0 1 2 3 4 5 6 7 You may have noticed that the


numbers given are NOT the same
as the octal permission codes
r + + + - - - - - passed to the chmod command.
w + + - - + + - - That's because these are masks —
x + - + - + - + - the complementary number to
subtract from 7 to acheive the
permission code you want. 7 is full rwx permissions. If you want that, you mask=0. If you
want the permissions to be set at 6, you mask=1; if at 4 you mask=3, and so on.

Why are there four digits in the umask option?

Good question! The initial zero indicates that the following three digits are octal numbers,
not decimal numbers. In the umask command that you can enter in a terminal (command
line mode), you may use octal or the ugo +/- method. But in the /etc/fstab file, it must be
octal and should have four digits, not three.

Examples:
umask=0000 means user, group and others have full rwx permissions
umask=0117 means the user, the file owner has read/write permissions but not execute,
and so does the group. But others —sometimes referred to as “world” for clarity's sake—
have no permissions at all.

21

You might also like