System Administration Guide, Volume I
  Rechercher uniquement dans ce livre
Télécharger cet ouvrage au format PDF

Mounting and Unmounting File Systems

34

This chapter describes how to mount and unmount file systems individually through the /etc/vfstab file. This is a list of the step-by-step instructions in this chapter.
How to See Which File Systems Are Mountedpage 562
How to Add an Entry in the /etc/vfstab Filepage 562
How to Mount Multiple File Systems Listed in the /etc/vfstab Filepage 564
How to Mount a File System Listed in the /etc/vfstab Filepage 566
How to Mount a UFS File Systempage 566
How to Mount an NFS File Systempage 568
x86: How to Mount an S5FS File Systempage 569
x86: How to Mount a PCFS (DOS) File System From a Hard Diskpage 570
How to Stop All Processes for a File Systempage 572
How to Unmount a File Systempage 574
How to Unmount File Systems Listed in the /etc/vfstab Filepage 575

Mounting File Systems

After you create a file system, you need to make it available. You make file systems available by mounting them. A mounted file system is attached to the system directory tree at the specified mount point, and becomes 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.
You can mount a local file system in these ways:
  • By creating an entry in the /etc/vfstab (virtual file system table) file. The /etc/vfstab file contains a list of file systems that are automatically mounted when the system is booted to multiuser state.
  • From the command line by using the mount command.
When file systems are shared from a server, a client can mount them as NFS file systems in any of these three ways:
  • By adding an entry to the /etc/vfstab file so that the file system is automatically mounted when the system is booted to multiuser state.
  • By using AutoFS to automatically mount or unmount the file system when a user changes into (mount) or out of (umount) the directory. See the NFS Administration Guide for information about AutoFS.
  • By using the mount command from the command line.
CD-ROMs containing file systems are mounted when the CD-ROM is inserted. Diskettes containing file systems are mounted by running the volcheck(1) command.

Prerequisites

The prerequisites to mount file systems are:
  • You must be root.
  • 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.

Verifying a Mounted File System

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

Commands Used to Mount and Unmount File Systems

Table 34-1 lists the commands in the /usr/sbin directory that you use to mount and unmount file systems.
Table 34-1
CommandDescription
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 inconsistencies. If you receive an error message from the mount or mountall command, you may 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 in a directory in the file system, or if a program has a file open in that file system.

General Mount Options

Table 34-2 describes the general 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.
Table 34-2
OptionFile SystemDescription
rw | ro
Specifies read/write or read-only. If you do not specify this option, the default is read/write.
nosuid
Disallows setuid execution and prevents devices on the file system from being opened. The default is to allow setuid execution and allow devices to be opened.
remount
With rw, remounts a file system with read/write access.
fUFS, S5FSFakes an entry in /etc/mnttab, but doesn't really mount any file systems.
nUFS, S5FSMounts the file system without making an entry in /etc/mnttab.
bg | fgNFSIf the first attempt fails, retries in the background (bg) or in the foreground (fg). The default is fg.
soft | hardNFSSpecifies 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 | nointrNFSSpecifies whether keyboard interrupts are allowed to kill a process hung while waiting for a response on hard-mounted file systems. The default is intr (interrupts allowed).
retry=nNFSRetries the mount operation when it fails. n is the number of times to retry.

Field Descriptions of the /etc/vfstab File

An entry in the /etc/vfstab file has seven fields, which are described in Table 34-3.
Table 34-3 /etc/vfstab
Field NameDescription
device to mountThe device to mount can be:

· The block special device for local UFS file systems (for example, /dev/dsk/c0t0d0s0).

· The resource name for remote file systems (for example, myserver:/export/home for an NFS file system). For more information on remote file systems, see NFS Administration Guide.

· The name of the slice on which to swap (for example, /dev/dsk/c0t3d0s1). · The /proc directory and proc file system type.

device to fsckThe raw (character) special device that corresponds to the 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 pointThe default mount point directory (for example, /usr for /dev/dsk/c0t0d0s6).
FS typeThe type of file system identified by the device to mount field.
fsck passThe 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 value greater than zero, the file system is checked; non-UFS file systems with a zero value for fsck pass are checked. For UFS file systems only, when the field contains a zero, the file system is not checked. 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. When the field contains a value of 1, the file system is checked sequentially. Otherwise, the value of the pass number does not have any effect. In SunOS system software, the fsck pass field does not explicitly specify the order in which file systems are checked.
mount at bootyes 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.
mount optionsA list of comma-separated options (with no spaces) that are used in mounting the file system. Use a dash (-) to show no options. See mount(1M) for a list of the available 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 (-).

· How to See Which File Systems Are Mounted

To see which file systems are mounted:

  $ mount  

