PDA

View Full Version : HOW TO edit /etc/fstab


imdeemvp
18th August 2004, 10:18 AM
Intended for our new Fedora Core users that are using linux for the first time and they want to undertand and edit the /etc/fstab


< How to edit and understand /etc/fstab - 1.0 >


There's a file called /etc/fstab in your Linux system. Learn what its contents mean and how it's used in conjunction with the mount command. When you learn to understand the fstab file, you'll be able to edit its contents yourself, too.


< 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:
/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) 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 either Ext2 or Ext3. Ext2 is the standard filesystem for Linux. Ext3 is a newer one 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 If you're using a fairly new version of a Linux distro, your Linux partitions may very well be formatted as ReiserFS instead of the good old Ext2. 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 Your Windoze 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 wary. 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, Windoze 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 conatins 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 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 Windoze 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.

to finish understanding line 4 and 5 please follow the author's link.

COMPLETE ARTICLE AND CREDITS HERE:
Author: NGene < nhlang at gmail dot com > (http://www.tuxfiles.org/linuxhelp/fstab.html)

kosmosik
18th August 2004, 10:30 AM
well what about 4th and 5th column? :P

imdeemvp
18th August 2004, 10:37 AM

not enough room that is why i posted the link...but i made a huge mistake i pressed submit when i meant to press PREVIEW.....so i could not finish editing :(

NOW to a better note, here is a sample of my /etc/stab:

LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
/dev/hda6 swap swap defaults 0 0
/dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0
/dev/cdrom1 /mnt/cdrom1 udf,iso9660 noauto,owner,kudzu,ro 0 0
/dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0
/dev/hda1 /mnt/winxp -t ntfs -r -o umask=0222
/dev/hda2 /mnt/windows vfat users,rw,owner,umask=000 0 0

i hope this will give you an idea how your windows partitions can me mounted automatically at boot........satisfied?..........eat a snickers bar :D

GreyGeek
19th August 2004, 07:09 PM
Nice description, imdeepmvp...
Your /etc/fstab file has some stuff that is in my RHEL3 fstab, but not in my FC2 fstab file: The "LABEL" stuff.
When I first saw that I checked mtab and /proc/mounts to see what was really running.

What is with that "LABLE" stuff? Decode it for me, would you please?
Thanks.
GreyGeek

kosmosik
19th August 2004, 07:27 PM
as for devices like removables (floppy, cdrom, pendrive, camera) and network filesystems (smb, nfs) I prefer to use autofs. it is much more convinient. you just pop the cd in and do "cd /misc/removable/cdrom" - cd gets automagicaly mounted and volia ;) when you leave the directory (and no process is opening it) it gets unmounted after 3 seconds... autofs rulez. I wonder why Fedora ships autofs but it is not configured after install? (but the service is running) it is very convinient way of accessing removables. it is very logical - you have a directory (f.e. /misc/removable like I did) and when it has subdirectory like "cdrom" it means cdrom is in, if no such directory - no cdrom :)

kosmosik
19th August 2004, 07:31 PM
the LABEL stuff AFAIR is way to add abstraction from hardware layout. meaning the block device (partition/fs) is accessed by its LABEL not by its physical location (device/partition) as hardware. means that you can f.e. have two drives with one partition on each. disk one is labeled "Root" and disk two is labeled "Home" in fstab you just enter volume names and it is independent on how you phisycaly connect the devices (which wire)... but AFAIR it works only with certain filesystems as extX and SGI XFS...

kosmosik
19th August 2004, 07:39 PM
this label stuff is good when you use external USB drive. such drive usualy is mapped as /dev/sda(and there go partitions on device) but if you happen to use also a pen drive or camera another external drive it sometimes will appear as diffferent /dev - entry. thus you cannot state explictly in /etc/fstab which FS is which. here LABEL comes handy, you just use LABEL on your externals drive FS and f.e. name one USB drive (1st) and the second (2nd) - then it does not matter if connected drive will apear as /dev/sda or /dev/sdb or whatever... it will still be mounted where you intended. it is also handy with multiple SCSI disks setups...

imdeemvp
19th August 2004, 07:55 PM
kosmosik...........dude thanks!

while i was ZzZzZzZzZzZzZzZ.........you were up :D

Mat
19th August 2004, 08:11 PM
something to add to the label-issue:

use /sbin/e2label to read/write the labels for the partitions


Mat

LinuxHippy
20th August 2004, 01:00 AM
Nice article-always wondered what those 0s and 1s meant. Got a situation: I want to share email messages between two Linux partitions on hda while the email would be on hdb1. How would I do this so that regular users could read and email on hdb1?

I'm thinking something like this:

/dev/hdb1 /mnt/hdb1 ext3 defaults 1 1

:confused:

imdeemvp
20th August 2004, 01:48 AM
you meant you want to transfer them from one linux partition to another linux partition?

nyba
20th August 2004, 03:02 AM
I have practical question might be related -
How to extend my root partition?

when I first installed fc2, I only give root partition a 6.8G allocation. Now as I am installing tons of applications, and a lot of files in my home directory (which is also on root partition) I used up 90% of that partition ....!

