UNIX System Administration - II
UNIX System Administration - II
Mounting
Before you can access the files on a file system, you need to mount the file system. Mounting a
file system attaches that file system to a directory (mount point) and makes it available to the
system. The root (/) file system is always mounted. Any other file system can be connected or
disconnected from the root (/) file system.
When you mount a file system, any files or directories in the underlying mount point directory
are unavailable as long as the file system is mounted. These files are not permanently affected by
the mounting process, and they become available again when the file system is unmounted.
However, mount directories are typically empty, because you usually do not want to obscure
existing files.
Mounting is the attaching of an additional file system to the currently accessible file system of a
computer. A file system is a hierarchy of directories (also referred to as a directory tree) that is
used to organize files on a computer or storage media (e.g., a CDROM or floppy disk).
mount command
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.
All files in a Unix file system are arranged in form of a big tree rooted at ‘/‘.These files can be
spread out on various devices based on your partition table, initially your parent directory is
mounted(i.e attached) to this tree at ‘/‘, others can be mounted manually using GUI interface(if
available) or using mount command.
mount command is used to mount the file system found on a device to big tree
structure(Unix file system) rooted at ‘/‘.
1. When used without any argument, the mount command will display all currently
attached file systems:
$ mount
By default, the output will include all file systems including the virtual ones such as cgroup,
sysfs, and others. Each line contains information about the device name, the directory to which
the device is mounted to, the type of the file system and the mount options in the following form:
device_name on directory type file system_type (options)
For example, to print only the ext4 partitions you would use:
$ mount -t ext4
To mount a file system in a given location (mount point), use the mount command in the
following form:
Once the file system is attached, the mount point becomes the root directory of the mounted file
system.
For example, to mount the /dev/sdb1 file system to the /mnt/media directory you would use:
Multiple options can be provided as a comma-separated list (do not insert a space after a
comma).
You can get a list of all mount options by typing man mount in your terminal.
If the /etc/fstab contains information about the given file system, the mount command uses the
value for the other parameter and the mount options specified in the fstab file.
/etc/fstab
$[File System] [Mount Point] [File System Type] [Options] [Dump] [Pass]
7. Use the mount command in one of the following forms to attach a file system specified in
the /etc/fstab file:
Unmounting
Unmounting refers to logically detaching a file system from the currently accessible file
system(s).
Unmount command
The umount command "unmounts" a mounted file system, informing the system to complete any
pending read or write operations, and safely detaching it.
The umount command detaches the specified file system(s) from the file hierarchy. A file
system is specified by giving the directory where it has been mounted. Giving the special device
on which the file system lives may also work, but is an obsolete method, mainly because it will
fail in case this device was mounted on more than one directory.
umount is most commonly used without any of its several options. The filesystem is identified by
the full pathname of the directory in which it has been mounted, not by its type. Thus, for
example, to unmount a filesystem that is mounted in a directory called /dir1, all that would be
necessary is to type in the following at the keyboard and press the Enter key:
$umount /dir1
Likewise, a USB key device, assuming that it had been mounted in the directory /mnt/usb, would
be unmounted with the following:
$umount /mnt/usb
Tag Description
-v Verbose mode.
-d In case the unmounted device was a loop device, also free this loop device.
-a All of the file systems described in /etc/mtab are unmounted. (With umount version
2.7 and later: the proc filesystem is not unmounted.)
-t vfstype
Indicate that the actions should only be taken on file systems of the specified type.
More than one type may be specified in a comma separated list. The list of file
system types can be prefixed with no to specify the file system types on which no
action should be taken.
-O options
Indicate that the actions should only be taken on file systems with the specified
options in /etc/fstab. More than one option type may be specified in a comma
separated list. Each option can be prefixed with no to specify options for which no
action should be taken.
-f Force unmount (in case of an unreachable NFS system). (Requires kernel 2.1.116 or
later.)
-l Lazy unmount. Detach the filesystem from the filesystem hierarchy now, and cleanup
all references to the filesystem as soon as it is not busy anymore. (Requires kernel
2.4.11 or later.)