Difference between revisions of "Fstab"

From ArchWiki
Jump to: navigation, search
(Cleaned up labels section, page still needs some work)
Line 120: Line 120:
 
'''Note''' that the UUIDs of ntfs partitions are smaller than the one for linux partitions. There is also UUID subvolume for btrfs.
 
'''Note''' that the UUIDs of ntfs partitions are smaller than the one for linux partitions. There is also UUID subvolume for btrfs.
  
== Using Unambiguous Label Identifiers ==
+
== Labels ==
The same {{Filename|/etc/fstab}} using unambiguous label identifiers.
+
 
 +
Labels should be un-ambiguous.  That is that each label needs to be unique in order to not cause any conflicts.  Devices and partitions can be labeled and used as identifiers in your {{Filename|/etc/fstab}} file. For example:
  
 
  # <file system>        <dir>        <type>    <options>            <dump> <pass>
 
  # <file system>        <dir>        <type>    <options>            <dump> <pass>
Line 131: Line 132:
 
  /dev/fd0              /media/fl    auto      user,noauto            0      0
 
  /dev/fd0              /media/fl    auto      user,noauto            0      0
 
   
 
   
  LABEL=ROOT              /            ext4      defaults,noatime        0      1
+
  LABEL=Arch_Root        /            ext4      defaults,noatime        0      1
  LABEL=HOMES            /home        ext4      defaults,noatime        0      2
+
  LABEL=Arch_Home        /home        ext4      defaults,noatime        0      2
  LABEL=SWAP              swap          swap      defaults                0      0
+
  LABEL=Arch_Swap        swap          swap      defaults                0      0
 +
 
 +
The device or partition will need to be labeled first.  You can use a common application like {{Package Official|gparted}} to label partitions (not all filesystem types support labels however) or you can use {{Codeline|e2label}} to label ext2, ext3, and ext4 partitions.
 +
 
 +
To label a device or partition it can not be mounted(needs source), boot from a LiveCD or LiveUSB to do this.  Then you can label by:
  
=== Labeling a Partition ===
+
  e2label /dev/sda6 Arch_Root
There are a number of utils one can use to set a partition label. You can't have the filesystem you wish to label mounted so you may need to boot with your Arch CD and then set the label (particularly for your / and /home partitions).
 
==== e2label ====
 
An example using e2label to label your /dev/sda2 as 'HOMES'
 
