Chapter 39 Mounting and Unmounting File Systems (Tasks)
This chapter describes how to mount and unmount file systems.
This is a list of the step-by-step instructions in this chapter.
Overview of Mounting File Systems
After you create
a file system, you need to make it available to the system so you can use
it. You make a file system available by mounting it, which attaches the file
system to the system directory tree at the specified mount point. The root
(/) file system is always mounted.
The following table provides guidelines on mounting file systems based
on how you use them.
|
Mount Type Needed
|
Suggested Mount Method
|
|
Local or remote file
systems that need to be mounted infrequently
|
The mount command that
you enter manually from the command line.
|
|
Local file systems
that need to be mounted frequently
|
The /etc/vfstab file, which mounts
the file system automatically when the system is booted in multi-user state.
|
|
Remote file systems
that need to be mounted frequently, such as home directories
|
-
The /etc/vfstab file, which automatically
mounts the file system when the system is booted in multi-user state.
-
AutoFS, which automatically mounts or unmounts the file system
when you access or change out of the directory.
To enhance performance, you can also cache the remote
file systems by using the CacheFS file system.
|
You can mount media that contains a file system by inserting the media
into the drive and running the volcheck command if necessary.
For more information on mounting removable media, see Chapter 17, Managing Removable Media (Overview).
Commands for Mounting and Unmounting File Systems
The following table lists the commands in the /usr/sbin
directory that you use to mount and unmount file systems.
Table 39–1 Commands for Mounting and Unmounting File Systems
|
Command
|
Man Page
|
Description
|
|
mount
|
mount(1M)
|
Mounts file systems and remote resources.
|
|
mountall
|
mountall(1M)
|
Mounts all file systems that are specified in the /etc/vfstab
file. The mountall command runs automatically when the
system enters multiuser mode.
|
|
umount
|
mount(1M)
|
Unmounts file systems and remote resources.
|
|
umountall
|
mountall(1M)
|
Unmounts all file systems that are specified in the /etc/vfstab file.
|
The mount and mountall commands
will not mount a read/write file system that has known inconsistencies. If
you receive an error message from the mount or mountall command, you might need to check the file system. See Chapter 42, Checking UFS File System Consistency (Tasks) for information on how to check the file system.
The umount and umountall commands
will not unmount a file system that is busy. A file system is considered busy
if one of the following is true:
-
A user is accessing a file or directory in the file system.
-
If a program has a file open in that file system.
-
If the file system is shared.
Commonly Used Mount Options
The following table describes the commonly used options that you can
specify with the mount -o option. If you
specify multiple options, separate them with commas (no spaces). For example, -o ro,nosuid.
For a complete list of mount options for each file system type, refer
to the specific mount man pages (for example, mount_ufs(1M)).
Table 39–2 Commonly Used
-o Mount Options
|
Option
|
File System
|
Description
|
|
bg | fg
|
NFS
|
If the first mount attempt fails, retries in the background
(bg) or in the foreground (fg). This
option is safe for non-critical vfstab entries. The default
is fg.
|
|
hard | soft
|
NFS
|
Specifies the procedure if the server does not respond.
The soft option indicates that an error is returned. The hard option indicates that the retry request is continued until
the server responds. The default is hard.
|
|
intr | nointr
|
NFS
|
Specifies whether keyboard interrupts are delivered to
a process that is hung while waiting for a response on a hard-mounted file
system. The default is intr (interrupts allowed).
|
|
largefiles | nolargefiles
|
UFS
|
Enables you to create files larger
than 2 Gbytes. The largefiles option means that a file
system mounted with this option might contain files larger
than 2 Gbytes, but it is not required. If the nolargefiles
option is specified, the file system cannot be mounted on a system that is
running Solaris 2.6 or compatible versions. The default is largefiles.
|
|
logging | nologging
|
UFS
|
Enables or disables logging for the file system. UFS logging
is the process of storing transactions (changes that make up a complete UFS
operation) into a log before the transactions are applied to the UFS file
system. Logging helps prevent UFS file systems from becoming inconsistent,
which means fsck can be bypassed. Bypassing fsck reduces the time to reboot a system if it crashes, or after a system
is shutdown uncleanly.
The log is allocated from free blocks on
the file system, and is sized at approximately 1 Mbyte per 1 Gbyte of file
system, up to a maximum of 64 Mbytes. The default is nologging.
|
|
atime | noatime
|
UFS
|
Suppresses access time updates on files, except when they
coincide with updates to the time of the last file status change or the time
of the last file modification. For more information, see stat(2). This option reduces disk
activity on file systems where access times are unimportant (for example,
a Usenet news spool). The default is normal access time (atime)
recording.
|
|
remount
|
All
|
Changes the mount options associated with an already-mounted
file system. This option can generally be used with any option except ro, but what can be changed with this option is dependent on the
file system type.
|
|
retry=n
|
NFS
|
Retries the mount operation when it
fails. n is the number of times to retry.
|
|
ro | rw
|
CacheFS, NFS, PCFS, UFS, HSFS
|
Specifies read/write (rw) or read-only
(ro). If you do not specify this option, the default is rw. The default option
for HSFS is ro.
|
|
suid | nosuid
|
CacheFS, HSFS, NFS, UFS
|
Allows or disallows setuid execution. The default is to allow setuid execution.
|
Field Descriptions for the /etc/vfstab File
An entry in the /etc/vfstab file has seven fields,
which are described in the following table.
Table 39–3 Field Descriptions for the
/etc/vfstab File
|
Field Name
|
Description
|
|
device to mount
|
This field identifies
one of the following:
-
The block device name for a local UFS file system (for example, /dev/dsk/c0t0d0s0).
-
The resource name for a remote file system (for example, myserver:/export/home). For more information about NFS, see System Administration Guide:
IP Services.
-
The block device name of the slice on which to swap (for example, /dev/dsk/c0t3d0s1).
-
A directory for a virtual file system type.
|
|
device to fsck
|
The raw (character) device name that
corresponds to the UFS file system identified by the device to mount field (for example, /dev/rdsk/c0t0d0s0). This
field determines the raw interface that is used by the fsck
command. Use a dash (-) when there is no applicable device,
such as for a read-only file system or a remote file system.
|
|
mount point
|
Identifies where to
mount the file system (for example, /usr).
|
|
FS type
|
Identifies the type of file system.
|
|
fsck pass
|
The pass number used
by the fsck command to decide whether to check a file system.
When the field contains a dash (-), the file system is
not checked.
When the field contains a zero, UFS file systems
are not checked but non-UFS file systems are checked. When the field contains
a value greater than zero, the file system is always checked.
All file systems with a value of 1 in this field are checked
one at a time in the order they appear in the vfstab
file. When the fsck command is run on multiple UFS file
systems that have fsck pass values greater than one and
the preen option (-o p) is used, the fsck
command automatically checks the file systems on different disks in parallel
to maximize efficiency. Otherwise, the value of the pass number does not have
any effect.
|
|
mount at boot
|
Set to yes or no for whether the file system should be automatically mounted by
the mountall command when the system is booted. Note that
this field has nothing to do with AutoFS. The root (/), /usr and /var file systems are not mounted
from the vfstab file initially. This field should always
be set to no for these file systems and for virtual file
systems such as /proc and /dev/fd.
|
|
mount options
|
A list of comma-separated options (with
no spaces) that are used for mounting the file system. Use a dash (-) to indicate no options. For a list of commonly used mount options,
see Table 39–2.
|
Note –
You must have an entry in each field in the /etc/vfstab file. If there is no value for the field, be sure to enter a
dash (-). Otherwise, the system might not boot successfully.
Similarly, white space should not be used in a field value.
Mounting File Systems
The following sections describe how to mount a file system by adding
an entry in the /etc/vfstab file or by using the mount command from the command line.
How to Determine Which File Systems Are Mounted
You can determine which file systems are already mounted by using the mount command.
|
-v
|
Displays the list of mounted file systems
in verbose mode.
|
Example—Determining Which File Systems Are Mounted
This example shows how to use the mount command to
display information about the file systems that are currently mounted.
$ mount
/ on /dev/dsk/c0t0d0s0 read/write/setuid/intr/largefiles/xattr/onerror= ...
/usr on /dev/dsk/c0t0d0s6 read/write/setuid/intr/largefiles/xattr/onerror= ...
/proc on /proc read/write/setuid/dev=4300000 on Fri Nov 30 11:25:13 2001
/etc/mnttab on mnttab read/write/setuid/dev=43c0000 on Fri Nov 30 11:25:13 ...
/dev/fd on fd read/write/setuid/dev=4400000 on Fri Nov 30 11:25:17 2001
/var/run on swap read/write/setuid/xattr/dev=1 on Fri Nov 30 11:25:20 2001
/tmp on swap read/write/setuid/xattr/dev=2 on Fri Nov 30 11:25:24 2001
/export on /dev/dsk/c0t0d0s4 read/write/setuid/intr/largefiles/xattr/ ...
/export/home on /dev/dsk/c0t0d0s7 read/write/setuid/intr/largefiles/ ...
$
|
How to Add an Entry to the /etc/vfstab File
-
Become superuser or assume an equivalent role.
-
Create a mount point for the file system to be mounted, if necessary.
There must be a mount point on the local system to mount a file system.
A mount point is a directory to which the mounted file system is attached.
-
Edit the /etc/vfstab file and add an entry. Make
sure that you do the following:
-
Separate each field with white space (a space or a tab).
-
Enter a dash (-) if a field has no contents.
-
Save the changes.
For detailed information about the /etc/vfstab
field entries, see Table 39–3.
Note –
Since the root (/) file system is mounted
read-only by the kernel during the boot process, only the remount option (and options that can be used in conjunction with remount) affect the root (/) entry in the /etc/vfstab file.
Examples—Adding an Entry to the /etc/vfstab
File
The following example shows how to mount the disk slice /dev/dsk/c0t3d0s7 as a UFS file system to the mount point directory /files1. The raw character device /dev/rdsk/c0t3d0s7
is specified as the device to fsck. The fsck pass value of 2 means that the file system will be
checked, but not sequentially.
#device device mount FS fsck mount mount
#to mount to fsck point type pass at boot options
#
/dev/dsk/c0t3d0s7 /dev/rdsk/c0t3d0s7 /files1 ufs 2 yes -
|
The following example shows how to mount the /export/man
directory from the system pluto as an NFS file system on
mount point /usr/man. A device to fsck
nor a fsck pass is specified because it's an NFS file system.
In this example, mount options are ro
(read-only) and soft.
#device device mount FS fsck mount mount
#to mount to fsck point type pass at boot options
pluto:/export/man - /usr/man nfs - yes ro,soft
|
The following example shows how to mount the root (/)
file system on a loopback mount point, /tmp/newroot.
LOFS file systems must always be mounted after the file systems that are in
the LOFS file system.
#device device mount FS fsck mount mount
#to mount to fsck point type pass at boot options
#
/ - /tmp/newroot lofs - yes -
|
How to Mount a File System (/etc/vfstab File)
-
Become superuser or assume an equivalent role.
-
Mount a file system listed in the /etc/vfstab file.
/mount-point specifies an entry in the mount point or device to mount field in the /etc/vfstab file. It is usually easier to specify the mount point.
Example—Mounting a File System (/etc/vfstab
File)
The following example shows how to mount the /usr/dist
file system that is listed in the /etc/vfstab file.
Examples—Mounting All File Systems (/etc/vfstab
File)
The following example shows the messages that are displayed if file
systems are already mounted when you use the mountall command.
# mountall
/dev/rdsk/c0t0d0s7 already mounted
mount: /tmp already mounted
mount: /dev/dsk/c0t0d0s7 is already mounted, /export/home is busy,
or the allowable number of mount points has been exceeded
|
All the file systems with a device to fsck entry
are checked and fixed, if necessary, before they are mounted.
The following example shows how to mount all the local systems that
are listed in the /etc/vfstab file.
# mountall -l
# mount
/ on /dev/dsk/c0t0d0s0 read/write/setuid/intr/largefiles/xattr/onerror= ...
/usr on /dev/dsk/c0t0d0s6 read/write/setuid/intr/largefiles/xattr/ ...
/proc on /proc read/write/setuid/dev=38c0000 on Tue Oct 30 15:45:32 2001
/etc/mnttab on mnttab read/write/setuid/dev=3980000 on Tue Oct 30 ...
/dev/fd on fd read/write/setuid/dev=39c0000 on Tue Oct 30 15:45:36 2001
/var/run on swap read/write/setuid/xattr/dev=1 on Tue Oct 30 15:45:39 ...
/tmp on swap read/write/setuid/xattr/dev=2 on Tue Oct 30 16:05:57 2001
/datab on /dev/dsk/c0t0d0s7 read/write/setuid/intr/largefiles/xattr/ ...
|
The following example shows how to mount all of the remote file systems
that are listed in the /etc/vfstab file.
# mountall -r
# mount
/ on /dev/dsk/c0t0d0s0 read/write/setuid/intr/largefiles/xattr/onerror= ...
/usr on /dev/dsk/c0t0d0s6 read/write/setuid/intr/largefiles/xattr/onerror= ...
/proc on /proc read/write/setuid/dev=38c0000 on Tue Oct 30 15:45:32 2001
/etc/mnttab on mnttab read/write/setuid/dev=3980000 on Tue Oct 30 ...
/dev/fd on fd read/write/setuid/dev=39c0000 on Tue Oct 30 15:45:36 2001
/var/run on swap read/write/setuid/xattr/dev=1 on Tue Oct 30 15:45:39 2001
/tmp on swap read/write/setuid/xattr/dev=2 on Tue Oct 30 16:05:57 2001
/datab on /dev/dsk/c0t0d0s7 read/write/setuid/intr/largefiles/xattr/ ...
/home/rimmer on pluto:/export/home/rimmer remote/read/write/setuid/xattr ...
|
How to Mount a UFS File System (mount Command)
-
Become superuser or assume an equivalent role.
-
Create a mount point for the file system to be mounted, if necessary.
There must be a mount point on the local system to mount a file system.
A mount point is a directory to which the mounted file system is attached.
-
Mount the UFS file system.
# mount [-o mount-options] /dev/dsk/device-name /mount-point
|
|
-o mount-options
|
Specifies mount options that you can use to mount a UFS file system. For a
list of options, see Table 39–2 or mount_ufs(1M).
|
|
/dev/dsk/device-name
|
Specifies the disk device name for the slice that contains the file system
(for example, /dev/dsk/c0t3d0s7). To get slice information
for a disk, see How to Display Disk Slice Information.
|
|
/mount-point
|
Specifies the directory on which to
mount the file system.
|
Example—Mounting a UFS File System (mount
Command)
The following example shows how to mount /dev/dsk/c0t3d0s7 on the /files1 directory.
# mount /dev/dsk/c0t3d0s7 /files1
|
Example—Mounting a UFS File System With Logging Enabled (mount Command)
UFS logging eliminates file system inconsistency, which can significantly
reduce the time of system reboots. The following example shows how to mount /dev/dsk/c0t3d0s7 on the /files1 directory
with logging enabled.
# mount -o logging /dev/dsk/c0t3d0s7 /files1
|
How to Mount a UFS File System Without Large Files (mount Command)
When you mount a file system, the largefiles option
is selected by default, which enables you to create files larger than 2 Gbytes.
Once a file system contains large files, you cannot remount the file system
with the nolargefiles option or mount it on a system that
is running Solaris 2.6 or compatible versions, until you remove any large
files and run the fsck command to reset the state to nolargefiles.
This procedure assumes that the file system is in the /etc/vfstab file.
-
Become superuser or assume an equivalent role.
-
Create a mount point for the file system to be mounted, if necessary.
There must be a mount point on the local system to mount a file system.
A mount point is a directory to which the mounted file system is attached.
-
Make sure there are no large files in the file system.
# cd /mount-point
# find . -xdev -size +20000000 -exec ls -l {} \;
|
/mount-point identifies the mount point of
the file system you want to check for large files.
-
Remove or move any large files in this file system to another file system,
if necessary.
-
Unmount the file system.
-
Reset the file system state.
-
Remount the file system with the nolargefiles option.
# mount -o nolargefiles /mount-point
|
Example—Mounting a File System Without Large Files (mount Command)
The following example shows how to check the /datab
file system and remount it with the nolargefiles option.
# cd /datab
# find . -xdev -size +20000000 -exec ls -l {} \;
# umount /datab
# fsck /datab
# mount -o nolargefiles /datab
|
How to Mount an NFS File System (mount Command)
-
Become superuser or assume an equivalent role.
-
Create a mount point for the file system to be mounted, if necessary.
There must be a mount point on the local system to mount a file system.
A mount point is a directory to which the mounted file system is attached.
-
Make sure the resource (file or directory) is available from a server.
To mount an NFS file system, the resource must be made available on
the server by using the share command. For information
on how to share resources, see “About the NFS Service” in System Administration
Guide: Resource Management and Network Services.
-
Mount the NFS file system.
# mount -F nfs [-o mount-options] server:/directory /mount-point
|
|
-o mount-options
|
Specifies mount options that you can use to mount an NFS
file system. See Table 39–2 for the list of commonly used mount options or mount_nfs(1M) for a complete list of options.
|
|
server:/directory
|
Specifies
the server's host name that contains the shared resource, and the path to
the file or directory to mount.
|
|
/mount-point
|
Specifies the directory on which to
mount the file system.
|
Example—Mounting an NFS File System (mount
Command)
The following example shows how to mount the /export/packages directory on /mnt from the server pluto.
# mount -F nfs pluto:/export/packages /mnt
|
x86: How to Mount a PCFS (DOS) File System From a Hard Disk (mount Command)
Use the following procedure to mount a PCFS (DOS) file system from a
hard disk.
-
Become superuser or assume an equivalent role.
-
Create a mount point for the file system to be mounted, if necessary.
There must be a mount point on the local system to mount a file system.
A mount point is a directory to which the mounted file system is attached.
-
Mount the PCFS file system.
# mount -F pcfs [-o rw | ro] /dev/dsk/device-name:logical-drive /mount-point
|
|
-o rw | ro
|
Specifies that you can mount a PCFS
file system read/write (rw) or read-only (ro). If you do not specify this
option, the default is rw.
|
|
/dev/dsk/device-name
|
Specifies the device name of the whole disk (for example, /dev/dsk/c0t0d0p0).
|
|
logical-drive
|
Specifies either the DOS logical drive
letter (c through z) or a drive number (1 through 24). Drive c is equivalent
to drive 1 and represents the Primary DOS slice on the drive. All other letters
or numbers represent DOS logical drives within the Extended DOS slice.
|
|
/mount-point
|
Specifies the directory on which to
mount the file system.
|
Note that the device-name and logical-drive must be separated by a colon.
x86: Examples—Mounting a PCFS (DOS) File System From a Hard Disk (mount Command)
The following example shows how to mount the logical drive in the primary
DOS slice on the /pcfs/c directory.
# mount -F pcfs /dev/dsk/c0t0d0p0:c /pcfs/c
|
The following example shows how to mount the first logical drive in
the extended DOS slice read-only on /mnt.
# mount -F pcfs -o ro /dev/dsk/c0t0d0p0:2 /mnt
|
Unmounting File Systems
The unmounting of a file system removes it from the file system mount
point, and deletes the entry from the /etc/mnttab file.
Some file system administration tasks cannot be performed on mounted file
systems. You should unmount a file system when the following occurs:
-
The file system is no longer needed or has been replaced by
a file system that contains more current software.
-
You need to check and repair the file system by using the fsck command. For more information about the fsck
command, see Chapter 42, Checking UFS File System Consistency (Tasks).
It is a good idea to unmount a file system before doing a complete backup.
For more information about doing backups, see Chapter 46, Backing Up Files and File Systems (Tasks).
Note –
File systems are automatically unmounted as part of the system
shutdown procedure.
You can use the umount -f option
to forcibly unmount a file system that is busy in an emergency situation.
This practice is not recommended under normal circumstances because the unmounting
of a file system with open files could cause a loss of data. This option is
only available for UFS and NFS file systems.
Prerequisites for Unmounting File Systems
The prerequisites for unmounting file systems include the following:
-
You must be superuser or assume an equivalent role.
-
A file system must be available for unmounting. You cannot
unmount a file system that is busy. A file system is considered busy if a
user is accessing a directory in the file system, if a program has a file
open in that file system, or if it is being shared. You can make a file system
available for unmounting by doing the following:
-
Changing to a directory in a different file system.
-
Logging out of the system.
-
Using the fuser command to list all processes
that are accessing the file system and to stop them if necessary. For more
details, see How to Stop All Processes Accessing a File System.
Notify users if you need to unmount a file system that they are using.
-
Unsharing the file system. For information about unsharing
a file system, see unshare(1M).
How to Verify a File System is Unmounted
To verify that you unmounted a file system or a number of file systems,
examine the output from the mount command.
$ mount | grep unmounted-file-system
$
|
How to Stop All Processes Accessing a File System
-
Become superuser or assume an equivalent role.
-
List all the processes that are accessing the file system so that you
know which processes you are going to stop.
# fuser -c [ -u ] /mount-point
|
|
-c
|
Reports on files that are mount points
for file systems and any files within those mounted file systems.
|
|
-u
|
Displays the user login name for each
process ID.
|
|
/mount-point
|
Specifies the name of the file system
for which you want to stop processes.
|
-
Stop all processes that are accessing the file system.
# fuser -c -k /mount-point
|
A SIGKILL is sent to each process that is using
the file system.
Note –
You should not stop a user's processes without first warning the
user.
-
Verify that there are no processes that are accessing the file system.
Example—Stopping All Processes Accessing a File System
The following example shows how to stop process 4006c
that is using the /export/home file system.
# fuser -c /export/home
/export/home: 4006c
# fuser -c -k /export/home
/export/home: 4006c
# fuser -c /export/home
/export/home:
|
How to Unmount a File System
Use the following procedure to unmount a file system, except for the
root (/), /usr, or /var file systems.
Note –
The root (/), /usr,
and /var file systems can be unmounted only during a
shutdown, since the system needs these file systems to function.
-
Make sure that you have met the prerequisites listed in Prerequisites for Unmounting File Systems.
-
Unmount the file system.
/mount-point is the name of the file system
that you want to unmount. This can be one of the following:
-
The directory name where the file system is mounted
-
The device name path of the file system
-
The resource for an NFS file system
-
The loopback directory for a LOFS file system
Examples—Unmounting a File System
The following example shows how to unmount a local home file system.
The following example shows how to unmount the file system on slice
7.
# umount /dev/dsk/c0t0d0s7
|
The following example shows how to forcibly unmount the /export file system.
The following example shows how to unmount all file systems in the /etc/vfstab file, except for the root (/), /proc, /var, and /usr
file systems.
All file systems are unmounted, except for those file systems that are
busy.