Linux - Mounting File Systems (CDROM, NFS, SMB, ...)
About
All files accessible in a Unix 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. Conversely, the umount command will detach it again.
In order to access any file system, it is first necessary to mount it. By mounting a file system, you direct Red Hat Linux to make:
- or a logical volume
available to the system. (To know more, see this article: Linux - Adding storage depends of LVM).
In order to mount any file system, two pieces of information must be specified:
- A device file name representing the desired disk drive and partition or the logical volume
- A directory under which the mounted file system will be made available (otherwise known as a mount point)
Articles Related
How to
Create a Mount Point
When you want to create a mount point to map a drive in Linux, a folder must be always created first.
mkdir /myMountFolder/MyMountPoint
When you create the directory with the root user, it will become a system-wide location.
See What is Mounted
In addition to mounting and unmounting disk space, it is possible to see what is mounted. There are several different ways of doing this:
- Viewing /etc/mtab
- Viewing /proc/mounts
- Issuing the df command
Mount File Systems Automatically
/etc/fstab
When a Red Hat Linux system is newly-installed, all the disk partitions defined and/or created during the installation are configured to be automatically mounted whenever the system boots.
However, what happens when additional disk drives are added to a system after the installation is done? The answer is “nothing” because the system was not configured to mount them automatically. However, this is easily changed.
The answer lies in the /etc/fstab file. This file is used to control what file systems are mounted when the system boots, as well as to supply default values for other file systems that may be mounted manually from time to time.
The following is an example of an fstab file on a typical Linux system:
# device name mount point fs-type options dump-freq pass-num LABEL=/ / ext3 defaults 1 1 /dev/hda6 swap swap defaults 0 0 none /dev/pts devpts gid=5,mode=620 0 0 none /proc proc defaults 0 0 none /dev/shm tmpfs defaults 0 0 # Removable media /dev/cdrom /mount/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0 /dev/fd0 /mount/floppy auto noauto,owner,kudzu 0 0 # NTFS Windows XP partition /dev/hda1 /mnt/WinXP ntfs-3g quiet,defaults,locale=en_US.utf8,umask=0 0 0 # Partition shared by Windows and Linux /dev/hda7 /mnt/shared vfat umask=000 0 0 # mounting tmpfs tmpfs /mnt/tmpfschk tmpfs size=100m 0 0 # mounting cifs //pingu/ashare /store/pingu cifs credentials=/root/smbpass.txt 0 0 # mounting NFS pingu:/store /store nfs rw 0 0
Each line represents one file system and contains the following fields:
- File system specifier — For disk-based file systems, either a device file or a device label specification
- Mount point — Except for swap partitions, this field specifies the mount point to be used when the file system is mounted
- File system type — The type of file system present on the specified device (note that auto may be specified to select automatic detection of the file system to be mounted, which is handy for removable media units such as diskette drives)
- Mount options — A comma-separated list of options that can be used to control mount's behavior
- Dump frequency — If the dump backup utility is used, the number in this field will control dump's handling of the specified file system
- File system check order — Controls the order in which the file system checker fsck checks the integrity of the file systems
To verify that the changes are correct, you can perform a mount command without giving the mount point such as:
[root@ebs121 ~]# mount /dev/sda2 mount: can't find /dev/sda2 in /etc/fstab or /etc/mtab