fstab syntax


fstab Syntax

Quote:
[Device] [Mount Point] [File_system] [Options] [dump] [fsck order]

Device = Physical location.
/dev/hdxy or /dev/sdxy.
x will be a letter starting with a, then b,c,….
y will be a number starting with 1, then 2,3,….
Thus hda1 = First partition on the master HD.

See Basic partitioning for more information

Note: zip discs are always numbered “4”.
Example: USB Zip = /dev/sda4.
Note: You can also identify a device by udev, volume label (AKA LABEL), or uuid.
These fstab techniques are helpful for removable media because the device (/dev/sdxy) may change. For example, sometimes the USB device will be assigned /dev/sda1, other times /dev/sdb1. This depends on what order you connect USB devices, and where (which USB slot) you use to connect. This can be a major aggravation as you must identify the device before you can mount it. fstab does not work well if the device name keeps changing.

To list your devices, first put connect your USB device (it does not need to be mounted).
By volume label:

Code:
ls /dev/disk/by-label -lah

By id:

Code:
ls /dev/disk/by-id -lah

By uuid:

Code:
ls /dev/disk/by-uuid -lah

IMO, LABEL is easiest to use as you can set a label and it is human readable.
The format to use instead of the device name in the fstab file is:
LABEL=<label> (Where <label> is the volume label name, ex. “data”).
UUID=<uuid> (Where <uuid> is some alphanumeric (hex) like fab05680-eb08-4420-959a-ff915cdfcb44).
Again, IMO, using a label has a strong advantage with removable media (flash drives).
See How to use Labels below.
For udev: udev does the same thing as LABEL, but I find it more complicated.
See How to udev for a very nice how to on udev.
Mount point.
This is where the partition is mounted or accessed within the “tree” (ie /mnt/hda1).
You can use any name you like.
In general

  1. /mnt Typically used for fixed hard drives HD/SCSI. If you mount your hard drive in /mnt it will NOT show in “Places” and your Desktop.
  2. /media Typically used for removable media (CD/DVD/USB/Zip). If you mount your hard drive in /media it WILL show in “Places” and your Desktop.

Examples:

  1. /mnt/windows
  2. /mnt/data
  3. /media/usb

To make a mount point:

Code:
sudo mkdir /media/usb

File types:
auto: The file system type (ext3, iso9660, etc) it detected automatically. Usually works. Used for removable devices (CD/DVD, Floppy drives, or USB/Flash drives) as the file system may vary on these devices.
Linux file systems: ext2, ext3, jfs, reiserfs, reiser4, xfs, swap.
Windows:
vfat = FAT 32, FAT 16
ntfs= NTFS
Note: For NTFS rw ntfs-3g
CD/DVD/iso: iso9660

To mount an iso image (*.iso NOT CD/DVD device):

Code:
sudo mount -t iso9660 -o ro,loop=/dev/loop0 <ISO_File> <Mount_Point>

Network file systems: This section assumes the server and client are already setup.
nfsExample:

Quote:
server:/shared_directory /mnt/nfs nfs <options> 0 0

More detailed information on nfs

smb (samba) : Samba mounts can be performed very easily via gui tools (See Ubuntu Wiki Setting up Samba). If you mount a samba share with the gui tools it will be placed in ~/.gvfs , a hidden directory in your home directory.
This section is limited to fstab and you will need a fstab entry to mount samba shares at boot.
smbfs is now depreciated for cifs : http://linux-cifs.samba.org/
cifs still uses a credentials file to avoid the need to enter a password. If you do not use a credentials file, you will mount a samba share with sudo and enter your username and password in a terminal.

Quote:
//Server/share /mnt/samba cifs users,auto,credentials=/path/credentials_file,noexec,noperm 0 0
  • Server = Name (if in /etc/hosts) or IP Address of samba server.
  • share = Name of shared directory (folder).
  • /mnt/samba = your desired mount point.
  • /path/credentials_file = full path to your credentials file. A credentials file should be owned by root (permissions 400) and contain two lines :
    Quote:
    username = samba_user
    password = samba_user_password

samba_user = samba user (on server).

samba_user_password = samba user password (on server).

  • noexec for security (it can be bypassed …).
  • noperm – Allows users to read/write samba shares (you still need to configure the server to allow rw on shares !!!). Without this option, users will not be able to have rwx access to new directories in the samba share. See this thread for further details.

smbfs : depreciated, but similar.

Quote:
//win_box/shared_folder /mnt/samba smbfs rw,credentials=/home/user_name/winbox-credentials.txt 0 0

And from Buck2348:

Quote:
I don’t mount any vfat shares but uid and gid work with smbfs shares. I might have to try out your syntax.
I could not automount at boot my smbfs shares until I found the this fixin the Forums. I hope it will help someone else. I think the problem was related to the fact that I don’t use a username and password in the Windows systems. All I had to do was add