Example--Seeing Which File Systems Are Mounted


  mars$ mount  
  / on /dev/dsk/c0t3d0s0 read/write on Tue Dec 24 12:29:22 1993  
  /usr on /dev/dsk/c0t1d0s6 read/write on Tue Dec 24 12:29:22 1993  
  /proc on /proc read/write on Tue Dec 24 12:29:22 1993  
  /tmp on swap read/write on Tue Dec 24 12:29:24 1993  
  /export/home on /dev/dsk/c0t3d0s7 read/write on Tue Dec 24 12:29:22 1993  
  /usr/openwin on pluto:/export/openwin read/write/remote on Tue Dec 24 12:30:32 1993  
  /usr/man on pluto:/export/man read/write/remote on Tue Dec 24 12:30:35 1993  
  /cdrom/ptf_1_2a on /vol/dev/dsk/c1t5/ptf_1_2a read only on Tue Dec 24 12:30:39  
  mars$  

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

  1. Make sure you have met the prerequisites listed on page 558.

  2. Edit the /etc/vfstab file and add an entry. See Table 34-3 on page 561 for detailed information about the /etc/vfstab field entries. Make sure you:

  • Separate each field with white space (a space or a Tab).
  • Enter a dash (-) if a field has no contents.
  1. Save the changes.

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


       #device         device          mount           FS      fsck    mount     mount  
       #to mount       to fsck         point           type    pass    at boot   options  
       #  
  (1) /dev/dsk/c0t3d0s7 /dev/rdsk/c0t3d0s7 /files1    ufs     2       yes       -  
  (2) pluto:/export/man   -           /usr/man        nfs     -       yes       ro,soft  
  (3) /               -               /tmp/newroot    lofs    -       yes       -  

(1)

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

(2)This 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 for NFS file systems. 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.

(3)This 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. Loopback file systems must always be mounted after the file systems used to make up the loopback file system. Be sure that the loopback entry is the last entry in the /etc/vfstab file so that it follows the entries that it depends on.

· How to Mount Multiple File Systems Listed in the /etc/vfstab File

  1. Make sure you have met the prerequisites listed on page 558.

  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.
In this command,
-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 type fstype 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 Multiple File Systems Listed in the /etc/vfstab File

This example shows the messages displayed if file systems are already mounted when you use the mountall command.

  # mountall  
  mount: /tmp already mounted  
  nfs mount: mount: /usr/openwin: Device busy  
  nfs mount: mount: /usr/man: Device busy  

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

  # mountall -l  
  # mount  
  / on /dev/dsk/c0t3d0s0 read/write on Tue Dec 24 12:29:22 1993  
  /usr on /dev/dsk/c0t1d0s6 read/write on Tue Dec 24 12:29:22 1993  
  /proc on /proc read/write on Tue Dec 24 12:29:22 1993  
  /tmp on swap read/write on Mon Dec 30 12:37:33 1993  

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

  # mountall -r  
  # mount  
  / on /dev/dsk/c0t3d0s0 read/write on Tue Dec 24 12:29:22 1993  
  /usr on /dev/dsk/c0t1d0s6 read/write on Tue Dec 24 12:29:22 1993  
  /proc on /proc read/write on Tue Dec 24 12:29:22 1993  
  /tmp_mnt/home/neptune on neptune:/export/home/neptune read/write/remote on Mon Dec 30  
  12:27:41 1993  
  /usr/openwin on pluto:/export/openwin read/write/remote on Mon Dec 30 12:37:53 1993  
  /usr/man on pluto:/export/man read/write/remote on Mon Dec 30 12:37:55 1993  

This example mounts all the NFS file systems listed in the /etc/vfstab file:

  # mountall -F nfs  
  # mount  
  / on /dev/dsk/c0t3d0s0 read/write on Tue Dec 24 12:29:22 1993  
  /usr on /dev/dsk/c0t1d0s6 read/write on Tue Dec 24 12:29:22 1993  
  /proc on /proc read/write on Tue Dec 24 12:29:22 1993  
  /tmp_mnt/home/neptune on neptune:/export/home/neptune read/write/remote on Mon Dec 30  
  12:27:41 1993  
  /usr/openwin on pluto:/export/openwin read/write/remote on Mon Dec 30 12:49:09 1993  
  /usr/man on pluto:/export/man read/write/remote on Mon Dec 30 12:49:11 1993  

· How to Mount a File System Listed in the /etc/vfstab File

  1. Make sure you have met the prerequisites listed on page 558.

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


  # mount mount-point  

In this command,
mount-point.....Is 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 Listed in the /etc/vfstab File

This example mounts the /usr/openwin file system listed in the /etc/vfstab file.

  # mount /usr/openwin  

· How to Mount a UFS File System

  1. Make sure you have met the prerequisites listed on page 558.

  2. Mount the UFS file system.


  # mount [-o mount-options] /dev/dsk/device-name mount-point  

