Fstab Demystified: How to Add Partitions

Written by:  • Edited by: Michele McDonough
Updated Oct 2, 2009
• Related Guides: File System | Linux | New Hard Drive

In this article, you will learn to understand fstab (File System Table) and its entries. We'll show you how to add a new hard drive to fstab and mount the partitions automatically on boot. We'll also explain some of the terminology used in fstab, and we take a look at the fdisk command.

Background for this Article

  • Konsole - Terminal also know as command line. Read : The Beginners Guide To Ubuntu Terminal by Josef Nankivell for more information on using Terminal commands.
  • Nano - Terminal text editor.

Please read part one of this series: How To Partition A Hard Drive In Linux

What is Fstab, and Why do I Need It?

fstab
click to enlarge
Fstab (File System Table) is a file used by Linux operating systems to mount partitions on boot. It needs this because it can't guess what the partitions are and what to mount them to.

Take a look at the contents of fstab open Terminal and type:

nano /etc/fstab

There's no editing yet, so there's no need to sudo this command at this time.

See the screenshot to the left for the result of this action.

Let's pick the line for root apart.

table
click to enlarge

The columns are as follows:

1. The device name or other means of locating the partition or data source.

2. The mount point, where the data is to be attached to the file system.

3. The file system type or algorithm used to interpret the file system.

4. Options that should be used when mounting at boot.

5. Dump-freq adjusts the archiving schedule for the partition (used by dump).

6. Pass-number indicates the order in which the fsck utility will scan the partitions for errors, when the computer powers on.

To close fstab file “ctrl+x”, “n” and “enter”.

Now let's find out what the device identifier is of the new partition. In Terminal type:

sudo fdisk -l

This is the result:

fdisk rsult
click to enlarge

In this case the first disk sda is a 120GB disk the second sdb is a 750GB disk.

Sda has 5 partitions: sda1, sda2, et cetera.

Sdb has 3 partitions: sdb1, sdb2, and sdb3.

We will add sdb1 to the fstab file. First we need to create a mount point. Most mount points are created in /media or /mnt, they can be put in the mount point any where you want. In this case, we will use /media.

In Terminal type:

sudo mkdir /media/partitionname1

Partitionname1 is the directory name for this mount point. You can use any name you want - data, entertainment, multimedia - whatever suits your needs.

Open fstab for editing in Terminal type:

sudo nano /etc/fstab

Add the following line below to what is already there:

/dev/sdb1 /media/partition1 ext3 defaults 0 3

I'll explain:

/dev/sdb1: Dev stands for "device file system" and sdb1 the partition on the hard disk.

/media/partition1: The mount point or in other words the folder that the new partition will be mounted to.

ext3: The file system used on the partition.

defaults: Defaults will automatically define these options: rw, suid, dev, exec, auto, nouser, async. These are all the options needed to get the partition to work properly.

0: The dump frequency of all the fstabs I've seen so far don't change this setting. So I have no explanation of it at this time. I will follow up on this in another article at a later date.

3: This sets the order of the fsck file system checking. I like all partitions checked every once in a while so I changed this to 3. If you don't want the partition checked, simply set this to 0.

Close the fstab file: “ctrl+x”, “y” and “enter”.

Check to make sure it mounts. In Terminal type:

sudo mount -a

This will mount any unmounted devices. Now, your partitions will be mounted automatically every time you boot.


Comments

Showing all 7 comments
 
Timothy Gott Mar 9, 2011 12:30 AM
sda is 'not' 120GB
"In this case the first disk sda is a 120GB disk the second sdb is a 750GB disk. ... Sda has 5 partitions: sda1, sda2, et cetera."

Looks like the snapshot that you took is the wrong one. The snapshot through me off (I'm just learning) because sda is a 160GB drive with three partitions.

But still thanks for the article. Other than this detail I find it very helpful.

And BTW what addon are you using for your comment verifier? I like the way yours doesn't show the code until 'after' you start to type in the information.

Thanks on all points :-)
Dan Bowkley Dec 3, 2010 12:31 AM
fsck frequency
With regards to file system checking, fstab merely tells the system in what order to perform checks, not how often. For example, if you have two hard drives with two partitions each, you can set sda1 and sdb1 to check at 1, and have sda2 and sdb2 check at 2. Then at boot, it will first check the first partition on each drive simultaneously, then check both second partitions at once. Having it do one per drive at the same time like that can really cut down boot time if you have a lot of hard drives. Unless you like painful wait times, I strongly suggest you never have two partitions on the same drive set to the same fsck order...in fact, if you can help it it's best not to have two partitions on the same bus get fsckd at the same time. Not an issue with SATA devices, but a potential problem on IDE and a real pain to manage on large SCSI arrays. Really depends on how fast the bus is relative to your drives' maximum transfer speed.

The frequency at which partitions get checked is actually set when you create the filesystem on it; it's passed as an option to mkfs and (I think) it can be changed later as well. But it's defined there, *not* in fstab.

Keep the great articles coming!
--D
santosh Oct 4, 2010 3:55 AM
Thanks
hi ! Thanks a lot for providing such Info. i really fond of it .thanks
NAVEENRAJ Sep 12, 2010 3:37 PM
THAKS A LOT
NICE INFO

THANKS A LOT :)
brad Apr 30, 2010 2:52 AM
Thanks!
Thanks bro, just saved me a billion time.
mohan Feb 19, 2010 1:19 AM
This is much appreciated
Much appreciated
zenboy Sep 1, 2009 8:27 PM
Great How-To!
Thank you for providing this great How-To!
There are many how-tos out there that only give you the steps but no explanation or details of why of things from many technical gurus. Your guide shows both of this needed points.
Like the saying goes: "Give a man a fish; you have fed him for today. Teach a man to fish; he will feed himself for live."
Keep up the good work.
 
blog comments powered by Disqus
Email to a friend