一、fstab文件的做用
文件/etc/fstab存放的是系統中的文件系統信息。當正確的設置了該文件,則能夠經過"mount /directory name"命令來加載一個文件系統,每種文件系統都對應一個獨立的行,每行中的字段都有空格或tab鍵分開。同時fsck、 mount、umount的等命令都利用該程序。node
二、下面是/etc/fatab文件的一個示例行: cat /proc/mounts
fs_spec fs_file fs_type fs_options fs_dump fs_pass
app
/dev/sda2 / ext4 defaults 1 1less
/dev/sda1 /boot ext4 defaults 1 2ssh
/dev/sda5 /home ext4 defaults 1 2async
/dev/sda3 swap swap defaults 0 0ide
tmpfs /dev/shm tmpfs defaults 0 0性能
fs_spec - ui
This field describes the block special device or remote filesystem to be mounted. For ordinary mounts it will hold (a link to) a block special device node (as created by mknod(8)) for the device to be mounted, like `/dev/cdrom' or `/dev/sdb7'. For NFS mounts one will have <host>:<dir>, e.g., `knuth.aeb.nl:/'. For procfs, use `proc'. Instead of giving the device explicitly, one may indicate the filesystem that is to be mounted by its UUID or LABEL (cf. e2label(8) or xfs_admin(8)), writing LABEL=<label> or UUID=<uuid>, e.g., `LABEL=Boot' or `UUID=3e6be9de-8139-11d1‐ -9106-a43f08d823a6'. It's also possible to use PARTUUID= and PARTLABEL=. These partitions identifiers are supported for example for GUID Partition Table (GPT). See mount(8), blkid(8) or lsblk(8) for more details about devices identifiers. Note that mount(8) uses UUIDs as strings. The string representation of the UUID should be based on lower case characters.
fs_file - this
This field describes the mount point for the filesystem. For swap partitions, this field should be specified as `none'. If the name of the mount point contains spaces these can be escaped as `\040'
fs_type - 編碼
This field describes the type of the filesystem. Linux supports lots of filesystem types, the most common are ext2, ext3, ext4, xfs, btrfs, vfat, sysfs, proc, nfs and cifs. For more details, see mount(8). An entry swap denotes a file or partition to be used for swapping, cf. swapon(8). An entry none is useful for bind or move mounts. More than one type may be specified in a comma-separated list. mount(8) and umount(8) support filesystem subtypes. The subtype is defined by '.subtype' suffix. For example 'fuse.sshfs'. It's recommended to use subtype notation rather than add any prefix to the first fstab field (for example 'sshfs#example.com' is deprecated).
查看系統支持的文件系統命令:ls /lib/modules/`uname -r`/kernel/fs/
fs_options -
This field describes the mount options associated with the filesystem. It is formatted as a comma separated list of options. It contains at least the type of mount plus any additional options appropriate to the filesystem type. For documentation on the available mount options, see mount(8). For documentation on the available swap options, see swapon(8).
推薦參數
noatime 關閉atime特性,提升性能,這是一個很老的特性,放心關閉,還能減小loadcycle
默認設置
defaults 使用默認設置。等於rw,suid,dev,exec,auto,nouser,async,具體含義看下面的解釋。
自動與手動掛載
auto 在啓動或在終端中輸入mount -a時自動掛載 noauto 設備(分區)只能手動掛載 The file system can be mounted only explicitly.
IO編碼設置
iocharset= 在=號後面加入你的本地編碼,彷佛在這個設備(分區)中作文件IO的時候就會自動作編 碼的格式轉換。 例如:你的某個分區是編碼是utf8,而設備中文件的編碼是gb2312,當是複製你設備中的文件到你的這 個分區時,它將自動作編碼轉換。 (不知道個人理解對不對,可是好像用下面的nls就能夠實現轉換。)
中文亂碼的解決
nls= 在=號後面加入你的本地編碼,你的中文就不會出現亂碼。
讀寫權限
umask= 這是關於讀寫權限的,好像比下面的ro,rw選項更管用!!! 例如:umask=000或0222,使得掛載時option中有default,普通用戶仍然能讀寫掛載設備中的東西。 請你們補充!!! ro 掛載爲只讀權限 rw 掛載爲讀寫權限
可執行
exec 是一個默認設置項,它使在那個分區中的可執行的二進制文件可以執行。 noexec 二進制文件不容許執行。千萬不要在你的root分區中用這個選項!!!
I/O同步
sync 全部的I/O將以同步方式進行 async 全部的I/O將以非同步方式進行
用戶掛載權限
user 容許任何用戶掛載設備。 Implies noexec,nosuid,nodev unless overridden. nouser 只容許root用戶掛載。這是默認設置。
suid Permit the operation of suid, and sgid bits. They are mostly used to allow users on a computer system to execute binary executables with temporarily elevated privileges in order to perform a specific task. nosuid Blocks the operation of suid, and sgid bits.
fs_dump -
This field is used for these filesystems by the dump(8) command to determine which filesystems need to be dumped. If the fifth field is not present, a value of zero is returned and dump will assume that the filesystem does not need to be dumped
fs_pass -
This field is used by the fsck(8) program to determine the order in which filesystem checks are done at reboot time. The root filesystem should be specified with a fs_passno of 1, and other filesystems should have a fs_passno of 2. Filesystems within a drive will be checked sequentially, but filesystems on different drives will be checked at the same time to utilize parallelism available in the hardware. If the sixth field is not present or zero, a value of zero is returned and fsck will assume that the filesystem does not need to be checked