Lesson 7 | Mounting and unmounting partitions |
Objective | Describe the use of the mount and unmount commands. |
Mounting and unmounting partitions on Unix OS
Mounting Linux
You attach a new filesystem to the filesystem using the mount
command.
In its simplest form, this command's syntax on a Linux machine is
mount –t type device mount-point
This command instructs the system to attach the filesystem on the specified device special file to the directory given as a mount-point
mount-point. In addition, the mount
command takes many options that affect the way the mounted filesystem is treated.
The mount command Options
The mount
command takes many options that affect the way the mounted filesystem is treated. You specify options on the command line as a comma-separated list marked with a –o
flag. For example, this Linux command mounts /dev/fd0 with the read-only (ro
) and nosuid
options set:
mount –t ext2 –o ro,nosuid /dev/fd0
For a complete list of potential options, refer to the manual page for mount
on your system. Note also that options vary among filesystem types. Here are some common useful options for the mount
command:
Option | Purpose |
ro rw | ro =Read-only. Filesystem is mounted read-only. rw =Read-write (default). |
suid nosuid | If a filesystem is mounted nosuid , the SUID protection bit has no effect for files on that filesystem. This can be a useful security measure. The default is suid , which allows the SUID bit to take effect. |
noexec exec | If a filesystem is mounted noexec , binaries on that filesystem cannot be run; the filesystem is used for data only. The default is exec , which means binaries can be run. |
auto noauto | noauto means the filesystem must be mounted by an explicit call to the mount command, rather than automatically at boot time. This option is used in configuration files discussed in the next lesson. |
remount | remount an already mounted filesystem. Used to change the options set for a mounted filesystem, without a complete unmount , mount cycle. |
Solaris System
On a Solaris system, you would use –F
instead of –t
to specify the type of filesystem. Solaris, however, automatically mounts a filesystem once it is set up in the system configuration file. Generally, it's necessary to specify either the mount-point or the special device file in the mount
command, but not both. For example:
mount /disk1d
looks up /disk1d in the configuration file to determine what special file is used to access it and then constructs and executes the proper mount
command. We eill examine this in detail later in this module.
AIX
On AIX, use –v
instead of –t
or –F
to specify the type of filesystem.
Unmounting
The command to unmount, or unattach, a filesystem is umount
.
You may specify either the device to be unmounted or the mount-point to be released. For example:
umount mount-point
umount device-file
A filesystem cannot be unmounted if it is "busy." A filesystem is busy if some process has files open in that filesystem. For example, if your shell has the directory /home/userA as its current directory, and you try to unmount /home, you will see the following:
umount /home
/home: Device Busy
In most cases, you must have root permissions to mount or unmount filesystems. Note: How do you remove the floppy on Solaris? How do you make the CD-ROM come out of the drive? Try the eject
command. Many Sun machines have no physical eject button, so you have to rely on this command to get your removable disk out. It serves the same purpose as umount for removable devices.
A mount-point is the directory to which a filesystem will be mounted.