System Administration Guide, Volume 1

Chapter 36 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.

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. Any other file system can be connected or disconnected from the root (/) file system.

The table below provides guidelines on mounting file systems based on how you use them.

Table 36-1 Determining How to Mount File Systems

If You Need to Mount ... 

Then You Should Use ... 

Local or remote file systems infrequently 

The mount command entered manually from the command line.

Local file systems frequently 

The /etc/vfstab file, which will mount the file system automatically when the system is booted in multi-user state.

Remote file systems frequently, such as home directories 

  • The /etc/vfstab file, which will automatically mount the file system when the system is booted in multi-user state.

  • AutoFS, which will automatically mount or unmount the file system when you change into (mount) or out of (unmount) the directory.

To enhance performance, you can also cache the remote file systems by using CacheFS. 

You can mount a CD-ROM containing a file system by simply inserting it into the drive (Volume Management will automatically mount it). You can mount a diskette containing a file system by inserting it into the drive and running the volcheck(1) command. See Chapter 14, Guidelines for Using CDs and Diskettes (Overview) for more information.

Commands Used to Mount and Unmount File Systems

The table below lists the commands in the /usr/sbin directory that you use to mount and unmount file systems.

Table 36-2 Commands for Mounting and Unmounting File Systems

Command 

Description 

mount(1M)

Mounts file systems and remote resources. 

mountall(1M)

Mounts all file systems specified in the /etc/vfstab file. The mountall command is run automatically when entering multiuser run states.

umount(1M)

Unmounts file systems and remote resources. 

umountall(1M)

Unmounts all file systems specified in the /etc/vfstab file.

The mount 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 39, Checking File System Integrity for information on how to check the file system.

The umount commands will not unmount a file system that is busy. A file system is considered busy if a user is accessing a file or directory in the file system, if a program has a file open in that file system, or if the file system is shared.

Commonly Used Mount Options

The table below describes the commonly used mount options that you can specify with the -o option of the mount command. 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 command man pages (for example, mount_ufs(1M)).

Table 36-3 Commonly Used -o Mount Options

Option 

File System 

Description 

bg | fg

NFS 

If the first 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. soft indicates that an error is returned. hard 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 a requirement. The default is largefiles. If the nolargefiles option is specified, the file system could not be mounted on a system running Solaris 2.6 or compatible versions.

logging | nologging

UFS 

Enables 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 approximately 1 Mbyte per 1 Gbyte of file system, up to a maximum of 64 Mbytes. The default is nologging.

noatime

UFS 

Suppresses access time updates on files, except when they coincide with updates to the ctime or mtime. 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, S5FS 

Specifies read/write or read-only. If you do not specify this option, the default is read/write. The default option for HSFS is ro.

suid | nosuid

CacheFS, HSFS, NFS, S5FS, UFS 

Allows or disallows setuid execution. The default is to allow setuid execution.

How to Determine Which File Systems Are Mounted

You can determine which file systems are mounted by using the mount command.


$ mount [ -v ]

-v

Displays the list of mounted file systems in verbose mode. 

Example--Determining Which File Systems Are Mounted


$ mount
/ on /dev/dsk/c0t0d0s0 read/write/setuid/intr/largefiles/onerror=panic on ...
/usr on /dev/dsk/c0t0d0s6 read/write/setuid/intr/largefiles/onerror=panic on ...
/proc on /proc read/write/setuid on Fri Sep 10 16:09:48 1999
/dev/fd on fd read/write/setuid on Fri Sep 10 16:09:51 1999
/etc/mnttab on mnttab read/write/setuid on Fri Sep 10 16:10:06 1999
/var/run on swap read/write/setuid on Fri Sep 10 16:10:06 1999
/tmp on swap read/write/setuid on Fri Sep 10 16:10:09 1999
/export/home on /dev/dsk/c0t0d0s7 read/write/setuid/intr/largefiles/onerror=panic ...
$

Mounting File Systems (/etc/vfstab File)

The /etc/vfstab Field Descriptions

An entry in the /etc/vfstab file has seven fields, which are described in the table below.

Table 36-4 /etc/vfstab Field Descriptions

Field Name 

Description 

device to mount

  • 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, Volume 3.

  • The block device name of the slice on which to swap (for example, /dev/dsk/c0t3d0s1).

  • The /proc directory for the proc 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 determines the raw interface that is used by fsck. 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

The type of file system identified by the device to mount field.

fsck pass

The pass number used by fsck 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 fsck is run on multiple UFS file systems that have fsck pass values greater than one and the preen option (-o p) is used, fsck 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.

The fsck pass field does not explicitly specify the order in which file systems are checked, other than as described above.

mount at boot

Set to yes or no for whether the file system should be automatically mounted by mountall 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 in mounting the file system. Use a dash (-) to indicate no options. See Table 36-3 for a list of commonly used mount options.


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.


