All files accessible in a *nix system are arranged in one big tree, the file hierarchy, rooted at /. These files can be spread out over several devices. The mount command serves to attach the file system found on some device to the big file tree.
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). Here's how to manually set up fstab to automatically mount your devices and partitions at boot:
- 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
A device / partition can be automatically mounted in fstab by using the partition's UUID to reference the partition you want to mount. By default, Ubuntu now uses UUID to identify partitions. A universally unique identifier (UUID) is an identifier standard used in software construction, standardised by the Open Software Foundation. The intent of UUIDs is to enable distributed systems to uniquely identify information without significant central coordination. The UUID of a device or partition can be used in fstab to
To list your devices by UUID from the terminal use either:
ls -l /dev/disk/by-uuid
Alternatively to referencing devices by UUID, ftsab can use other syntax to refer to and mount partitions such as:
Device : /dev/sdxy
Label : LABEL=label
Samba : //server/share
NFS : server:/share
SSHFS : sshfs#user@server:/share
A mount point is a location on the directory tree to mount the partition defined by the UUID. The default mount location is /media although you may specify and use alternate locations such as /mnt.
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 to mount a folder at the mount point: /media/windows
The mount point would have to be created first, this can be done through the terminal as per creating a directory:
sudo mkdir /media/windows
Then the mount can be made e.g.
sudo mount UUID=thedeviceUUID /media/windows options
/etc/fstab contains the necessary information to automate the process of mounting partitions and the configuration file can be opened through a terminal with:
sudo gedit /etc/fsab#
The syntax of a fstab entry is:
[Device] [Mount Point] [File System Type] [Options] [Dump] [Pass]
[Device] = The device/partition (by /dev location or UUID) that contains a file system you want to mount.
[Mount Point] = The mount point from which it will be possible to access the content of the device/partition. Mount points should not have spaces in the names.
[File System Type] = The type of file system
[Options] = Options are dependent on the file system. You may use "defaults" here, where Ubuntu uses relatime as default for linux native file systems.
Other common options:
sync/async - All I/O to the file system should be done (a)synchronously. auto - The filesystem can be mounted automatically at bootup
noauto - The filesystem will NOT be automatically mounted at startup
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 - this is a network device, mount it after bringing up the network. Only valid with fstype nfs.
For specific options with specific file systems see: man mount
[Dump] = Enable or disable backing up of the device/partition (the command dump). This field is usually set to 0, which disables it.
[Pass] = 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.
Use the command cat /etc/fstab to read your current fstab file:
# /etc/fstab: static file system information.
# Use 'blkid -o value -s UUID' to print the universally unique identifier
# for a device; this may be used with UUID= as a more robust way to name
# devices that works even if disks are added and removed. See fstab(5).
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc nodev,noexec,nosuid 0 0
# / was on /dev/sda1 during installation
UUID=5235fc71-828f-4733-a3d0-bd05a1fba472 / ext4 errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=46ebe12c-3c21-4cf4-b3b6-04302917e1df none swap sw 0 0
# / was on /dev/sda1 during installation
#UUID=5235fc71-828f-4733-a3d0-bd05a1fba472 /DataDrive ext4 errors=remount-ro 0 1
# BackupDrive was on /dev/sdb1 during installation
UUID=ae240116-45f8-4ab3-88c7-ed4996462329 /BackupDrive ext4 errors=remount-ro 0 1
To add another device/partition to mount:
- create a new uncommented line in fstab
- add the UUID of the device/partition to mount using the UUID obtained using sudo blkid
- next include the desired mount point
- then add the file system type for the device/partition, this can be found with sudo blkid
- then add the options, my preference errors=remount-ro
- then dump, typically 0
- and finally add the fsck pass, typically 2
- save fstab
- reboot to test