The fstab file has a very key mission for your Linux system. What it does is map devices to directories so those devices can be used. If you plug in an external drive or a device like such as an iPod you are going to have to take advantage of fstab. In this article you will learn how to create a proper fstab entry to make mounting devices simple.
What fstab does
As said earlier, the /etc/fstab file is a means to map devices to locations so the devices can be used. Typically when you plug in an external device that device will show up as a device in the special directory /dev. Most externally connected usb devices will show up as a variation of /dev/sda. But if you try to access that device through the /dev directory you'll have no luck. Instead you have to map the device to a regular, mountable directory so the device can be used. Without the fstab file only the root user would be able to do the mounting and the mount command would always be something like "mount /dev/sda2 /media/mp3". When the root user mounts a device in this way only the root user will have write access to the device. In the case of an mp3 player that means only the root user will be able to add music to the device. That's where fstab helps out. You can create an fstab entry that will allow standard users to mount and unmount devices as well as write to those mounted devices.
Typical fstab entry
The structure of an fstab entry is:
device mounting_directory filesystem_type options 0 0
The device will always be assigned once you have plugged in what it is you are going to mount. The easiest way to find out what has been assigned is to open up a command terminal and enter the command dmesg. Using dmesg will require you to keep issuing the command until the kernel has recognized the device. Or you could enter the command tail -f /var/log/messages (must be run as root). Using the tail command will keep follow the output of the messages log file which will give you all the information you need.
With the understanding of where you get the device location in hand let's move on to the mounting_directory entry. This is quite simple: Create a directory, as a sub directory under /media named after the device you want to mount. For instance, if you are going to mount a USB thumbdrive you can create a directory called /media/thumb or if you need to mount your iPod you can create a directory called /media/ipod. This directory is where you will be mounting your device. When the device is mounted there you will go to that directory to manage the devices' data.
The next section, filesystem_type, describes the type of file system you wanting to mount. Linux supports quite a large selection of file systems such as: cramfs, efs, ext2, ext3, vfat, fat, nfs, udf, sysv, smbfs, minix, msdos, reiserfs, hpfs, hfs, iso9660, and many more. There is also the auto file system type which means the kernel will discover the type.
The options section of fstab is where things start to grow a bit more complex. I will explain the more common options:
The final section is actually the dump/fsck section. Basically if you set these bits to 0 (off) the mounted devices will not be checked by either dump or fsck. You will rarely, if ever, need anything but zeros here.
So there it is. The basics of the oft-confusing fstab file. Later we will get into some sticker fstab issues, but for now you should have a pretty sound understanding of how fstab works.
Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.
We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.
If you like our content, and would like to help, please consider making a contribution:
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.