How to Add an Entry to the /etc/vfstab File

  1. Become superuser.

    Also, 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.

  2. Edit the /etc/vfstab file and add an entry.


    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.


    See Table 36-4 for detailed information about the /etc/vfstab field entries. Make sure that you:

    • Separate each field with white space (a space or a tab).

    • Enter a dash (-) if a field has no contents.

  3. Save the changes.

Examples--Adding an Entry to the /etc/vfstab File

The following example mounts the disk slice /dev/dsk/c0t3d0s7 as a UFS file system attached to the mount point directory /files1 with the default mount options (read/write). It specifies the raw character device /dev/rdsk/c0t3d0s7 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 mounts the directory /export/man from the system pluto as an NFS file system on mount point /usr/man. It does not specify a device to fsck or a fsck pass because it's an NFS file system. In this example, mount options are ro (read-only) and soft. For greater reliability, specify the hard mount option for read/write NFS file systems.


#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 mounts the root (/) file system on a loopback mount point named /tmp/newroot. It specifies yes for mount at boot, no device to fsck, and no fsck pass number. LOFS file systems must always be mounted after the file systems used to make up 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)

  1. Become superuser.

    Also, 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.

  2. Mount a file system listed in the /etc/vfstab file.


    # mount mount-point
    

    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 mounts the /usr/dist file system listed in the /etc/vfstab file.


# mount /usr/dist

How to Mount All File Systems (/etc/vfstab File)

  1. Become superuser.

    Also, 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.

  2. Mount the file systems listed in the /etc/vfstab file.


    # mountall [-l | -r] [-F fstype]

    If no options are specified, all file systems listed in the /etc/vfstab file with yes in the mount at boot field are mounted.

    -l

    Mounts all the local file systems listed in the /etc/vfstab file with yes in the mount at boot field.

    -r

    Mounts all the remote file systems listed in the /etc/vfstab file with yes in the mount at boot field.

    -F fstype

    Mounts all file systems of the specified type listed in the /etc/vfstab file with yes in the mount at boot field.

    All the file systems with a device to fsck entry are checked and fixed, if necessary, before mounting.

Examples--Mounting All File Systems (/etc/vfstab File)

The following example shows the messages 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

The following example mounts all the local systems listed in the /etc/vfstab file.


# mountall -l
# mount
/ on /dev/dsk/c0t0d0s0 read/write/setuid/intr/largefiles/onerror=panic on ...
/usr on /dev/dsk/c0t0d0s6 read/write/setuid/intr/largefiles/onerror=panic on ...
/proc on /proc read/write/setuid on Fri Sep 10 16:09:48 1999
/dev/fd on fd read/write/setuid on Fri Sep 10 16:09:51 1999
/etc/mnttab on mnttab read/write/setuid on Fri Sep 10 16:10:06 1999
/var/run on swap read/write/setuid on Fri Sep 10 16:10:06 1999
/tmp on swap read/write/setuid on Fri Sep 10 16:10:09 1999
/export/home on /dev/dsk/c0t0d0s7 read/write/setuid/intr/largefiles/onerror=panic on ...

The following example mounts all the remote file systems listed in the /etc/vfstab file.


# mountall -r
# mount
/ on /dev/dsk/c0t0d0s0 read/write/setuid/intr/largefiles/onerror=panic on ...
/usr on /dev/dsk/c0t0d0s6 read/write/setuid/intr/largefiles/onerror=panic on ...
/proc on /proc read/write/setuid on Fri Sep 10 16:09:48 1999
/dev/fd on fd read/write/setuid on Fri Sep 10 16:09:51 1999
/etc/mnttab on mnttab read/write/setuid on Fri Sep 10 16:10:06 1999
/var/run on swap read/write/setuid on Fri Sep 10 16:10:06 1999
/tmp on swap read/write/setuid on Fri Sep 10 16:10:09 1999
/export/home on /dev/dsk/c0t0d0s7 read/write/setuid/intr/largefiles/onerror=panic on ...
/usr/dist on mars:/usr/dist remote/read/write/setuid on Tue Sep 14 15:32:18 1999

Mounting File Systems (mount Command)

How to Mount a UFS File System

  1. Become superuser.

    Also, 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.

  2. Mount the UFS file system by using the mount command.


    # 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. See Table 36-3 or mount_ufs(1M) for a list of options.

    /dev/dsk/device-name

    Specifies the disk device name for the slice holding the file system (for example, /dev/dsk/c0t3d0s7). See "How to Display Disk Slice Information" to get slice information for a disk.

    mount-point

    Specifies the directory on which to mount the file system. 

Example--Mounting a UFS File System

The following example mounts /dev/dsk/c0t3d0s7 on the /files1 directory.


# mount /dev/dsk/c0t3d0s7 /files1

