Understanding fstab
Sorry this is such a long post.
I added much of this information to the Ubuntu wiki.
update May 2009 : tbuss kindly converted this post to a pdf which is available here. The pdf can be downloaded if you log into scribd. You may use openid to log in, so should be easy if you also have an account at launchpad.
Ubuntu Wiki : fstab
There are essentially 5 sections:
- Introduction / Mount.
- "fstab syntax" - Syntax and fstab options.
- How to label, FAT and Linux file systems.
- Examples, FAT and Linux native file systems.
- References
Scroll down to the section you need.
Introduction
If you simply want a gui tool to manage your partitions (/etc/fstab) try Pysdm.
pysdm Screen Shot
/etc/fstab is a system configuration file and is used to tell the Linux kernel which partitions (file systems) to mount and where on the file system tree.
/etc/mtab is an index of all mounted partitions/file systems.
Note: See references section at the end of this how to for useful links.
How to mount
The mount command and fstab go hand in hand:
- Options for mount and fstab are similar.
- If a device/partition is not listed in fstab ONLY ROOT may mount the device/partition.
- Users can mount a removable device using pmount.
- Users may mount a device/partition if the device is in fstab with the proper options.
How to mount
Mount Partitions Automatically (At BOOT).
Filesystems and Mounting Thanks Hermanzone
mount has a multitude of options. Manpage: man mount
pmount: Pmount allows a user to mount removable media.
pmount uses /media/<NAME> as the mount point.
Syntax:Example:pmount <device> <NAME>This creates a directory "data" in /media (mount point is /media/data) and mounts your removable device there.Code:pmount /dev/dsa1 data
To unmount:Note: pmount does not like to mount to an existing directory in /media.Code:pumount <NAME>
- For example, if you have a directory /media/usb ; pmount /dev/sda1 usb may fail.
- If you are having problems with gnome-volume-manager or pmount check the contents of /media and delete directories as needed.
- Obviously do not delete a directory in /media if a device is mounted to this mount point.
Configure pmount for internal drives
To show your partitions/usb devices, first plug in your usb card.
To list your mounted partitions:To list all your partitions, mounted or not:Code:mountTo list all your partitions by UUID:Code:sudo fdisk -l
First connect all your devices, then:
============== END OF INTRODUCTION ===============Code:ls /dev/disk/by-uuid -alh
fstab Syntax
Device = Physical location.[Device] [Mount Point] [File_system] [Options] [dump] [fsck order]
/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 informationNote: 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:By id:Code:ls /dev/disk/by-label -lahBy uuid:Code:ls /dev/disk/by-id -lahIMO, LABEL is easiest to use as you can set a label and it is human readable.Code:ls /dev/disk/by-uuid -lah
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
- /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.
- /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:
- /mnt/windows
- /mnt/data
- /media/usb
To make a mount point:File types:Code:sudo mkdir /media/usb
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: iso9660To mount an iso image (*.iso NOT CD/DVD device):Network file systems: This section assumes the server and client are already setup.Code:sudo mount -t iso9660 -o ro,loop=/dev/loop0 <ISO_File> <Mount_Point>
nfs Example:server:/shared_directory /mnt/nfs nfs <options> 0 0More detailed information on nfssmb (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.
//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 :
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.
And from Buck2348://win_box/shared_folder /mnt/samba smbfs rw,credentials=/home/user_name/winbox-credentials.txt 0 0I 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 fix in 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 addto the options list in the fstab line for these shares.Code:username=share,password=More detailed information on see : The Official Samba 3.2.x HOWTO and Reference Guidesshfs : 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.
Linux native file systems: Use defaults or users. To change ownership and permissions, mount the partition, then use chown and chmod.UUID=12102C02102CEB83 /media/windows ntfs-3g auto,users,permissions 0 0
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
=========== End of fstab =============/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
How to Label
Linux: How the label and the UUID are set depends on the file system type used. It can normally be set when creating/formatting the file system and the file system type usually has some tool to change it later on (e.g. e2tunefs,xfs_admin,reiserfstune,etc.)
Labels
Mke2fs/e2label/tune2fs:
Note: For either ext2 or ext3 file systems.
WARNING: mke2fs will reformat your partition and set a label at the same time. This will delete any data on the target partition.
To set a label without reformatting use e2label or tune2fs
- Make a label:
ORCode:mke2fs -L <label> <dev>ORCode:e2label <dev> <label>Examples:Code:tune2fs -L <label> <dev>ORmke2fs -L data /dev/hda3ORe2label /dev/hda3 datatune2fs -L data /dev/hda3- Create a mount point:
Code:sudo mkdir /media/data- Add an entry to /etc/fstab:
LABEL=data /media/data ext3 defaults 0 0- To mount:
Code:sudo mount LABEL=data
ReiserFS:
Use reiserfstune:Code:reiserfstune --l <Label> <device>Note:That is a small "L" and not the number 1.JFS:
Use jfs_tune:To show the label:Code:jfs_tune -L <Label> <device>Code:jfs_tune -l <device>Note:That is a small "L" and not the number 1.XFS:
Use xfs_admin:To show the label:Code:sudo xfs_admin -L <Label> <device>Code:xfs_admin -l <device>Note:That is a small "L" and not the number 1.FAT (Windows partitions):
Use mtools to label a FAT partition:
- Install mtools:
Code:sudo aptitude install mtools- Copy the mtools configuration file to ~:
Note: ~ is shorthand for /home/user_name.Code:cp /etc/mtools.conf ~/.mtoolsrc- Mount your flash drive.
- Edit ~/.mtoolsrc:
Code:gedit ~/.mtoolsrc- Add these lines to the end of ~/.mtoolsrc:
Where <device> is the device assigned to your mounted USB device/flash drive (ie sda1, sdb1, ...).drive i: file="<device>"
mtools_skip_check=1
Note: You can do this from the command line:Code:echo 'drive i: file="<device>"' >> ~/.mtoolsrc echo mtools_skip_check=1 >> ~/.mtoolsrcAlthough you will need to edit ~/.mtoolsrc for each new device if the device assignment changes.Example: = drive i: file="/dev/sda1"- Change to drive i:
Code:mcd i:- Check the current label:
Code:mlabel -s i:- Change the current label:
Code:sudo mlabel -s i:DATA- Or
Code:sudo mlabel i:DATApieroxy reports the -s flag did not work, thanks pieroxyNote: mlabel USES ALL CAPS.- Add an entry to fstab:
Note: You can also mount the usb device with:LABEL=DATA <mount_point> vfat defaults 0 0Code:mount LABEL=<label>
NTFS (Windows partitions):Thanks to rudyj for pointing out the oversight.Use ntfsprogs:
First install ntfsprogs:Or use Synaptic.Code:sudo aptitude install ntfsprogs
Then:
- Show label:
Code:ntfslabel <device>- Change label:
Code:ntfslabel <device> <label>Where:
- <label> = your new label
- <device> = your partition to label (/dev/hda1 perhaps)
- Add an entry to fstab:
Note: You can also mount the usb device with:LABEL=DATA <mount_point> ntfs(or ntfs-3g) defaults 0 0Code:mount LABEL=<label>
============== END OF LABEL ===============
Examples of fstab options
********* FAT **********
FAT partitions are easy to share between Linux and Windows as both OS will read FAT "out of the box" without additional installation or configuration.
In this example I will use /mnt/data as my mount point.
fstab:Code:sudo mkdir /mnt/dataDefault permissions of /mnt/data:LABEL=data /mnt/data vfat <see options below> 0 0drwxr-xr-x 2 root root
- fstab options: defaults
mount /mnt/data yields: mount: only root can mount /dev/sdb1 on /mnt/data
sudo mount /mnt/data mounts the device.
Permissions:Note: ONLY ROOT has rw permissions.drwxr-xr-x 7 root root- fstab options: users,noauto,rw
mount /mnt/data mounts the partition.
Permissions:Note: The user can mount the device and has rw permissions.drwxr-xr-x 7 bodhi adm
Note: The ownership and permissions of the mount point have changed !- fstab options: users,noauto,gid=100,umask=007
mount /mnt/data mounts the partition.
Permissions:Note: The user can mount the device and now both the user and the users group have rw permissions.drwxrwx--- 7 bodhi users
Note: The ownership and permissions of the mount point have changed again !
********* Linux Native File Systems **********
In this example I will use ext3, but this holds true for ext2, reiserfs, jfs, and xfs.
fstab:Code:sudo mkdir /mnt/ext3LABEL=ext3 /mnt/ext3 auto <see options below> 0 0
- fstab options: defaults
mount /mnt/data yields: mount: only root can mount LABEL=ext3 on /mnt/ext3
sudo mount /mnt/ext3 mounts the device.
Permissions:Note: Ownership has changed ! owner=bodhi, group=users, however ONLY USER (and root of course) has rw permissions.bodhi@Arch:~$ls -l /mnt | grep ext3
drwxr-xr-x 3 bodhi users 1024 2006-11-07 17:26 ext3- fstab options: users,noauto
mount /mnt/ext3 mounts the partition.
Permissions:Note: The user can mount the device and has rw permissions.bodhi@Arch:~$mount /mnt/ext3/
bodhi@Arch:~$ls -l /mnt | grep ext3
drwxr-xr-x 3 bodhi users 1024 2006-11-07 17:26 ext3
Note: Ownership remains bodhi:users
Note: ext2 and ext3 do not take uid=xxx, gid=xxx, or umask=xxx
To set group rw permissions:
fstab options: users,noauto
- mount the partition: mount /mnt/ext3
- Set permisions of the mount point: chmod 777 /mnt/ext3
The set ownership and permissions will remain in effect with un-mount and re-boot.
Example:
Note: The permissions revert when the partition is un-mounted REDbodhi@Arch:~$chmod 777 /mnt/ext3
bodhi@Arch:~$ls -l /mnt | grep ext3
drwxrwxrwx 3 bodhi users 1024 2006-11-07 17:51 ext3
bodhi@Arch:~$umount /mnt/ext3/
bodhi@Arch:~$ls -l /mnt | grep ext3
drwxr-xr-x 2 root root 4096 2006-11-07 17:28 ext3
bodhi@Arch:~$mount /mnt/ext3/
bodhi@Arch:~$ls -l /mnt | grep ext3
drwxrwxrwx 3 bodhi users 1024 2006-11-07 17:51 ext3
bodhi@Arch:~$
Note: The permissions remain rw when the partition is re-mounted BLUE
Permissions:
Note: The user can mount the device and now both the user and the users group have rw permissions. 8)
============== END OF EXAMPLES ===============
References
Partitioning: Basic partitioning
Mount:
How to mount filesystems in Linux
Ubuntu Automatically Mount Partitions
man mount
Mount Other Filesystems
Fstab:
fstab wiki
How to edit and understand /etc/fstab
Tuning the Filesystem Check at Bootup
Labels: How to use Labels
udev: How to udev
NTFS: ntfs-3g
Zip dirve how-to: How to Zip Drive
nfs:
How to set up NFS
How to NFS v4
Debian/Ubuntu NFS Guide Short but sweeeet !
Mount Windows Sares: Mount Windows shares permanently
Samba:
Setting up Samba
How to mount smbfs shares permanently
bodhi.zazen
Bookmarks