jump to navigation

Mounting File Systems on Linux December 25, 2010

Posted by Tournas Dimitrios in Linux.

Possibly the first and most obvious difference for anyone coming from the Windows world is that Linux does not have drive letters. Instead, Linux mounts file systems into the root file system. This tutorial aims to explain what a file system is, and how to mount and configure fstab to mount them automatically.

A device is the physical device on which the various file systems are stored. For example, your CD-ROM drive is a device, and the CD holds the file system. Hard disks are also devices, and depending on how they are partitioned, could hold multiple file systems.

Below is an example of a typical dual-boot setup, it is 120gb disk split into 4 partitions (file systems).

Partition table of a disk
Device File system Size
/dev/hda1 NTFS 15G
/dev/hda2 ext3 15G
/dev/hda3 swap 80G
/dev/hda4 FAT32 80G

We have 4 partitions on this device. File systems come in many flavours, this greatly depends on the operating system that is installed, see Common Filesystems below.

You should also note that a file system can exist on another computer, in the case of NFS (Network File System), you can mount a share from another computer. More on NFS and Windows shares later.

Mounting a File System :

In order for Linux to be able to see and use the contents of a file system, it must first be mounted. To mount a file system you use the mount command. The format of the command is shown below.

mount -t filesystem /device/path /mountpoint/path

A file system is mounted into what’s called a mount point. The mount point is simply a directory where the mounted file system will be placed. For example if I were to mount /dev/hda4 from the table above into /mnt/data then /mnt/data would contain the contents of that file system. The mount point must exist in order for the mount to succeed. Use ‘ mkdir /mnt/name‘ to create a mount point.

The -t switch tells the mount program what type of file system we are mounting, so to mount the hda6 FAT32 partition, you would issue the command:

mount -t vfat /dev/hda6 /mnt/data

For common file systems, such as FAT32, and EXT2/3 you do not need to include the partition type.
Unmounting a File System :

When you shut down your computer, Linux will unmount the file systems for you, when a file system is unmounted, any unwritten data is written and the file system becomes unavailable. When using removable media such as floppy disks, it’s important to remember to unmount it before removing the disk, or you may loose data.

To unmount a file system, you only need to pass the mount point:

umount /mnt/data

If a file is being used, you will receive an error saying “Device is busy”. You will also receive this error if you are currently in a directory within the file system, make sure you ‘cd’ out of any directories and close all files before unmounting.
Introducing fstab :

Manually mounting file systems is time consuming and can only be done by the root account, that is unless there is an entry for the mount in fstab.

fstab (file system table) is a file that stores a list of file systems and their associated mount points. You can find fstab in /etc/fstab. When this file is configured, you only need to provide the mount point to the mount command. It also allows users to mount and unmount file systems.

Each line in fstab is in the format ‘device mount_point filesystem_type options 0 0‘. Below is a sample fstab file:

The fstab file
Device Mount point FS Type Options
/dev/hda1 / ext3 defaults 1 1
/dev/hdb1 /home ext3 defaults 1 2
/dev/cdrom /media/cdrom auto auto ro,noauto,user,exec 0 0
/dev/fdo /media/floppy auto ro,noauto,user,exec 0 0
/dev/hda2 swap swap defaults 0 0

The first 3 columns you should already know, they are the device, the mount point and of course the file system. Note that auto is not a file system, if used mount will automatically detect what file system is on the device.
Mount Options :

Column 4 above lists the options to use with the mount. Options are separated with a command without a space. Valid options are:

mount options
auto/noauto Specified whether the device will be mounted automatically when the system boots.
user/nouser Specifies whether a user can mount the device, user allows any system user to mount it, nouser restricts mounting to the root account only.
exec/noexec: Specifies whether binaries can be executed from the partition, exec allows this, noexec doesn’t. Exec is the default option.
rw/ro Specifies whether the mount is read-only (ro) or read-write (rw). Obviously you won’t be able to write to a read-only file system.
sync/async: Specifies how data is written to the device, sync means that it is done synchronously. This means that data is written as and when you save/copy a file etc. async is done asynchronously, meaning a file could be written some time after you actually save it. Both have their advantages, but be careful using async on removable devices such as floppies.