I have a slave harddrive, now have 3 partitions in vfat - I am planning to get one of them to ext3 or reiserfs ... Do you know how to extend my / partition to the new partition? I think most of the files are located at /usr, about 4G ...

thanks!

imdeemvp
20th August 2004, 03:10 AM
i dont think linux partitions can be resize or extended.....i know under mandrake it is recommended to do a back up before doing it.......i dont if it can be done in fedora core!

nyba
20th August 2004, 03:22 AM
I am thinking reformat on vfat to ext3 or possible to to reiserfs, then su
cp -rf /usr /mnt/oldvfat
then edit fstab to mount /usr at this /hdb2 ( 17G space)
what do u think?

Mat
20th August 2004, 04:12 AM
use "cp -a"!!! this will preserve symlinks, ownerships etc..

crackers
20th August 2004, 04:29 AM
I am thinking reformat on vfat to ext3 or possible to to reiserfs, then su
cp -rf /usr /mnt/oldvfat
then edit fstab to mount /usr at this /hdb2 ( 17G space)
what do u think?
That will work quite well, but you'll need to do things, all as "root" in this order (comments denoted by //):

# fdisk /dev/hdb -l // to make sure you have the right partition
# mkfs.ext3 /dev/hdbx // I don't have Reiser installed...
# e2label /dev/hdbx /USR
# mkdir /mnt/temp
# mount /dev/hdbx /mnt/temp
# cp -a /usr/* /mnt/temp // this may take a while...
# umount /mnt/temp // this may also take a while for the buffers to flush

Edit /etc/fstab to make the new entry:

LABEL=/USR /usr ext3 defaults 1 2


This is where it gets a little tricky. Note that you should NOT be doing this in GUI mode (runlevel 5), but it's okay in console mode (runlevel 3). This part is where I always cross my fingers...

# mv /usr /usr.bak
# mkdir /usr
# mount -a

That last command should cause your new partition to be mounted on the "new" /usr mount point.

IF IT DOES NOT MOUNT, make note of the errors, remove the new entry from /etc/fstab. Then

# rm -rf /usr // it had better not be mounted, otherwise it'll just wipe the partition
# mv /usr.bak /usr


Please note that if you don't understand the above sequence, you probably shouldn't be doing this without on-site help from someone who does understand it. Not trying to be nasty or anything, but I've been doing this for years and my heart-rate always jumps at those last couple of steps - every time. It's make-or-break time...

nyba
20th August 2004, 05:43 PM
Hey, thanks!

I am at the step of cp -a, cracker's code is just as typing on my machine!
I just modified mount command to mount -t ext3 /dev/hdbx /mnt/temp
copying seems that it is going to last a while ... :)

let's see what's next ...

nyba
20th August 2004, 06:53 PM
back now ... !
with the new /usr, kernel 2.6.8 ...

many thanks for all helps! my heart beats ok now and the system will last for a while now ... :)
yum update ...


In the process, I found that in the future, LVM(Logical Volume Manager for the Linux operating system) will be a wiser solution at the time system implementation
http://tldp.org/HOWTO/LVM-HOWTO/index.html

imdeemvp
20th August 2004, 07:42 PM
i am happy this topic is helping us understand all the necessary feactures of fedora :D

LinuxHippy
20th August 2004, 07:54 PM
you meant you want to transfer them from one linux partition to another linux partition?

no. I have FC2 on partition hda2 and Desktop/LX on partition hda5. They are both vers of Linux and both use Sylpheed as a mail reader/writer. My mail is on hdb1. I don't want any permissions to exist on hdb1. I'd like to be able to access my mail to read and write when I am in FC2 and then when I am in Desktop/LX. What do I do to do away with permissions on hdb1?

Mat
20th August 2004, 08:35 PM
well, best bet would to create a new partition just for mail...
than you can mount it in both linuxes..

navesdeavila
4th January 2005, 03:54 PM
Hi, I`m a new linux user and I just can`t write my fstab file 'cause when I access the properties of the file, it says that I`m not the owner of the file. The problem is: I`m logged as root and the root has permission to write.

Thanks!!! :(

nyba
4th January 2005, 04:42 PM
you can chmod u+rxw fstab
to change the attribute of your fstab file, and then try to modify it
before doing that, it is best to cp fstab fstab.old to backup

imdeemvp
4th January 2005, 08:08 PM
Hi, I`m a new linux user and I just can`t write my fstab file 'cause when I access the properties of the file, it says that I`m not the owner of the file. The problem is: I`m logged as root and the root has permission to write.

Thanks!!! :(
Are you issuing this command?:gedit /etc/fstabyou can be logged as regular user and become root in terminal. So try it again.

Jesus-Franco
5th January 2005, 06:25 AM
Perfect How-To imdeemvp, I think it's perfect. Very very well written. :)

imdeemvp
5th January 2005, 06:34 AM
Thank you, but I admit that I had learned from some of the mods and by visiting some linux sites too. And for more fedora support always check out www.fedoranews.org you will learn a lot.