In this command,
-o mount-options..Specifies mount options that you can use to mount a UFS file system. See Table 34-2 for the list of general mount options or mount_ufs(1M) for a complete list of options.
/dev/dsk/device-name Is the special block device file for the disk slice
holding the file system (for example, /dev/dsk/c0t3d0s7). See Chapter 1, "Planning File Systems," for information about how to find out disk device names.
mount-point.....Is the directory where the file system is mounted.

Example--Mounting a UFS File System

In this example, /dev/dsk/c0t3d0s7 is mounted on the /files1 directory.

  # mount /dev/dsk/c0t3d0s7 /files1  

· How to Mount an NFS File System

  1. Make sure you have met the prerequisites listed on page 558.

  2. Make sure the file system is available from a server.

    To mount an NFS file system, it must be made available from the server system. The share(1M) command creates a list of file systems in the file /etc/dfs/sharetab than can be shared across the network. See [ cross-reference to be supplied ] for information on how to export file systems.

  3. Mount the NFS file system.


  # mount -F nfs [-o mount-options] server:/directory mount-point  

In this command,
-o mount-optionsSpecifies mount options that you can use to mount a NFS file system. See Table 34-2 for the list of general mount options or mount_nfs(1M) for a complete list of options.
server:/directoryIs the server's host name on which the file system is mounted, and the name of the file system to mount.
mount-pointIs the directory where the file system is mounted.

Example--Mounting an NFS File System

In this example, packages from the server pluto in the directory /export/packages are mounted on /mnt.

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

· x86: How to Mount an S5FS File System

  1. Make sure you have met the prerequisites listed on page 558.

  2. Mount the S5FS file system.


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

In this command,
-o mount-options..Specifies mount options that you can use to mount a S5FS file system. See Table 34-2 for the list of common mount options or mount_s5fs(1M) for a complete list of options.
/dev/dsk/device-name Is the device name of the disk slice holding the file
system (for example, /dev/dsk/c0t3d0s7). See Chapter 1, "Planning File Systems," for information about how to find out disk device names.
mount-point.....Is the directory where the file system is mounted.

Example--Mounting an S5FS File System

In this example, /dev/dsk/c0t3d0s7 is mounted on the /files1 directory.

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

· x86: 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. Make sure you have met the prerequisites listed on page 558.

  2. Mount the PCFS file system.


  # mount -F pcfs [-o rw | ro] /dev/dsk/device-name:logical-drive mount-  
  point  

In this command,
-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 Is the device name of the whole disk (for example,
/dev/dsk/c0t0d0p0).

logical-driveSpecifies 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-pointIs the directory where the file system is mounted.
Note that the device-name and logical-drive must be separated by a colon.

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

In this example, the logical drive in the Primary DOS slice is mounted on the /pcfs/c directory.

  # mount -F pcfs /dev/dsk/c0t0d0p0:c /pcfs/c  

In this example, the first logical drive in the Extended DOS slice on the disk is mounted read-only on /pcfs/d.

  # mount -F pcfs -o ro /dev/dsk/c0t0d0p0:2 /pcfs/d  

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:
  • It is no longer needed or has been replaced by a file system that contains more current software.
  • You check and repair it using the fsck command. See Chapter 39, "Checking File System Integrity," for more information about the fsck command.
It is a good idea to unmount a file system before doing a complete backup of it. See Chapter 42, "Backing Up Files and File Systems," for more information about doing backups.

Note - File systems are automatically unmounted as part of the system shutdown procedure.

Prerequisites

The prerequisites to unmount file systems are:
  • You must be root.
  • A file system must be available for unmounting. You cannot umount a file system that is 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.

    · Logging out of the system.

Notify users if you need to unmount a file system they are using.

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 See Which File Systems Are Mounted" on page 562.

· How to Stop All Processes for a File System

  1. Become root.

  2. List all the processes that are using the file system, so you know which processes you are going to stop.


  # fuser -c [-u] mount-point  

In this command,
-cReports on files that are mount points for file systems, and any files within those mounted file systems.
-uDisplays the user login name for each process ID.
mount-pointIs the name of the file system for which you want to stop processes.
  1. Stop all processes for 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.

Verification--Stopping All Processes for a File System

Verify that there are no processes using the file system.

  # fuser -c mount-point  

Example--Stopping All Processes for a File System

In this example, process 4006c that is using the /export/home file system is stopped.

  # 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 / or /usr):

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

  1. Make sure you have met the prerequisites listed on page 571.

  2. Unmount the file system.


  # umount mount-point  

In this command,
mount-point.....Is 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

In this example, a local home file system is unmounted.

  # umount /export/home  

In this example, the file system on slice 7 is unmounted.

  # umount /dev/dsk/c0t0d0s7  

· How to Unmount File Systems Listed in the /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 page 571.

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


  # umountall  

All systems that can be unmounted are unmounted. File systems that are busy are not unmounted.
  1. For the file systems that were busy and not unmounted, make them available to be unmounted as described in "How to Stop All Processes for a File System" on page 572.

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