# e2label /dev/sda6 HOMES
 
  
==== GParted ====
+
Labels can be up to 16 characters longThey can also have spaces too, but there is no way to have your {{Filename|fstab}} file (or [[GRUB]] configuration file for that matter) be able to recognize them by that label if you do.
GParted is a graphical means to do many disc changes including labelsJust like e2label, it cannot modify a mounted filesystem.  If you want to use GParted to set labels on your / and /home partitions, consider booting from the [[http://gparted.sourceforge.net/download.php GParted LiveCD]].  Once you are in the GUI, simply right-click the drive partition in question and select 'label' from the sub-menu.
 
  
 
=See also =
 
=See also =

Revision as of 02:12, 26 November 2009

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end The Template:Filename file contains static filesystem information. It defines how storage devices and partitions are to be initialized and integrated into the overall system.

A closer look at the fstab file

Lets have a closer look to the build up of the file. A typical entry has the following fields (fields are separated by either a space or a tab):

<file system>	<dir>	<type>	<options>	<dump>	<pass>
  • The first field, <file systems> is pretty straightforward. This entry tells the mount command exactly what to mount, so one should substitute for this entry the device name, remote partition, or similar.
  • The second field, <dir>, tells the mount command where it should mount the <file system>.
  • The <type> field tells the mount command the file system type of the device or partition to be mounted. Many different file systems are supported. For a complete list of supported file systems, consult the mount man-page. Typical names to be used include among others ext2, ext3, reiserfs, xfs, jfs, smbfs, iso9660, vfat, ntfs, swap, and auto. 'auto' is NOT a file system, it lets the mount command guess what type of file system is used, particularly handy for removable devices, floppies, and cdroms.
  • Moving on to the next field, which is the <options> field. I will only put the most common options here, not to confuse people ;). For a complete list see the mount manpage.
auto        File system will mount automatically at boot, or when the command 'mount -a' is issued.
noauto	    The file system can be mounted only explicitly.
exec	    Again this is a default option. The 'exec' option lets you execute binaries that are on that partition.
noexec	    Binaries are not allowed to be executed. NEVER use this option for your root file system!
ro	    Mount file system read only
rw 	    Mount file system read-write
sync	    All I/O should be done synchronously
async	    All I/O should be done asynchronously
user	    Permit any user to mount the filesystem. Implies noexec,nosuid,nodev unless overridden.
nouser	    Only permit root to mount the filesystem. This is also a default setting.
defaults    Use default settings. Equivalent to rw,suid,dev,exec,auto,nouser,async.
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.
noatime     Do not update inode access times on this file system.
nodiratime  Do not update directory inode access times on this filesystem.
relatime    Update inode access times relative to modify or change time. Access time is only updated if the previous
            access time was earlier than the current modify or change time. (Similar to noatime, but doesn't break
            mutt or other applications that need to know if a file has been read since the last time it was modified.)
Tip: the use of either Template:Codeline or Template:Codeline improves the performance of your system, see Maximizing Performance#noatime, nodiratime and relatime mount options.
  • Over to the fifth field, <dump>. The <dump> entry is used by the dump utility to decide when to make a backup. When installed (dump is not installed by a standard installation of Arch Linux), dump checks the entry and uses the number to decide if a file system should be backed up. Possible entries are 0 and 1. If 0, dump will ignore the file system, if 1, dump will make a backup. Most users will not have dump installed, so they should put 0 for the <dump> entry.
  • The last entry is <pass>. fsck looks at the number substituted for <pass> and determines in which order the file systems should be checked. Possible entries are 0, 1, and 2. File systems with a <pass> value 0 will not be checked by the fsck utility. The root file system should have the highest priority, 1, all other file systems you want to have checked should get a 2.

Example /etc/fstab

One can define file systems within the Template:Filename in three different ways: by device, by UUID, or by labels. Each is discussed below and examples given. The advantage to using either of the latter two is that they are wed to the partition regardless of disk order. In other words, if you have multiple HDDs and for some reason, they get switched, Arch doesn't wig out.

Although rare, this can happen. For example, your controller resets the order of your HDDs (i.e. hdd0 and hdd1 get switched where the second drive becomes the first). You can make this situation simply by switching data cables from your HDDs to your motherboard.

Using Device Identifiers

Here is a typical Template:Filename using Device (/dev/sdx) formatted identifiers.

# <file system>        <dir>         <type>    <options>             <dump> <pass>
none                   /dev/pts      devpts    defaults                0      0
none                   /dev/shm      tmpfs     defaults                0      0

/dev/cdrom             /media/cd     iso9660   ro,user,noauto,unhide   0      0
/dev/dvd               /media/dvd    udf       ro,user,noauto,unhide   0      0
/dev/fd0               /media/fl     auto      user,noauto             0      0

/dev/sda2              /             ext4      defaults,noatime        0      1
/dev/sda6              /home         ext4      defaults,noatime        0      2
/dev/sda7              swap          swap      defaults                0      0

Listing Drive Partitions

There are a number of programs to accomplish this task.

fdisk

Use fdisk with the -l switch to get a listing of all partitions/HDDs on your system.

# fdisk -l
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000d4c1g
 
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        2550    20482843+   b  W95 FAT32
/dev/sda2            2551        5100    20482875   83  Linux
/dev/sda3            5101        7650    20482875   83  Linux
/dev/sda4            7651      121601   915311407+   5  Extended
/dev/sda5            7651       10200    20482843+  83  Linux
/dev/sda6           10201       17849    61440561   83  Linux
/dev/sda7           17850       18104     2048256   82  Linux swap / Solaris
/dev/sda8           18105       18113       72261   83  Linux
/dev/sda9           18114      121601   831267328+   7  HPFS/NTFS

GParted

GParted is a graphical means to do many disc changes including displaying a graphical map of your HDDs. Install gparted via pacman

# pacman -S gparted

Run it from the shell (type gparted as root) or if using Gnome, Applications>Tools>Gparted Partition Editor

Using UUID Identifiers (main article: Persistent block device naming)

The same Template:Filename using the UUID identifiers.

# <file system>        <dir>         <type>    <options>             <dump> <pass>
none                   /dev/pts      devpts    defaults                0      0
none                   /dev/shm      tmpfs     defaults                0      0

/dev/cdrom             /media/cd     iso9660   ro,user,noauto,unhide   0      0
/dev/dvd               /media/dvd    udf       ro,user,noauto,unhide   0      0
/dev/fd0               /media/fl     auto      user,noauto             0      0

UUID=24f28fc6-717e-4bcd-a5f7-32b959024e26              /             ext4      defaults,noatime        0      1
UUID=03ec5dd3-45c0-4f95-a363-61ff321a09ff              /home         ext4      defaults,noatime        0      2
UUID=4209c845-f495-4c43-8a03-5363dd433153              swap          swap      defaults                0      0

Getting UUIDs

blkid command will allow you to list your partitions and the UUID associated with it, if there is any. For example:

# blkid
/dev/sda1: UUID="76E4F702E4F6C401" LABEL="vista" TYPE="ntfs"
/dev/sda2: LABEL="Root" UUID="24f28fc6-717e-4bcd-a5f7-32b959024e26" TYPE="ext4"
/dev/sda6: LABEL="Home" UUID="03ec5dd3-45c0-4f95-a363-61ff321a09ff" TYPE="ext4" 
/dev/sda7: LABEL="swap" UUID="4209c845-f495-4c43-8a03-5363dd433153" TYPE="swap"
/dev/sda10: UUID="0ea7a93f-537c-4868-9201-0dc090c050e4" TYPE="crypto_LUKS"
/dev/mapper/sda10: UUID="d3560bbb-b5d5-46c5-a7a8-434c885217c7" UUID_SUB="425ab275-d520-4636-8d16-55fb2b957971" TYPE="btrfs"

the UUIDs are generated for you by the mkfs.* commands, when you create the filesystems.

Note that the UUIDs of ntfs partitions are smaller than the one for linux partitions. There is also UUID subvolume for btrfs.

Labels

Labels should be un-ambiguous. That is that each label needs to be unique in order to not cause any conflicts. Devices and partitions can be labeled and used as identifiers in your Template:Filename file. For example:

# <file system>        <dir>         <type>    <options>             <dump> <pass>
none                   /dev/pts      devpts    defaults                0      0
none                   /dev/shm      tmpfs     defaults                0      0

/dev/cdrom             /media/cd     iso9660   ro,user,noauto,unhide   0      0
/dev/dvd               /media/dvd    udf       ro,user,noauto,unhide   0      0
/dev/fd0               /media/fl     auto      user,noauto             0      0

LABEL=Arch_Root        /             ext4      defaults,noatime        0      1
LABEL=Arch_Home        /home         ext4      defaults,noatime        0      2
LABEL=Arch_Swap        swap          swap      defaults                0      0

The device or partition will need to be labeled first. You can use a common application like Template:Package Official to label partitions (not all filesystem types support labels however) or you can use Template:Codeline to label ext2, ext3, and ext4 partitions.

To label a device or partition it can not be mounted(needs source), boot from a LiveCD or LiveUSB to do this. Then you can label by:

e2label /dev/sda6 Arch_Root

Labels can be up to 16 characters long. They can also have spaces too, but there is no way to have your Template:Filename file (or GRUB configuration file for that matter) be able to recognize them by that label if you do.

See also