[POST] What Is the Linux fstab File, and How Does It Work?
If you’re running Linux, then it’s likely that you’ve needed to change some options for your file systems. Getting acquainted with fstab can make the whole process a lot easier, and it’s much easier than you think.
What Is Fstab?
Fstab is your operating system’s file system table. If you want a review of file systems, be sure to check out our other article, HTG Explains: Which Linux File System Should You Choose? In the old days, it was the primary way that the system mounted files automatically. Nowadays, you can plug in a USB drive of any kind and it’ll just pop up in Nautilus like it does in Windows and Mac OS, but once upon a time, you had to manually mount those disks to a specific folder using the “mount” command. This held true for DVDs, CDs, and even floppies (remember those?).
Back then, your only alternative was the tell the computer that anytime a specific device was plugged in, it should be automatically mounted in a specific place. This is where fstab came in, and it was awesome. Suppose you swapped hard disks on your IDE or SCSI controller. The computer could load the file systems in a different order, potentially messing things up. Fstab is configured to look for specific file systems and mount them automatically in a desired way each and every time, preventing a myriad of disasters from occurring.
Your Fstab File
The fstab file is located at:
/etc/fstab
Let’s take a look at my fstab file, shall we?

You’ll definitely see differences, but if you want to follow along with your own fstab just pop this command into a terminal:

You can also use gedit if you’re not comfortable with nano.
The Obvious Options

You’ll notice all of the entries begin with UUIDs. You may remember seeing this in one of our previous articles, How to Choose a Partition Scheme for Your Linux PC, but we’ll explain it again anyway. Each file system, during formatting, gets assigned a Universally Unique Identifier, which it takes to the grave. Since it cannot be changed, this is the ideal way to select file systems for mounting, especially for important ones. Let’s say your /home partition is on a second hard drive and you end up moving it to an external hard drive; fstab will still find that partition and mount it correctly, avoiding a failed boot. If you switch to (or are stuck using) the old method of using device identifiers to select partitions (i.e. /dev/sda1), this advantage disappears because hard drives and partitions are counted by their controllers, and can thus change.
Edit: Using UUIDs in your fstab file, while convenient for most home users, does have a few big caveats. This doesn’t work when using things like “assembled” or “network-based” devices. If you’re more of an advanced user, or plan on using things like software RAID in the future, you’re better off not using UUIDs.

The next section of fstab, like all subsequent ones, is separated by either a space or a tab, or a combination of them. Here, you’ll find the mount point. As you can see, I have a root (/) mount point, a swap, and two that I manually added in for my shared network storage drives. If you’re adding an entry to fstab, then you’ll have to manually create the mount point before you restart your computer (and the changes take effect).

Next is the section which identifies the type of file system on the partition. Many, such as ext2/3/4, ReiserFS, jFS, etc. are natively read by Linux. Your particular system may still need to have particular packages installed to be able to read and write to them. The perfect examples are my NTFS partitions; you can see that I’m using the ntfs-3g driver to access them.
The Scarier Stuff
The next few sections are what usually scare away newcomers, but they’re really not so complicated. There’s a large set of options available, but there’s a handful or so of very common ones. Let’s take a look at them. (The default option is first, followed by alternatives, but as Linux distros can be very different, your mileage may vary.)
- auto/noauto: Specify whether the partition should be automatically mounted on boot. You can block specific partitions from mounting at boot-up by using “noauto”.
- exec/noexec: Specifies whether the partition can execute binaries. If you have a scratch partition that you compile on, then this would be useful, or maybe if you have /home on a separate file system. If you’re concerned about security, change this to “noexec”.
- ro/rw: “ro” is read-only, and “rw” is read-write. If you want to be able to write to a file-system as the user and not as root, you’ll need to have “rw” specified.
- sync/async: This one is interesting. “sync” forces writing to occur immediately on execution of the command, which is ideal for floppies (how much of a geek are you?) and USB drives, but isn’t entirely necessary for internal hard disks. What “async” does is allow the command to execute over an elapsed time period, perhaps when user activity dies down and the like. Ever get a message asking to your “wait while changes are being written to the drive?” This is usually why.
- nouser/user: This allows the user to have mounting and unmounting privileges. An important note is that “user” automatically implies “noexec” so if you need to execute binaries and still mount as a user, be sure to explicitly use “exec” as an option.
These options are separated by a comma and no spaces, and can be put in any order. If you’re not sure about the defaults, it’s okay to explicitly state your options. Things that are mounted from temporary places (like USB) won’t follow this basic pattern unless you created entries for them (by UUID) in fstab. It’s convenient when you want an external hard drive to always mount in a particular way, because normal thumb-drives and the like won’t be affected.

You can see that my two storage drives have user mounting privileges enabled, read-write access enabled, and auto-mounting is turned on. I don’t compile much software, but when I do, I add the “exec” option at the end of the list.
Dumping and Fscking

