Previous Page
Next Page

Unmounting a File System

Unmounting a file system removes it from the file system mount point and deletes the entry from /etc/mnttab. Some file system administration tasks, such as labelit and fsck, cannot be performed on mounted file systems. You should unmount a file system if any of the following three conditions exist:

  • The file system is no longer needed or has been replaced by a file system that contains software that is more current.

  • When you check and repair it by using the fsck command.

  • When you are about to do a complete backup of it.

To unmount a file system, use the umount command:

umount <mount-point>

<mount-point> is the name of the file system you want to unmount. This can be either the directory name in which the file system is mounted or the device name path of the file system. For example, to unmount the /home2 file system, type the following:

umount /home2

Alternatively, you can specify the device name path for the file system:

umount /dev/dsk/c0t0d0s0

Note

Shutting Down the System File systems are automatically unmounted as part of the system shutdown procedure.


The fuser Command

Before you can unmount a file system, you must be logged in as the administrator (root) and the file system must not be busy. A file system is considered busy if a user is in a directory in the file system or if a program has a file open in that file system. You can make a file system available for unmounting by changing to a directory in a different file system or by logging out of the system. If something is causing the file system to be busy, you can use the fuser command, described in Table 1.18, to list all the processes that are accessing the file system and to stop them if necessary.

Table 1.18. The fuser Command Options

Option

Description

-c

Reports on files that are mount points for file systems and on any files within that mounted file system.

-f

Prints a report for the named file but not for files within a mounted file system.

-k

Sends the SIGKILL signal to each process.

-u

Displays the user login name in parentheses following the process ID.


Note

Informing Users Always notify users before unmounting a file system.


The syntax for fuser is as follows:

/usr/sbin/fuser [options] <file>|<file system>

Replace <file> with the filename you are checking, or replace <file system> with the name of the file system you are checking.

The following example uses the fuser command to find out why /home2 is busy:

fuser -cu /home2

The system displays each process and user login name that is using this file system:

/home2:     8448c(root)    8396c(root)

The following command stops all processes that are using the /home2 file system by sending a SIGKILL to each one. Don't use it without first warning the users:

fuser -c -k /home2

Using the fuser command as described is the preferred method for determining who is using a file system before unmounting it. Added in Solaris 8 was another, less desirable method for unmounting a file system, using the umount command with the -f option, as follows:

umount -f /home2

The -f option forcibly unmounts a file system. Using this option can cause data loss for open files and programs that access files after the file system has been unmounted; it returns an error (EIO). The -f option should be used only as a last resort.

You can also use the fuser command to check on any device such as the system console. By typing:

fuser /dev/console

The system displays the processes associated with that device as follows:

/dev/console:      459o     221o

/etc/mnttab

When a file system is mounted, an entry is maintained in the mounted file system table called /etc/mnttab. The file /etc/mnttab is really a file system that provides read-only access to the table of mounted file systems for the current host. The mount command adds entries to this table, and umount removes entries from this table. The kernel maintains the list in order of mount time. For example, the first mounted file system is first in the list, and the most recently mounted file system is last. When mounted on a mount point, the file system appears as a regular file containing the current mnttab information. Each entry in this table is a line of fields separated by spaces in this form:

<special> <mount_point> <fstype> <options> <time>

Table 1.19 describes each field.

Table 1.19. /etc/mnttab Fields

Field

Description

<special>

The resource to be mounted (that is, /dev/dsk/c0t0d0s0)

<mount_point>

The pathname of the directory on which the file system is mounted

<fstype>

The file system type

<options>

The list of mount options used to mount the file system

<time>

The time at which the file system was mounted


Following is a sample /etc/mnttab file:

# more /etc/mnttab
/dev/dsk/c0t0d0s0       /       ufs     \
rw,intr,largefiles,logging,xattr,onerror=panic,dev=2200008     1127941982
/devices        /devices        devfs   dev=4380000     1127941959
ctfs    /system/contract        ctfs    dev=43c0001     1127941959
proc    /proc   proc    dev=4400000     1127941959
mnttab  /etc/mnttab     mntfs   dev=4440001     1127941959
swap    /etc/svc/volatile       tmpfs   xattr,dev=4480001       1127941959
objfs   /system/object  objfs   dev=44c0001     1127941959
/dev/dsk/c0t0d0s6      /usr    ufs     \
rw,intr,largefiles,logging,xattr,onerror=panic,dev=220000e     1127941982
fd      /dev/fd fd      rw,dev=4640001  1127941982
/dev/dsk/c0t0d0s1      /var    ufs     \
rw,intr,largefiles,logging,xattr,onerror=panic,dev=2200009     1127941983
swap    /tmp    tmpfs   xattr,dev=4480002       1127941983
swap    /var/run        tmpfs   xattr,dev=4480003       1127941983
/dev/dsk/c0t0d0s5      /opt    ufs     \
rw,intr,largefiles,logging,xattr,onerror=panic,dev=220000d     1127941991
/dev/dsk/c0t0d0s7      /export/home    ufs     \
rw,intr,largefiles,logging,xattr,onerror=panic,dev=220000f     1127941991
-hosts  /net    autofs  nosuid,indirect,ignore,nobrowse,dev=4700001     1127942006
auto_home      /home   autofs  indirect,ignore,nobrowse,dev=4700002    1127942006
smokey:vold(pid487)    /vol    nfs     ignore,noquota,dev=46c0001      1127942024
/vol/dev/dsk/c0t2d0/s10_software_companion     /cdrom/s10_software_companion   hsfs\
ro,nosuid,noglobal,maplcase,rr,traildot,dev=16c0001    1127942029
/dev/dsk/c2t1d0s1      /mnt    ufs     rw,intr,largefiles,logging,xattr,\
onerror=panic,dev=800089      1128021589

