SilverBear's Guide to
FSTABing Your Way to the Top

This page is under construction, right now -- in real time. It may change from moment to moment. Check back later if you don't understand something in it's current state. . .

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

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 special device or remote filesystem to be mounted
 
[notes]
the mount point for the filesystem
 
[notes]
the type of filesystem. e.g.:
ext2
ext3
jfs
reiserfs
vfat
xfs
auto
 
[notes]
the mount options to be associated with the filesystem
 
[notes]
to be used by the dump(8) command
 
[notes]
used by the fsck(8) program to set the order in which filesystem checks are done at reboot
values:
0,1,2
 
[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 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.

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


The meaning of the allowed mounting options, in mutually-exclusive groups:

auto Partition is automatically mounted at boot time.
noauto Partition is not automatically mounted, but can be mounted with the mount command.


nouser Partition cannot be mounted by a mount command from a regular user, only root.
user A Partition can be mounted by a mount command from a regular user. The name of the mounting user is written to /etc/mtab so that s/he can unmount the file system again. ‡ This automatically implies noexec, nosuid, nodev unless overridden.
users Allow every user to mount and unmount the file system. ‡ This automatically implies noexec, nosuid, nodev unless overridden.


rw Read and write privileges are established for this partition.
ro All files are Read Only.


exec Binaries and scripts located on the partition may be executed.
noexec Binaries and scripts located on the partition may be not executed.


suid Allow set-user-identifier or set-group-identifier bits to take effect.
nosuid Do not allow set-user-identifier or set-group-identifier bits to take effect.


dev Interpret character or block special devices on the file system. Essential for the OS root partition and its system directories.
nodev Do not set character or special devices access on this partition.


async All I/O to the file system should be done asynchronously. Better for fixed disks.
sync All I/O to the file system should be done synchronously. Better for removable devices like floppies and USB drives.


atime Update inode access time for each access. This is the default.
noatime Do not update inode access times on this file system (e.g, for faster access on the news spool to speed up news servers).
 

Precision counts!

Be sure to set only one option from each of the groups: the other[s] are the opposite! At the same time, if one option that you set carries with it certain defaults for other options, you must explicitly set the countermanding options or the default ones will rule.

Example: the users option implies [for security] the default noexec. To allow binaries on this partition to be executed by users who mount it, the line would need to have the countermanding option like this:
auto,users,exec




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
r + + + - - - - -
w + + - - + + - -
x + - + - + - + -

You may have noticed that the numbers given are NOT the same as the octal permission codes passed to the chmod command. That's because these are masks —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.





Sorry: I ran out of steam.
Please try back in a couple weeks. and I may finish this article by then. . .