The next option is a binary value (“0” for false and “1” for true) for “dumping.” This is a pretty much out-dated method of backup for cases when the system went down. You should leave this as “0”.

The last option is a numeric value for “passing.” This tells the system the order in which to fsck (pronounce that however you like), or perform a file system check. If a disk has an option of “0” it will be skipped, like my NTFS-formatted storage drives. The root file system should always be “1” and other file systems can go afterward. This works best for journaling file systems like ext3/4 and ReiserFS. Older file systems like FAT16/32 and ext2 can take a while, so it’s better to turn their fscking off and do it periodically yourself.
[POST] What Is the Linux fstab File, and How Does It Work?的更多相关文章
- Linux fstab 参数详解
[root@qs-wg-db1 /]# cat /etc/fstab LABEL=/ / ext3 defaults ...
- linux C file format analysis
c语言文件格式 source file file.c C source, ASCII text pretreatment 预处理文件 file.i C source, ASCII text assem ...
- linux move file / folder bash command
linux move file / folder bash command mv $ which mv $ man mv # mv [-f] source target/ target folder ...
- Linux Kernel File IO Syscall Kernel-Source-Code Analysis(undone)
目录 . 引言 . open() syscall . close() syscall 0. 引言 在linux的哲学中,所有的磁盘文件.目录.外设设备.驱动设备全部被抽象为了"文件" ...
- Linux:file命令显示自定义文件类型
file 命令可以查看文件类型信息,原理见: 非常Linux-file命令与magic file 修改 /ect/magic 文件后,可用 file 命令显示自定义文件类型信息. man magic ...
- linux flushing file system caches
We may drop the file system caches on Linux to free up memory for applications. Kernels 2.6.16 and n ...
- Oracle:ORA-09925 and linux Read-only file system error
今天上午有同事反映应用数据库连接不上:于是排查数据库: [oracle@db ~]$ sqlplus / as sysdba SQL*Plus: Release - Production on Thu ...
- linux command file/type which/whereis
今天遇到几个命令,初见时感觉好像啊,不太能区分其具体功能和区别,因此特来记录一下. 1. file和type file: 查看文件类型 type: display information of com ...
- Linux 命令 - file: 确定文件类型
命令格式 file [-bchikLNnprsvz0] [--apple] [--mime-encoding] [--mime-type] [-e testname] [-F separator] [ ...
随机推荐
- windows钩子(转)
1. 消息钩子 提示: 如果要设置系统级钩子, 钩子函数必须在 DLL 中. SetWindowsHookEx( idHook: Integer; {钩子类型} lpfn: TFNHookP ...
- Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. An attempt was made to load a program
今天同事在一个服务器(winserver 2008 x64)上新建了一个IIS(7) 网站,但是报了如下错误: Could not load file or assembly 'System.Data ...
- 国内A股16家上市银行的財务数据与股价的因子分析报告(1)(工具:R)
分析人:BUPT_LX 研究目的 用某些算法对2014年12月份的16家国内A股上市的商业银行当中11项財务数据(资产总计.负债合计.股本.营业收入.流通股A.少数股东权益.净利润.经营活动的现金流量 ...
- Android 为何比 iOS 卡?【转载】
Android 卡是必须的,当你的手机装了 20 多个 app,那不卡才叫见鬼了呢,我手机微信都打不开,手机直接自动重启啦~哪种东西生来就是完美的呢?即便是台式机,也是越用越慢.换句话,如果没有特别原 ...
- C#.NET常见问题(FAQ)-如何让控件或者窗体本身全屏
初始化的时候保存控件的原始尺寸,然后通过Dock属性调节 注意如果你的控件是放在容器中的,那么对应设置的也要是容器的Dock属性 全屏的效果如下图所示 更多教学视频和资料下载,欢迎关注以下 ...
- springboot结合jwt实现基于restful接口的身份认证
基于restful接口的身份认证,可以采用jwt的方式实现,想了解jwt,可以查询相关资料,这里不做介绍~ 下面直接看如何实现 1.首先添加jwt的jar包,pom.xml中添加依赖包: <de ...
- 012-Go ORM框架之Gorm测试
1:参考:https://github.com/jinzhu/gorm 2:数据库脚本(pg) -- create table posts( id serial primary key, conten ...
- Tomcat下HTTPS双向认证配置以及客户端调用案例
1:生成服务器端的keystore和truststore文件 (1)以jks格式生成服务器端包含Public key和Private Key的keystore文件 keytool -genkey -a ...
- 递归的隐含限制——处理对象小的可以、大的不可以
最近自己编写了一个求n阶行列式的值的C程序,编译成功,并且使用了一个3阶行列式进行了测试,测试也成功了.以为这样就万事大吉了,可是后来在实际应用中调用该函数时却导致程序无法运行.注意到,实际应用中要求 ...
- TP - 001