Alternatively, if you want to use the default options, just use defaults in the options field, the default options are: rw,suid,dev,exec,auto,nouser,async.
Dump and fsck :

The final two options on the line are the dump and fsck options. The first value is the priority for dump (a backup utility). The root file system should have a value of 1, other drives should follow after in order of priority, 2, 3 etc. This should be set to 0 for removable and networked file systems.

The second number is for fsck and determines the order that the file system is checked. If it is set to 0 it will be ignored. The root file system should be 1.
Mounting Other Filesystems :
NTFS Partitions : Fedora includes the ntfs-3g file system, which allows read-write access to NTFS partitions. If you find that ntfs-3g is missing, you can install it with:

yum install ntfs-3g


yum install kmod-ntfs

You can then mount the file system using ‘ntfs’ (read-only) or ‘ntfs-3g’ as the file system type:

mount -t ntfs-3g /dev/hda1 /mnt/ntfs

Mounting NFS File Systems :

You can manually mount an NFS file system using the mount command:

mount -t nfs server:/dir/name /mnt/point

To add an entry into fstab, the device is in the format of the computer name or IP address followed by a colon and the path to the mount point, the file system is always NFS:

server:/opt/public /mnt/pub nfs options 0 0


For NFS, the options are as follows:
hard/soft When set to hard, a program using a file on the server will stop and wait for the server to come back online if the file systems becomes unavailable. When set to soft, the progrma should report an error.Note that with hard, unless intr is specified, the user cannot terminate the process waiting for the server to become available.
intr Allows NFS requests to be interrupted if the server becomes unavailable.
tcp Specified to use TCP instead of UDP which is the default, TCP is more reliable and better on heavy load networks.

There are of course many more options for NFS, there is a a NFS tutorial here which has more information on NFS mounts.
Mounting Windows/Samba Shares :

Mounting a Windows share is similar to NFS, however you may need to pass the username and password to the server. Like NTFS, there are two file system types you can use: ‘smbfs’ and ‘cifs’. Using ‘smbfs’ works on versions of Windows prior to Server 2003 and Samba.

For servers running Server 2003 or later, you need to use ‘cifs’.

To manually mount a Windows share, use the command:

mount -t smb //server/share /mnt/point -o username=user,password=pass

To add a Windows share to fstab, enter the file system as smbfs, add the username and password to the options column e.g.

//server/share /mnt/point smbfs username=user,password=pass,auto 0 0

You can use the standard options (see 3.1. Mount Options) for whether you want the mount accessible to users and to mount on boot up.
Common File Systems :

For reference, below is a list of some common file system types:

For reference, below is a list of some common file system types:
ext2 and ext3 Currently the standard file system for Linux systems, obviously ext3 is newer. Ext3 is journaled, meaning that should you experience a power cut, you shouldn’t loose any data.
ReiserFS Some Linux distributions have started using ReiserFS, so if you’re using a fairly new distro, it’s possible that your Linux partitions are using this instead of ext2 or ext3. ReiserFS, like ext3 is a journaled file system, but is much more advanced, many Linux distro’s have started using ReiserFS.
swap Well yeah, it’s the swap partition…
vfat aka FAT, FAT16 or FAT32, is the file system used by Windows 9x and Millennium Edition and is supported by NT, 2000 and XP. The NT line prefer to use the NTFS file system (see below), If you are dual booting Linux and Windows and need to share data between them, it’s a good idea to create a vfat partition as LInux support for NTFS at the moment is read-only.
NTFS The NT File System obviously belongs to the Windows NT line of operating systems, these include Windows 2000 and XP, Server 2003 and Vista. Depending on your distro, you may or may not have NTFS support built in.


1. NFS: Network File System on Linux « Tournas Dimitrios - December 25, 2010

[…] file systems under Linux. If you aren’t up to speed on mounting within Linux, read the mounting tutorial first. What is […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s