Before Solaris 8, the /etc/mnttab file was a text file. The downside of being a text file was that it could get out of sync with the actual state of mounted file systems, or it could be manually edited. Now this file is a mntfs file system that provides read-only information directly from the kernel about mounted file systems for the local hosts.

You can display the contents of the mount table by using the cat or more commands, but you cannot edit them.

You can also view a mounted file system by typing /sbin/mount from the command line as shown earlier in this section.

Creating an Entry in the /etc/vfstab File to Mount File Systems

Objective:

Explain the purpose and function of the vfstab file in mounting UFS file systems, and the function of the mnttab file system in tracking current mounts.

The /etc/vfstab (virtual file system table) file contains a list of file systems, with the exception of the /etc/mnttab and /var/run, to be automatically mounted when the system is booted to the multiuser state. The system administrator places entries in the file, specifying what file systems are to be mounted at bootup. The following is an example of the /etc/vfstab file:

# cat /etc/vfstab
#device       device          mount           FS      fsck    mount   mount
#to mount     to fsck         point           type    pass    at boot options
#
fd     -      /dev/fd fd      -       no      -
/proc  -      /proc   proc    -       no      -
/dev/dsk/c0t0d0s3     -       -       swap    -       no      -
/dev/dsk/c0t0d0s0     /dev/rdsk/c0t0d0s0      /       ufs     1       no      -
/dev/dsk/c0t0d0s6     /dev/rdsk/c0t0d0s6      /usr    ufs     1       no      -
/dev/dsk/c0t0d0s1     /dev/rdsk/c0t0d0s1      /var    ufs     1       no      -
/dev/dsk/c0t0d0s7     /dev/rdsk/c0t0d0s7      /export/home    ufs     2       yes    -
/dev/dsk/c0t0d0s5     /dev/rdsk/c0t0d0s5      /opt    ufs     2       yes     -
/devices        -     /devices       devfs    -       no      -
ctfs   -      /system/contract       ctfs     -       no      -
objfs  -      /system/object  objfs   -       no      -
swap   -      /tmp    tmpfs   -       yes     -

Exam Alert

You'll need to make entries in the vfstab file on the exam. Understand the syntax and know how to create a new line in this file for both a UFS file system and swap.


Each column of information follows this format:

  • device to mount The buffered device that corresponds to the file system being mounted.

  • device to fsck The raw (character) special device that corresponds to the file system being mounted. This determines the raw interface used by fsck. Use a dash (-) when there is no applicable device, such as for swap, /proc, tmp, or a network-based file system.

  • mount point The default mount point directory.

  • FS type The type of file system.

  • fsck pass The pass number used by fsck to decide whether to check a file. When the field contains a 0 or a non-numeric value, the file system is not checked. When the field contains a value of 1, the fsck utility gets started for that entry and runs to completion. When the field contains a value greater than 1, that device is added to the list of devices to have the fsck utility run. The fsck utility can run on up to eight devices in parallel. This field is ignored by the mountall command.

  • mount at boot Specifies whether the file system should be automatically mounted when the system is booted. These file systems get mounted when SMF starts up the svc:/system/file system service instances.

    Note

    vfstab Entries for root (/), /usr, and /var For root (/), /usr, and /var file systems (if they are separate file systems), the mount at boot field option is no. The kernel mounts these file systems as part of the boot sequence before the mountall command is run. The mount command explicitly mounts the file systems root (/), /usr, and /var when SMF starts up the svc:/system/file system service instances.


  • mount options A list of comma-separated options (with no spaces) used when mounting the file system. Use a dash (-) to use default mount options.

Type the mount command with the -p option to display a list of mounted file systems in /etc/vfstab format:

mount -p

The system responds with this:

/dev/dsk/c0t0d0s0 - / ufs - no rw,intr,largefiles,logging,xattr,onerror=panic
/devices - /devices devfs - no
ctfs - /system/contract ctfs - no
proc - /proc proc - no
mnttab - /etc/mnttab mntfs - no
swap - /etc/svc/volatile tmpfs - no xattr
objfs - /system/object objfs - no
/dev/dsk/c0t0d0s6 - /usr ufs - no rw,intr,largefiles,logging,xattr,onerror=panic
fd - /dev/fd fd - no rw
/dev/dsk/c0t0d0s1 - /var ufs - no rw,intr,largefiles,logging,xattr,onerror=panic
swap - /tmp tmpfs - no xattr
swap - /var/run tmpfs - no xattr
/dev/dsk/c0t0d0s4 - /data ufs - no rw,intr,largefiles,logging,xattr,onerror=panic
/dev/dsk/c0t0d0s5 - /opt ufs - no rw,intr,largefiles,logging,xattr,onerror=panic
/dev/dsk/c0t0d0s7 - /export/home ufs - no rw,intr,largefiles,logging,xattr,\
onerror=panic

The -p option is useful for obtaining the correct settings if you're making an entry in the /etc/vfstab file.


Previous Page
Next Page