Example--Mounting a UFS File System With Logging Enabled

UFS logging eliminates file system inconsistency, which can significantly reduce the time of system reboots. The following example mounts /dev/dsk/c0t3d0s7 on the /files1 directory with logging enabled.


# mount -o logging /dev/dsk/c0t3d0s7 /files1

How to Remount a UFS File System Without Large Files

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 running Solaris 2.6 or compatible versions, until you remove any large files and run fsck to reset the state to nolargefiles.

This procedure assumes that the file system is in the /etc/vfstab file.

  1. Become superuser.

  2. Make sure there are no large files in the file system.


    # cd mount-point
    # find . -xdev -size +20000000 -exec ls -l {} \;
    

    mount-point

    Specifies the mount point of the file system you want to check for large files. 

    If large files exist within this file system, they must be removed or moved to another file system.

  3. Unmount the file system.


    # umount mount-point
    
  4. Reset the file system state.


    # fsck mount-point
    
  5. Remount the file system with the nolargefiles option.


    # mount -o nolargefiles mount-point
    

Example--Mounting a File System Without Large Files

The following example checks the /datab file system and remounts 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

  1. Become superuser.

    Also, 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.

  2. 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. See System Administration Guide, Volume 3 for information on how to share resources.

  3. Mount the NFS file system by using the mount command.


    # 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 36-3 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

The following example mounts the /export/packages directory on /mnt from the server pluto.


# mount -F nfs pluto:/export/packages /mnt

IA: How to Mount a System V (S5FS) File System

  1. Become superuser.

    Also, 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.

  2. Mount the S5FS file system by using the mount command.


    # mount -F s5fs [-o mount-options] /dev/dsk/device_name mount-point
    

    -o mount-options

    Specifies mount options that you can use to mount a S5FS file system. See Table 36-3 for the list of commonly used mount options or mount_s5fs(1M) for a complete list of options.

    /dev/dsk/device-name

    Specifies the disk device name of the slice holding the file system (for example, /dev/dsk/c0t3d0s7). See "How to Display Disk Slice Information" to get slice information for a disk.

    mount-point

    Specifies the directory on which to mount the file system. 

IA: Example--Mounting an S5FS File System

The following example mounts /dev/dsk/c0t3d0s7 on the /files1 directory.


# mount -F s5fs /dev/dsk/c0t3d0s7 /files1

IA: How to Mount a PCFS (DOS) File System From a Hard Disk

Use the following procedure to mount a PCFS (DOS) file system from a hard disk.

  1. Become superuser.

    Also, 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.

  2. Mount the PCFS file system by using the mount command.


    # 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 or read-only. If you do not specify this option, the default is read/write. 

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

IA: Examples--Mounting a PCFS (DOS) File System From a Hard Disk

The following example mounts 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 mounts 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

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

Prerequisites

The prerequisites to unmounting file systems are:

Verifying an Unmounted File System

To verify that you unmounted a file system or a number of file systems, look at the output from the mount command. This is described in "How to Determine Which File Systems Are Mounted".

How to Stop All Processes Accessing a File System

  1. Become superuser.

  2. List all the processes that are accessing the file system, so 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

    The name of the file system for which you want to stop processes. 

  3. Stop all processes accessing the file system.


    Note -

    You should not stop a user's processes without warning.



    # fuser -c -k mount-point
    

    A SIGKILL is sent to each process using the file system.

  4. Verify that there are no processes accessing the file system.


    # fuser -c mount-point
    

Example--Stopping All Processes Accessing a File System

The following example stops 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 /, /usr, or /var):


Note -

The root (/), /usr, and /var file systems are special cases. The root (/) file system can be unmounted only during a shutdown, since the system needs the root (/) file system to function.


  1. Make sure you have met the prerequisites listed on "Prerequisites".

  2. Unmount the file system.


    # umount mount-point
    

    mount-point

    The name of the file system that you want to unmount. This can either be the directory name where the file system is mounted, the device name path of the file system, the resource for an NFS file system, or the loopback directory for LOFS file systems. 

Examples--Unmounting a File System

The following example unmounts a local home file system.


# umount /export/home

The following example unmounts the file system on slice 7.


# umount /dev/dsk/c0t0d0s7

How to Unmount All File Systems (/etc/vfstab File)

Use the following procedure to unmount all the file systems listed in the /etc/vfstab file, except for the /, /proc, /var, and /usr file systems.

  1. Make sure you have met the prerequisites listed on "Prerequisites".

  2. Unmount all the file systems listed in the /etc/vfstab file.


    # umountall
    

    All systems that are unmounted, except those that are busy.

  3. For the file systems that were busy and not unmounted, make them available to be unmounted as described in "How to Stop All Processes Accessing a File System".

  4. Repeat Step 2 as needed until all file systems are unmounted.