Code:
username=share,password=

to the options list in the fstab line for these shares.

More detailed information on see : The Official Samba 3.2.x HOWTO and Reference Guide

sshfs : Network shares over ssh
http://ubuntu.wordpress.com/2005/10/…m-using-sshfs/

Code:
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

Options:
Ubuntu 8.04 now defaults to “relatime”. For a discussion of this option see : http://lwn.net/Articles/244829/
defaults = rw, suid, dev, exec, auto, nouser, and async.
Options for a separate /home : nodev,nosuid,relatime
My recommended options for removable (USB) drives are in green.
auto= mounted at boot
noauto= not mounted at boot
user= when mounted the mount point is owned by the user who mounted the partition
users= when mounted the mount point is owned by the user who mounted the partition and the group users
ro= read only
rw= read/write
VFAT/NTFS:
In general, ownership and permissios of vfat / ntfs are set at the time of mounting. This is often a source of confusion.
uid= Sets owner. Syntax: may use user_name or user ID #.
gid= sets group ownership of mount point. Again may use group_name or GID #.
umask can be used to set permissions if you wish to change the default.
Syntax is “odd” at first.
To set a permissions of 777, umask=000
To set permissions of 700, umask=077
Best is to set directories with executable permissions and file with read write. To do this, use fmask and dmask (rather then umask):
dmask=027
fmask=137
With these options files are not executable (all colored green in a terminal w/ ls)

NTFS ONLY:
You may now mount a ntfs partition with the “permissions” option. This options supports standard linux permissions on ntfs.

Quote:
UUID=12102C02102CEB83 /media/windows ntfs-3g auto,users,permissions 0 0

Linux native file systems: Use defaults or users. To change ownership and permissions, mount the partition, then use chown and chmod.
Note: Warning re: sync and flash devices:
Warning
Additional Options: (From wiki.linuxquestions.org/wiki/Fstab):

  • sync/async – All I/O to the file system should be done (a)synchronously.
  • auto – The filesystem can be mounted automatically (at bootup, or when mount is passed the -a option). This is really unnecessary as this is the default action of mount -a anyway.
  • noauto – The filesystem will NOT be automatically mounted at startup, or when mount passed -a. You must explicitly mount the filesystem.
  • dev/nodev – Interpret/Do not interpret character or block special devices on the file system.
  • exec / noexec – Permit/Prevent the execution of binaries from the filesystem.
  • suid/nosuid – Permit/Block the operation of suid, and sgid bits.
  • ro – Mount read-only.
  • rw – Mount read-write.
  • user – Permit any user to mount the filesystem. This automatically 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.
  • _netdev – Used for network shares (nfs, samba, sshfs, etc), mounting the network share is delayed until after the boot process brings up the network (otherwise the mount will fail as the network is not up).

Dump
Dump: Dump field sets whether the backup utility dump will backup file system. If set to “0” file system ignored, “1” file system is backed up.
Fsck order
Fsck: Fsck order is to tell fsck what order to check the file systems, if set to “0” file system is ignored.
See also: Tuning the Filesystem Check at Bootup
Fstab Examples

Quote:

/dev/sda14 /mnt/zen ext3 relatime 0 2
# Usb device (assuming vfat)
/dev/sdb1 /media/usb auto users,uid=1000,gid=100,utf8,dmask=027,fmask=137 0 0
#Data partition
LABEL=data /mnt/usr_data ext3 auto,users,rw,relatime 0 0
# Flash drive By UUID
UUID=fab05680-eb08-4420-959a-ff915cdfcb44 /media/flash vfat user,uid=1000,gid=100,utf8,dmask=027,fmask=137 0 0
/dev/disk/by-id/usb-IOMEGA_ZIP_250_059B00301400B0F1-part4 /mnt/zip vfat users,uid=1000,gid=100,utf8,dmask=027,fmask=137 0 0
/dev/hda1 /mnt/windows ntfs-3g auto,users,uid=1000,gid=100,utf8,dmask=027,fmask=1 37 0 0
# VFAT
# FAT ~ Linux calls FAT file systems vfat)
# /dev/hda1
UUID=12102C02102CEB83 /media/windows vfat auto,users,uid=1000,gid=100,utf8,dmask=027,fmask=1 37 0 0
# NTFS ~ Use ntfs-3g for write access (rw)
# /dev/hda1
UUID=12102C02102CEB83 /media/windows ntfs-3g auto,users,permissions 0 0
# Separate Home
# /dev/sda7
UUID=413eee0c-61ff-4cb7-a299-89d12b075093 /home ext3 nodev,nosuid,relatime 0 2

# Samba
//server/share /media/samba cifs user=user,uid=1000,gid=100,noperm 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

# user=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,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