特殊:Badtitle/NS100:Fstab:修订间差异
小无编辑摘要 |
|||
(未显示1个用户的7个中间版本) | |||
第1行: | 第1行: | ||
{{From|https://help.ubuntu.com/community/Fstab}} | {{From|https://help.ubuntu.com/community/Fstab}} | ||
{{Languages|UbuntuHelp:Fstab}} | {{Languages|UbuntuHelp:Fstab}} | ||
== Introduction == | == Introduction to fstab == | ||
The configuration file <code><nowiki>/etc/fstab</nowiki></code> contains the necessary information to | https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconDisks.png The configuration file <code><nowiki>/etc/fstab</nowiki></code> contains the necessary information to automate the process of mounting partitions. In a nutshell, mounting is the process where a raw (physical) partition is prepared for access and assigned a location on the file system tree (or mount point). | ||
== | * In general fstab is used for internal devices, CD/DVD devices, and network shares (samba/nfs/sshfs). Removable devices such as flash drives *can* be added to fstab, but are typically mounted by gnome-volume-manager and are beyond the scope of this document. | ||
<ol><li>Options for mount and fstab are similar. | |||
</li><li>Partitions listed in fstab can be configured to automatically mount during the boot process. | |||
</li><li>If a device/partition is not listed in fstab ONLY ROOT may mount the device/partition. | |||
</li><li>Users may mount a device/partition if the device is in fstab with the proper options.</li></ol> | |||
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconSambaShares.png For usage with network shares, see [[UbuntuHelp:SettingUpNFSHowTo|SettingUpNFSHowTo]] , [[UbuntuHelp:SettingUpSamba|SettingUpSamba]] and [http://www.debuntu.org/2006/04/27/39-mounting-a-fuse-filesystem-form-etcfstab SSHFS]. | |||
== Fstab File Configuration == | |||
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=info.png The syntax of a fstab entry is : | |||
<pre><nowiki> | <pre><nowiki> | ||
[Device] [Mount Point] [File System Type] [Options] [Dump] [Pass] | |||
or | </nowiki></pre> | ||
{|border="1" cellspacing="0" | |||
|'''fields''' ||'''description''' | |||
|- | |||
| || The device/partition (by /dev location or UUID) that contain a file system. | |||
|- | |||
| || The directory on your root file system (aka mount point) from which it will be possible to access the content of the device/partition (note: swap has no mount point). Mount points should not have spaces in the names. | |||
|- | |||
| || Type of file system (see [[UbuntuHelp:LinuxFilesystemsExplained|LinuxFilesystemsExplained]]). | |||
|- | |||
| || Mount options of access to the device/partition (see the man page for <code><nowiki>mount</nowiki></code>). | |||
|- | |||
| || Enable or disable backing up of the device/partition (the command ''dump''). This field is usually set to 0, which disables it. | |||
|- | |||
| || Controls the order in which ''fsck'' checks the device/partition for errors at boot time. The root device should be 1. Other partitions should be 2, or 0 to disable checking. | |||
|} | |||
Please refer to the examples section for sample entries. We have provided you some detailed explanations of each field: | |||
=== Device === | |||
By default, Ubuntu now uses [http://en.wikipedia.org/wiki/UUID UUID] to identify partitions. | |||
UUID=xxx.yyy.zzz | |||
To list your devices by UUID use blkid | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo blkid | |||
The | </nowiki></pre> | ||
Alternately syntax to refer to partitions : | |||
* Device : /dev/sdxy | |||
* Label : LABEL=label | |||
* Network ID | |||
* Samba : //server/share | |||
* NFS : server:/share | |||
* SSHFS : sshfs#user@server:/share | |||
=== Mount point === | |||
A mount point is a location on your directory tree to mount the partition. The default location is /media although you may use alternate locations such as /mnt or your home directory. | |||
You may use any name you wish for the mount point, but you must create the mount point before you mount the partition. | |||
For example : /media/windows | |||
<pre><nowiki> | |||
sudo mkdir /media/windows | |||
</nowiki></pre> | |||
=== File System Type === | |||
You may either use auto or specify a file system. Auto will attempt to automatically detect the file system of the target file system and in general works well. In general auto is used for removable devices and a specific file system or network protocol for network shares. | |||
Examples: | |||
* auto | |||
* vfat - used for FAT partitions. | |||
* ntfs, ntfs-3g - used for ntfs partitions. | |||
* ext2, ext3, jfs, reiserfs, etc. | |||
* udf,iso9660 - for CD/DVD. | |||
* swap. | |||
That's way the bsteest answer so far! | |||
=== Dump === | |||
This field sets whether the backup utility dump will backup file system. If set to "0" file system ignored, "1" file system is backed up. | |||
Dump is seldom used and if in doubt use 0. | |||
=== Pass (fsck order) === | |||
Fsck order is to tell fsck what order to check the file systems, if set to "0" file system is ignored. | |||
Often a source of confusion, there are only 3 options : | |||
* 0 == do not check. | |||
* 1 == check this partition first. | |||
* 2 == check this partition(s) next | |||
In practice, use "1" for your root partition, / and 2 for the rest. All partitions marked with a "2" are checked in sequence and you do not need to specify an order. | |||
Use "0" to disable checking the file system at boot or for network shares. | |||
You may also "tune" or set the frequency of file checks (default is every 30 mounts) but in general these checks are designed to maintain the integrity of your file system and thus you should strongly consider keeping the default settings. | |||
== Examples == | |||
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconEnvelope.png The contents of the file will look similar to following: | |||
<pre><nowiki> | <pre><nowiki> | ||
# /etc/fstab: static file system information. | # /etc/fstab: static file system information. | ||
第16行: | 第82行: | ||
# <file system> <mount point> <type> <options> <dump> <pass> | # <file system> <mount point> <type> <options> <dump> <pass> | ||
proc /proc proc defaults 0 0 | proc /proc proc defaults 0 0 | ||
# /dev/sda5 | |||
UUID=be35a709-c787-4198-a903-d5fdc80ab2f8 / ext3 relatime,errors=remount-ro 0 1 | |||
# /dev/sda6 | |||
UUID=cee15eca-5b2e-48ad-9735-eae5ac14bc90 none swap sw 0 0 | |||
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec,utf8 0 0 | |||
</nowiki></pre> | |||
<u>NOTE</u>: These network share examples (samba, nfs, and sshfs) assume you have already set up the appropriate server. | |||
<pre><nowiki> | |||
# FAT ~ Linux calls FAT file systems vfat) | |||
# /dev/hda1 | |||
UUID=12102C02102CEB83 /media/windows vfat auto,users,uid=1000,gid=100,dmask=027,fmask=137,utf8 0 0 | |||
# NTFS ~ Use ntfs-3g for write access (rw) | |||
# /dev/hda1 | # /dev/hda1 | ||
UUID=12102C02102CEB83 /media/windows ntfs | UUID=12102C02102CEB83 /media/windows ntfs-3g auto,users,uid=1000,gid=100,dmask=027,fmask=137,utf8 0 0 | ||
# Zip Drives ~ Linux recognizes ZIP drives as sdx'''4''' | |||
# Separate Home | |||
# /dev/sda7 | |||
UUID=413eee0c-61ff-4cb7-a299-89d12b075093 /home ext3 nodev,nosuid,relatime 0 2 | |||
# /dev/ | # Data partition | ||
UUID= | # /dev/sda8 | ||
UUID=3f8c5321-7181-40b3-a867-9c04a6cd5f2f /media/data ext3 relatime,noexec 0 2 | |||
# / | # Samba | ||
//server/share /media/samba cifs user=user,uid=1000,gid=100 0 0 | |||
# "Server" = Samba server (by IP or name if you have an entry for the server in your hosts file | |||
# "share" = name of the shared directory | |||
# "user" = your samba user | |||
# This set up will ask for a password when mounting the samba share. If you do not want to enter a password, use a credentials file. | |||
# replace "user=user" with "credentials=/etc/samba/credentials" In the credentials file put two lines | |||
# username=user | |||
# password=password | |||
# make the file owned by root and ro by root (sudo chown root.root /etc/samba/credentials && sudo chmod 400 /etc/samba/credentials) | |||
# / | # NFS | ||
Server:/share /media/nfs nfs rsize=8192 and wsize=8192,noexec,nosuid | |||
# "Server" = Samba server (by IP or name if you have an entry for the server in your hosts file | |||
# "share" = name of the shared directory | |||
/dev/ | #SSHFS | ||
sshfs#user@server:/share fuse user,allow_other 0 0 | |||
# "Server" = Samba server (by IP or name if you have an entry for the server in your hosts file | |||
# "share" = name of the shared directory | |||
</nowiki></pre> | |||
=== File System Specific Examples === | |||
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=example.png Here are a couple of basic examples for different file system types. I will use /dev/sdb1 or /dev/hda2 for simplicity, but remember that any /dev location, UUID=<some_id>, or LABEL=<some_label> can work. | |||
==== ext2 and ext3 ==== | |||
The main difference between ext2 and ext3 is that ext3 has journaling which helps protect it from errors when the system crashes. | |||
A root filesystem: | |||
<pre><nowiki> | |||
UUID=30fcb748-ad1e-4228-af2f-951e8e7b56df / ext3 defaults,errors=remount-ro,noatime 0 1 | |||
</nowiki></pre> | </nowiki></pre> | ||
A non-root file system, ext2: | |||
<pre><nowiki> | |||
/dev/sdb1 /media/disk2 ext2 defaults 0 2 | |||
</nowiki></pre> | |||
==== fat16 and fat32 ==== | |||
<pre><nowiki> | |||
/dev/hda2 /media/data1 vfat defaults,user,exec,uid=1000,gid=100,umask=000 0 0 | |||
</nowiki></pre> | |||
<pre><nowiki> | |||
/dev/sdb1 /media/data2 vfat defaults,user,dmask=027,fmask=137 0 0 | |||
</nowiki></pre> | |||
==== ntfs ==== | |||
This example is perfect for a Windows partition. | |||
<pre><nowiki> | |||
/dev/hda2 /media/windows ntfs-3g defaults,locale=en_US.utf8 0 0 | |||
</nowiki></pre> | |||
To get a list of all the | For a list of locales available on your system, run | ||
<pre><nowiki> | |||
locale -a</nowiki></pre> | |||
==== hfs+ ==== | |||
the hfs+ filesystem is generally used by Apple computers. | |||
<pre><nowiki> | |||
/dev/sdb1 /media/Macintosh_HD hfsplus rw,exec,auto,users 0 0 | |||
</nowiki></pre> | |||
== Editing fstab == | |||
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=PicDocs.png Please, before you edit system files, '''make a backup'''. The -B flag with nano will make a backup automatically. | |||
To edit the file in Ubuntu, run: | |||
<pre><nowiki> | |||
gksu gedit /etc/fstab | |||
</nowiki></pre> | |||
To edit the file in Kubuntu, run: | |||
<pre><nowiki> | |||
kdesu kate /etc/fstab | |||
</nowiki></pre> | |||
To edit the file directly in terminal, run: | |||
<pre><nowiki> | |||
sudo nano -Bw /etc/fstab | |||
</nowiki></pre> | |||
* -B = Backup origional fstab to /etc/fstab~ . | |||
* -w = disable wrap of long lines. | |||
Alternate: | |||
<pre><nowiki> | |||
sudo -e /etc/fstab | |||
</nowiki></pre> | |||
=== Useful Commands === | |||
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconGNOMETerminal.png To view the contents of <code><nowiki>/etc/fstab</nowiki></code>, run the following terminal command: | |||
<pre><nowiki> | |||
cat /etc/fstab | |||
</nowiki></pre> | |||
To get a list of all the UUIDs, use one of the following two commands: | |||
<pre><nowiki> | <pre><nowiki> | ||
sudo blkid | |||
ls -l /dev/disk/by-uuid | ls -l /dev/disk/by-uuid | ||
</nowiki></pre> | </nowiki></pre> | ||
== Other | To list the drives and relevant partitions that are attached to your system, run: | ||
<pre><nowiki> | |||
sudo fdisk -l | |||
</nowiki></pre> | |||
To mount all file systems in <code><nowiki>/etc/fstab</nowiki></code>, run: | |||
<pre><nowiki> | |||
sudo mount -a | |||
</nowiki></pre> | |||
Remember that the mount point must already exist, otherwise the entry will not mount on the filesystem. To create a new mount point, use root privileges to create the mount point. Here is the generalization and an example: | |||
<pre><nowiki> | |||
sudo mkdir /path/to/mountpoint | |||
sudo mkdir /media/disk2 | |||
</nowiki></pre> | |||
== Other Resources == | |||
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconBook-small.png Here are some more links for your convenience: | |||
* [[UbuntuHelp:UsingUUID|UUID]] | * [[UbuntuHelp:UsingUUID|UUID]] | ||
* http:// | * [http://ubuntuforums.org/showthread.php?t=283131 How to fstab] (from the Ubuntu Forums) | ||
* http://en.wikipedia.org/wiki/Fstab | |||
[[ | * [[UbuntuHelp:SettingUpNFSHowTo|SettingUpNFSHowTo]] | ||
* [[UbuntuHelp:SettingUpSamba|SettingUpSamba]] | |||
* [[UbuntuHelp:LinuxFilesystemsExplained|LinuxFilesystemsExplained]] | |||
* [[UbuntuHelp:AutomaticallyMountPartitions|AutomaticallyMountPartitions]] | |||
* [[UbuntuHelp:HowtoPartition|HowtoPartition]] | |||
[[category:UbuntuHelp]] | [[category:UbuntuHelp]] |
2011年7月2日 (六) 21:50的最新版本
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/Fstab }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/af | • {{#if: UbuntuHelp:Fstab|Afrikaans| [[::Fstab/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/ar | • {{#if: UbuntuHelp:Fstab|العربية| [[::Fstab/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/az | • {{#if: UbuntuHelp:Fstab|azərbaycanca| [[::Fstab/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/bcc | • {{#if: UbuntuHelp:Fstab|جهلسری بلوچی| [[::Fstab/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/bg | • {{#if: UbuntuHelp:Fstab|български| [[::Fstab/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/br | • {{#if: UbuntuHelp:Fstab|brezhoneg| [[::Fstab/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/ca | • {{#if: UbuntuHelp:Fstab|català| [[::Fstab/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/cs | • {{#if: UbuntuHelp:Fstab|čeština| [[::Fstab/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/de | • {{#if: UbuntuHelp:Fstab|Deutsch| [[::Fstab/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/el | • {{#if: UbuntuHelp:Fstab|Ελληνικά| [[::Fstab/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/es | • {{#if: UbuntuHelp:Fstab|español| [[::Fstab/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/fa | • {{#if: UbuntuHelp:Fstab|فارسی| [[::Fstab/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/fi | • {{#if: UbuntuHelp:Fstab|suomi| [[::Fstab/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/fr | • {{#if: UbuntuHelp:Fstab|français| [[::Fstab/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/gu | • {{#if: UbuntuHelp:Fstab|ગુજરાતી| [[::Fstab/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/he | • {{#if: UbuntuHelp:Fstab|עברית| [[::Fstab/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/hu | • {{#if: UbuntuHelp:Fstab|magyar| [[::Fstab/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/id | • {{#if: UbuntuHelp:Fstab|Bahasa Indonesia| [[::Fstab/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/it | • {{#if: UbuntuHelp:Fstab|italiano| [[::Fstab/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/ja | • {{#if: UbuntuHelp:Fstab|日本語| [[::Fstab/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/ko | • {{#if: UbuntuHelp:Fstab|한국어| [[::Fstab/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/ksh | • {{#if: UbuntuHelp:Fstab|Ripoarisch| [[::Fstab/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/mr | • {{#if: UbuntuHelp:Fstab|मराठी| [[::Fstab/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/ms | • {{#if: UbuntuHelp:Fstab|Bahasa Melayu| [[::Fstab/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/nl | • {{#if: UbuntuHelp:Fstab|Nederlands| [[::Fstab/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/no | • {{#if: UbuntuHelp:Fstab|norsk| [[::Fstab/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/oc | • {{#if: UbuntuHelp:Fstab|occitan| [[::Fstab/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/pl | • {{#if: UbuntuHelp:Fstab|polski| [[::Fstab/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/pt | • {{#if: UbuntuHelp:Fstab|português| [[::Fstab/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/ro | • {{#if: UbuntuHelp:Fstab|română| [[::Fstab/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/ru | • {{#if: UbuntuHelp:Fstab|русский| [[::Fstab/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/si | • {{#if: UbuntuHelp:Fstab|සිංහල| [[::Fstab/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/sq | • {{#if: UbuntuHelp:Fstab|shqip| [[::Fstab/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/sr | • {{#if: UbuntuHelp:Fstab|српски / srpski| [[::Fstab/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/sv | • {{#if: UbuntuHelp:Fstab|svenska| [[::Fstab/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/th | • {{#if: UbuntuHelp:Fstab|ไทย| [[::Fstab/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/tr | • {{#if: UbuntuHelp:Fstab|Türkçe| [[::Fstab/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/vi | • {{#if: UbuntuHelp:Fstab|Tiếng Việt| [[::Fstab/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/yue | • {{#if: UbuntuHelp:Fstab|粵語| [[::Fstab/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/zh | • {{#if: UbuntuHelp:Fstab|中文| [[::Fstab/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/zh-hans | • {{#if: UbuntuHelp:Fstab|中文(简体)| [[::Fstab/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:Fstab | UbuntuHelp:Fstab | {{#if: | :}}Fstab}}/zh-hant | • {{#if: UbuntuHelp:Fstab|中文(繁體)| [[::Fstab/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:Fstab|:Fstab|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :Fstab/zh | | {{#ifexist: Fstab/zh | | {{#ifeq: {{#titleparts:Fstab|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:Fstab|1|-1|}} | zh | | }}
Introduction to fstab
The configuration file /etc/fstab
contains the necessary information to automate the process of mounting partitions. In a nutshell, mounting is the process where a raw (physical) partition is prepared for access and assigned a location on the file system tree (or mount point).
- In general fstab is used for internal devices, CD/DVD devices, and network shares (samba/nfs/sshfs). Removable devices such as flash drives *can* be added to fstab, but are typically mounted by gnome-volume-manager and are beyond the scope of this document.
- Options for mount and fstab are similar.
- Partitions listed in fstab can be configured to automatically mount during the boot process.
- If a device/partition is not listed in fstab ONLY ROOT may mount the device/partition.
- Users may mount a device/partition if the device is in fstab with the proper options.
For usage with network shares, see SettingUpNFSHowTo , SettingUpSamba and SSHFS.
Fstab File Configuration
The syntax of a fstab entry is :
[Device] [Mount Point] [File System Type] [Options] [Dump] [Pass]
fields | description |
The device/partition (by /dev location or UUID) that contain a file system. | |
The directory on your root file system (aka mount point) from which it will be possible to access the content of the device/partition (note: swap has no mount point). Mount points should not have spaces in the names. | |
Type of file system (see LinuxFilesystemsExplained). | |
Mount options of access to the device/partition (see the man page for mount ).
| |
Enable or disable backing up of the device/partition (the command dump). This field is usually set to 0, which disables it. | |
Controls the order in which fsck checks the device/partition for errors at boot time. The root device should be 1. Other partitions should be 2, or 0 to disable checking. |
Please refer to the examples section for sample entries. We have provided you some detailed explanations of each field:
Device
By default, Ubuntu now uses UUID to identify partitions. UUID=xxx.yyy.zzz To list your devices by UUID use blkid
sudo blkid
Alternately syntax to refer to partitions :
- Device : /dev/sdxy
- Label : LABEL=label
- Network ID
- Samba : //server/share
- NFS : server:/share
- SSHFS : sshfs#user@server:/share
Mount point
A mount point is a location on your directory tree to mount the partition. The default location is /media although you may use alternate locations such as /mnt or your home directory. You may use any name you wish for the mount point, but you must create the mount point before you mount the partition. For example : /media/windows
sudo mkdir /media/windows
File System Type
You may either use auto or specify a file system. Auto will attempt to automatically detect the file system of the target file system and in general works well. In general auto is used for removable devices and a specific file system or network protocol for network shares. Examples:
- auto
- vfat - used for FAT partitions.
- ntfs, ntfs-3g - used for ntfs partitions.
- ext2, ext3, jfs, reiserfs, etc.
- udf,iso9660 - for CD/DVD.
- swap.
That's way the bsteest answer so far!
Dump
This field sets whether the backup utility dump will backup file system. If set to "0" file system ignored, "1" file system is backed up. Dump is seldom used and if in doubt use 0.
Pass (fsck order)
Fsck order is to tell fsck what order to check the file systems, if set to "0" file system is ignored. Often a source of confusion, there are only 3 options :
- 0 == do not check.
- 1 == check this partition first.
- 2 == check this partition(s) next
In practice, use "1" for your root partition, / and 2 for the rest. All partitions marked with a "2" are checked in sequence and you do not need to specify an order. Use "0" to disable checking the file system at boot or for network shares. You may also "tune" or set the frequency of file checks (default is every 30 mounts) but in general these checks are designed to maintain the integrity of your file system and thus you should strongly consider keeping the default settings.
Examples
The contents of the file will look similar to following:
# /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda5 UUID=be35a709-c787-4198-a903-d5fdc80ab2f8 / ext3 relatime,errors=remount-ro 0 1 # /dev/sda6 UUID=cee15eca-5b2e-48ad-9735-eae5ac14bc90 none swap sw 0 0 /dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec,utf8 0 0
NOTE: These network share examples (samba, nfs, and sshfs) assume you have already set up the appropriate server.
# FAT ~ Linux calls FAT file systems vfat) # /dev/hda1 UUID=12102C02102CEB83 /media/windows vfat auto,users,uid=1000,gid=100,dmask=027,fmask=137,utf8 0 0 # NTFS ~ Use ntfs-3g for write access (rw) # /dev/hda1 UUID=12102C02102CEB83 /media/windows ntfs-3g auto,users,uid=1000,gid=100,dmask=027,fmask=137,utf8 0 0 # Zip Drives ~ Linux recognizes ZIP drives as sdx'''4''' # Separate Home # /dev/sda7 UUID=413eee0c-61ff-4cb7-a299-89d12b075093 /home ext3 nodev,nosuid,relatime 0 2 # Data partition # /dev/sda8 UUID=3f8c5321-7181-40b3-a867-9c04a6cd5f2f /media/data ext3 relatime,noexec 0 2 # Samba //server/share /media/samba cifs user=user,uid=1000,gid=100 0 0 # "Server" = Samba server (by IP or name if you have an entry for the server in your hosts file # "share" = name of the shared directory # "user" = your samba user # This set up will ask for a password when mounting the samba share. If you do not want to enter a password, use a credentials file. # replace "user=user" with "credentials=/etc/samba/credentials" In the credentials file put two lines # username=user # password=password # make the file owned by root and ro by root (sudo chown root.root /etc/samba/credentials && sudo chmod 400 /etc/samba/credentials) # NFS Server:/share /media/nfs nfs rsize=8192 and wsize=8192,noexec,nosuid # "Server" = Samba server (by IP or name if you have an entry for the server in your hosts file # "share" = name of the shared directory #SSHFS sshfs#user@server:/share fuse user,allow_other 0 0 # "Server" = Samba server (by IP or name if you have an entry for the server in your hosts file # "share" = name of the shared directory
File System Specific Examples
Here are a couple of basic examples for different file system types. I will use /dev/sdb1 or /dev/hda2 for simplicity, but remember that any /dev location, UUID=<some_id>, or LABEL=<some_label> can work.
ext2 and ext3
The main difference between ext2 and ext3 is that ext3 has journaling which helps protect it from errors when the system crashes. A root filesystem:
UUID=30fcb748-ad1e-4228-af2f-951e8e7b56df / ext3 defaults,errors=remount-ro,noatime 0 1
A non-root file system, ext2:
/dev/sdb1 /media/disk2 ext2 defaults 0 2
fat16 and fat32
/dev/hda2 /media/data1 vfat defaults,user,exec,uid=1000,gid=100,umask=000 0 0
/dev/sdb1 /media/data2 vfat defaults,user,dmask=027,fmask=137 0 0
ntfs
This example is perfect for a Windows partition.
/dev/hda2 /media/windows ntfs-3g defaults,locale=en_US.utf8 0 0
For a list of locales available on your system, run
locale -a
hfs+
the hfs+ filesystem is generally used by Apple computers.
/dev/sdb1 /media/Macintosh_HD hfsplus rw,exec,auto,users 0 0
Editing fstab
Please, before you edit system files, make a backup. The -B flag with nano will make a backup automatically. To edit the file in Ubuntu, run:
gksu gedit /etc/fstab
To edit the file in Kubuntu, run:
kdesu kate /etc/fstab
To edit the file directly in terminal, run:
sudo nano -Bw /etc/fstab
- -B = Backup origional fstab to /etc/fstab~ .
- -w = disable wrap of long lines.
Alternate:
sudo -e /etc/fstab
Useful Commands
To view the contents of /etc/fstab
, run the following terminal command:
cat /etc/fstab
To get a list of all the UUIDs, use one of the following two commands:
sudo blkid ls -l /dev/disk/by-uuid
To list the drives and relevant partitions that are attached to your system, run:
sudo fdisk -l
To mount all file systems in /etc/fstab
, run:
sudo mount -a
Remember that the mount point must already exist, otherwise the entry will not mount on the filesystem. To create a new mount point, use root privileges to create the mount point. Here is the generalization and an example:
sudo mkdir /path/to/mountpoint sudo mkdir /media/disk2
Other Resources
Here are some more links for your convenience: