100% found this document useful (1 vote)
35 views5 pages

UNIX System Administration - II

The document discusses mounting and unmounting file systems. Mounting attaches a file system to a directory to make it accessible. Unmounting logically detaches a file system. The mount command is used to attach file systems, while umount detaches them.

Uploaded by

Allu Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
35 views5 pages

UNIX System Administration - II

The document discusses mounting and unmounting file systems. Mounting attaches a file system to a directory to make it accessible. Unmounting logically detaches a file system. The mount command is used to attach file systems, while umount detaches them.

Uploaded by

Allu Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Mounting and Unmounting File Systems

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)

2. To display only certain file systems use the -t option.

For example, to print only the ext4 partitions you would use:

$ mount -t ext4

3. Mounting a File System

To mount a file system in a given location (mount point), use the mount command in the
following form:

$ mount [OPTION...] DEVICE_NAME DIRECTORY

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:

sudo mount /dev/sdb1 /mnt/media

Usually when mounting a device with a common file system such


as ext4 or xfs the mount command will auto-detect the file system type. However, some file
systems are not recognized and need to be explicitly specified.

4. Use the -t option to specify the file system type:

$mount -t TYPE DEVICE_NAME DIRECTORY

5. To specify additional mount options, use the -o option:

$mount -o OPTIONS DEVICE_NAME DIRECTORY

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.

6. Mounting a File System using /etc/fstab


When providing just one parameter (either directory or device) to the mount command, it will
read the content of the /etc/fstab configuration file to check whether the specified file system is
listed or not.

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.

The /etc/fstab file contains a list of entries in the following form:

/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:

$mount [OPTION...] DIRECTORY

$mount [OPTION...] DEVICE_NAME

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.

The basic syntax of umount is

$umount [options] filesystem

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

Options for the umount command:

Tag Description

-V Print version and exit.

-h Print help message and exit.

-v Verbose mode.

-n Unmount without writing in /etc/mtab.

-r In case unmounting fails, try to remount read-only.

-d In case the unmounted device was a loop device, also free this loop device.

-i Don’t call the /sbin/umount.<filesystem> helper even if it exists. By default


/sbin/umount.<filesystem> helper is called if one exists.

-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.)

You might also like