Mount in  Unix

  Disk and Filesystems Management in  Unix Mount Options Performing Mounts Mounting CD-ROM
 df du      

The file system is best visualized as a tree, rooted, as it were, at /. /dev, /usr, and the other directories in the root directory are branches, which may have their own branches, such as /usr/local, and so on.

There are various reasons to house some of these directories on separate file systems. /var contains the directories log/, spool/, and various types of temporary files, and as such, may get filled up. Filling up the root file system is not a good idea, so splitting /var from / is often favorable.

Another common reason to contain certain directory trees on other file systems is if they are to be housed on separate physical disks, or are separate virtual disks, such as Network File System mounts, or CDROM drives.

During the boot process, file systems listed in /etc/fstab are automatically mounted (unless they are listed with the noauto option).

The /etc/fstab file contains a list of lines of the following format:

device       /mount-point fstype     options      dumpfreq     passno
device
A device name (which should exist), as explained in Section 16.2.
mount-point
A directory (which should exist), on which to mount the file system.
fstype
The file system type to pass to mount(8). The default FreeBSD file system is ufs.
options
Either rw for read-write file systems, or ro for read-only file systems, followed by any other options that may be needed. A common option is noauto for file systems not normally mounted during the boot sequence. Other options are listed in the mount(8) manual page.
dumpfreq
This is used by dump(8) to determine which file systems require dumping. If the field is missing, a value of zero is assumed.
passno
This determines the order in which file systems should be checked. File systems that should be skipped should have their passno set to zero. The root file system (which needs to be checked before everything else) should have its passno set to one, and other file systems' passno should be set to values greater than one. If more than one file systems have the same passno then fsck(8) will attempt to check file systems in parallel if possible.

Consult the fstab(5) manual page for more information on the format of the /etc/fstab file and the options it contains.

The mount(8) command is what is ultimately used to mount file systems.

In its most basic form, you use:

# mount device mountpoint

There are plenty of options, as mentioned in the mount(8) manual page, but the most common are:

Mount Options
-a
Mount all the file systems listed in /etc/fstab. Except those marked as ``noauto'', excluded by the -t flag, or those that are already mounted.
-d
Do everything except for the actual mount system call. This option is useful in conjunction with the -v flag to determine what mount(8) is actually trying to do.
-f
Force the mount of an unclean file system (dangerous), or forces the revocation of write access when downgrading a file system's mount status from read-write to read-only.
-r
Mount the file system read-only. This is identical to using the ro (rdonly for FreeBSD versions older than 5.2) argument to the -o option.
-t fstype
Mount the given file system as the given file system type, or mount only file systems of the given type, if given the -a option.

``ufs'' is the default file system type.

-u
Update mount options on the file system.
-v
Be verbose.
-w
Mount the file system read-write.

The -o option takes a comma-separated list of the options, including the following:

nodev
Do not interpret special devices on the file system. This is a useful security option.
noexec
Do not allow execution of binaries on this file system. This is also a useful security option.
nosuid
Do not interpret setuid or setgid flags on the file system. This is also a useful security option.
The umount(8) command takes, as a parameter, one of a mountpoint, a device name, or the -a or -A option. All forms take -f to force unmounting, and -v for verbosity. Be warned that -f is not generally a good idea. Forcibly unmounting file systems might crash the computer or damage data on the file system.

-a and -A are used to unmount all mounted file systems, possibly modified by the file system types listed after -t. -A, however, does not attempt to unmount the root file system.

Mounting is a process that attach individual file systems to their mount points on the directory hierarchy. This action makes a file system accessible to the system and to the users.

You use the unmounting process to detach a file system from its mount point in the directory hierarchy. This action makes a file system unavailable to the system or users.

After you have created a file system by using the newfs command, you must attach it to the  Unix directory hierarchy at a mount point. A mount point is a directory that is the point of connection for a file system.  File systems are commonly referred to by the names of their mount points, for example, the / (root) file system or the /usrfile system.

To determine which file systems are currently mounted use

Note – While system administrators typically use the /usr/sbin/mount command, the system boot scripts use the /sbin/mount command.

Mounting a File System Automatically

The  Unix provides several methods for automating file system mounts.

 Unix /etc/vfstab Virtual File System Table

The /etc/vfstab file lists all the file systems to be automatically mounted at system boot time, with the exception of the /etc/mnttab and /var/runfile systems.

The file format includes seven fields per line entry. By default, a tab separates each field, but any whitespace can be used for separators. The dash ( - ) character is used as a placeholder for fields when text arguments are not appropriate. Commented lines begin with the hash ( # ) symbol.

To add a line entry, you need the following information:

Note : For / (root), /usr , and /var (if it is a separate file system) file systems, the mount at boot field value is specified as 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) and /usr as specified in the /etc/rcS.d/S30rootusr.sh script and the /var file system as specified in the /etc/rcS.d/S70buildmnttab script.

Note – Because the default is to use tabs to separate the fields in the /etc/vfstab file, the fields often do not line up under their respective headings. This can lead to some confusion when you are viewing this file in a terminal window.

An example of a /etc/vfstab file follows:

# more /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/c0t0d0s1 - - swap - no -

/dev/dsk/c0t0d0s0 /dev/rdsk/c0t0d0s0 / ufs 1 no -

/dev/dsk/c0t0d0s7 /dev/rdsk/c0t0d0s7 /export/home ufs 2 yes -

swap - /tmp tmpfs - yes -

/etc/mnttab file system that provides read-only information directly from the kernel

The /etc/mnttab file is really an mntfs file system that provides read-only information directly from the kernel about mounted file systems on the local host.

Each time a file system is mounted, the mount command adds an entry to this file. Whenever a file system is unmounted, its entry is removed from the /etc/mnttab file.

The following examples show two ways to display currently mounted file systems.

# more /etc/mnttab

/dev/dsk/c0t0d0s0 / ufs

rw,intr,largefiles,xattr,onerror=panic,suid,dev=2200000 10164665 25

/proc /proc proc dev=4300000 1016466524

mnttab /etc/mnttab mntfs dev=43c0000 1016466524

fd /dev/fd fd rw,suid,dev=4400000 1016466527

swap /var/run tmpfs xattr,dev=1 1016466529

swap /tmp tmpfs xattr,dev=2 1016466532

/dev/dsk/c0t0d0s7 /export/home ufs

rw,intr,largefiles,xattr,onerror=panic,suid,dev=2200007 1016466532

-hosts /net autofs indirect,nosuid,ignore,nobrowse,dev=4580001 1016466537

auto_home /home autofs indirect,ignore,nobrowse,dev=4580002 1016466537

-xfn /xfn autofs indirect,ignore,dev=4580003 1016466537 sys41:vold(pid248) /vol nfs ignore,dev=4540001 1016466554

# mount

/ on /dev/dsk/c0t0d0s0

read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Mon Mar 18

08:48:45 2002

/proc on /proc read/write/setuid/dev=4300000 on Mon Mar 18 08:48:44 2002

/etc/mnttab on mnttab read/write/setuid/dev=43c0000 on Mon Mar 18 08:48:44 2002

/dev/fd on fd read/write/setuid/dev=4400000 on Mon Mar 18 08:48:47 2002

/var/run on swap read/write/setuid/xattr/dev=1 on Mon Mar 18 08:48:49 2002

/tmp on swap read/write/setuid/xattr/dev=2 on Mon Mar 18 08:48:52 2002

/export/home on /dev/dsk/c0t0d0s7

read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Mon Mar 18

08:48:52 2002

Mounts

You can mount file systems manually by logging in as the root user and running the mount command, or the system can automatically mount file systems at boot time after consulting the /etc/vfstab file.

Mounting a Local File System Manually

The mount command not only lists which file systems are currently mounted, it also provides you, as the root user, with a method for mounting file systems.

To mount a local file system manually, you need to know the name of the device where the file system resides and its mount point directory name. Perform the command:

# mount /dev/dsk/c0t0d0s7 /export/home

In this example, the default action mounts the file system with the following options: read/write , setuid , intr , nologging , and largefiles , xattr , and onerror .

The following list explains the default options for the mount command.

Note – Due to file system overhead, the largest file size that can be created is approximately 866 Gbytes.

The /etc/vfstab file provides you with another important feature. Because the /etc/vfstab file contains the mapping between the mount point and the actual device name, the root user can manually mount a file system specifying only the mount point on the command line.

# mount /export/home  # means take options from /etc/vfstab

Using the mount Command Options

mount command is unique amont Unix utilities in that it requres options to be preseded by the -o flag. When you are using multiple options, enter them as a comma-separated list following the -o flag. Some options used to mount local file systems include: ro , nosetuid ,

mount -o option,option,... device_name mount_point

Note – Mount options are discussed in detail in the man page for the mount_ufs command.

# mount -o ro /dev/dsk/c0t0d0s6 /usr

# mount -o ro,nosuid /dev/dsk/c0t0d0s7 /export/home

# mount -o noatime /dev/dsk/c0t0d0s7 /export/home

# mount -o nolargefiles /dev/dsk/c0t0d0s7 /export/home

Use of the nolargefiles option fails if the file system to be mounted contains a large file or did contain a large file at one time. If the file system currently contains a large file and the root user needs to mount it with this option, then the large file must be located and moved or removed from the file system. Then you must execute the fsck command manually to update the superblock information. The mount also fails if the file system at one time contained a large file, even though it was moved or removed. You must execute the fsck command to clear the old information and allow the file system to be mounted.

# mount -o logging /dev/dsk/c0t0d0s7 /export/home

UFS logging is a process of storing file system transactions or changes that make up a complete file or directory operation into a log before they are applied to the file system. After a transaction is stored, the complete transaction can be applied to the file system later. The UFS log is allocated from free blocks in the file system. It is sized approximately 1 Mbyte per 1 Gbyte, up to a maximum of 64 Mbytes.

As a UFS log reaches its maximum size, it begins to write transactions to the file system. When the file system is unmounted, the entire UFS log is emptied, and all transactions are written to the file system. UFS logging offers two advantages. First, it prevents file systems from becoming inconsistent, therefore eliminating the need to run lengthy fsck scans. Secondly, you can bypass fsck scanning, which reduces the time required to reboot a system if it was stopped by a method other than an orderly shutdown.

Mounting All File Systems Manually

The /etc/vfstab file is read by the /usr/sbin/mountall command during the system boot sequence and mounts all file systems that have a yes in the mount at boot field. The root user can use the mountall command to mount manually every file system in the /etc/vfstab file that has a yes in the mount at boot field, for example:

    # mountall

To mount only the local file systems listed in the /etc/vfstab file, execute:

# mountall -l

During the boot sequence, the fsck utility checks each local file system in the /etc/vfstab file that has a device to fsck entry and an fsck pass number greater than 0. The utility determines if the file system is in a usable state to be safely mounted.

If the fsck utility determines that the file system is in an unusable state (for example, corrupted), the fsck utility repairs it before the mount is attempted. The system attempts to mount any local file systems that have a - (dash) or 0 (zero) entry in the fsck pass field without checking the file system itself.

Mounting a New File System

To add a new disk to the system, prepare the disk to hold a file system, and mount the file system, perform these general steps:

  1. Set up the disk hardware, which might include setting address switches and connecting cables.

  2. Perform a reconfiguration boot or run the devfsadm utility to add support for the new disk.

  3. Use the format utility to partition the disk into one or more slices.

  4. Create a new file system on one slice by using the newfs command.

  5. Create a mount point for the file system by using the mkdir command to create a new directory in the / (root) file system.
        #
    mkdir /database

  6. Mount the new file system manually by using the mount command.

# mount /dev/dsk/c1t4d0s0 /database

7. Use the mount command to determine if the file system is mounted.

# mount

/ on /dev/dsk/c0t0d0s0

read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Mon

Mar 18 08:48:45 2002

/proc on /proc read/write/setuid/dev=4300000 on Mon Mar 18 08:48:44 2002

/etc/mnttab on mnttab read/write/setuid/dev=43c0000 on Mon Mar 18

08:48:44 2002

/dev/fd on fd read/write/setuid/dev=4400000 on Mon Mar 18 08:48:47 2002

/var/run on swap read/write/setuid/xattr/dev=1 on Mon Mar 18 08:48:49

2002

/tmp on swap read/write/setuid/xattr/dev=2 on Mon Mar 18 08:48:52 2002

/export/home on /dev/dsk/c0t0d0s7

read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Mon

Mar 18 08:48:52 2002

/database on /dev/dsk/c1t4d0s0

read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=800020 on Mon

Mar 18 09:15:26 2002

8. Edit the /etc/vfstab file to add a line entry for the new file system.

# vi /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/c0t0d0s1 - - swap - no -

/dev/dsk/c0t0d0s0 /dev/rdsk/c0t0d0s0 / ufs 1 no -

/dev/dsk/c0t0d0s7 /dev/rdsk/c0t0d0s7 /export/home ufs 2 yes -

swap - /tmp tmpfs - yes -

/dev/dsk/c1t4d0s0 /dev/rdsk/c1t4d0s0 /database ufs 1 yes logging

#

The file system automatically mounts whenever the system boots .

Mounting Different Types of File Systems

Different file system types have unique properties that affect how the mount command functions.

By default, the mount command assumes it is mounting a ufs -type file system. However, when you are mounting a different type of file system, you might have to specify its type on the command line. You use the -F option with the mount command to specify the type of file system mounted. The file system type must be determinable from the

/etc/vfstab , /etc/default/fs , or /etc/dfs/fstypes files.

Determining a File System’s Type

Because the mount commands need the file system type to function properly, the file system type must be explicitly specified or determined by searching the following files:

If the file system’s type has not been explicitly specified on the command line using the mount -F FStype option, the mount command examines the /etc/vfstab file to determine the file system’s type. The mount command makes this determination by using the file system’s block device name, raw device name, or mount point directory name.

If the mount command cannot determine the file system’s type by searching the /etc/vfstab file, the mount command uses the default file system type specified in either the /etc/default/fs file or the /etc/dfs/fstypes file, depending on whether the file system is local or remote.

The default local file system type is specified in the /etc/default/fs file by the line entry LOCAL=fstype .

LOCAL=ufs

The first line entry in the /etc/dfs/fstypes file determines the default remote file system type.

nfs NFS Utilities

autofs AUTOFS Utilities

cachefs CACHEFS Utilities

Using the fstypCommand

You can also use the fstyp command with the raw device name of the

disk slice to determine a file system’s type.

# fstyp /dev/rdsk/c0t0d0s7

ufs

Specifying an hsfs File System Type

To mount a file system that resides on a CD-ROM when the Volume Management services are stopped, as the root user perform the command:

# mount -F hsfs -o ro /dev/dsk/c0t6d0s0 /cdrom

In this example, the file system type is hsfs , the file system resides on disk slice /dev/dsk/c0t6d0s0 , and the mount point /cdrom is a pre-existing directory in the  Unix.

Specifying a pcfs File System Type

To mount a file system that resides on a diskette when the Volume Management services are stopped, as the root user, perform the commands:

# mkdir /pcfs

# mount -F pcfs /dev/diskette /pcfs

In this example, the file system type is pcfs . This file system resides on the device /dev/diskette , and the mount point is /pcfs .

Performing Unmounts

A file system is commonly unmounted if it needs to be checked and repaired by the fsck command, or if it needs to be backed up completely.

Unmounting a File System

Some file system administration tasks cannot be performed on mounted file systems. To unmount a file system to prepare it for system maintenance, use the umount command.

Unmounting a file system by using the umount command removes it from the file system mount point and deletes its entry from the /etc/mnttab file.

Note – Notify users before unmounting a file system that they are currently accessing.

To unmount a file system manually by using the directory mount point, perform the command:

# umount /export/home

To unmount a file system manually by using the logical disk device name, perform the command:

# umount /dev/dsk/c0t0d0s7

Unmounting All File Systems

The /etc/mnttab file is read by the /usr/sbin/umountall command during the system shutdown sequence or when umountall is invoked from the command line. The umountall unmounts all file systems

specified in the vfstab file except / (root), /usr , /proc , /dev/fd , /var ,  /var/run , and /tmp .

Run the umountall command as the root user when you want to unmount manually all the file systems listed in the /etc/mnttab file, for example:

# umountall

To unmount only the local file systems listed in the /etc/mnttab file, perform the command:

# umountall -l

To verify that a file system or a number of file systems have been unmounted, invoke the mount command and check the output.

Unmounting a Busy File System

Any file system that is busy is not available for unmounting. Both the umount and umountall commands display the error message: umount: file_system_name busy

A file system is considered to be busy if one of the following conditions exists:

There are two methods to make a file system available for unmounting if it is busy:

Note – The fuser command displays the process IDs of all processes currently using the specified file system. Each process ID is followed by a letter code. These letter codes are described in the man page for this command.

Using the fuserCommand

To stop all processes that are currently accessing a file system, follow these steps:

1. As the root user, list all of the processes that are accessing the file system. Use the following command to identify which processes need to be terminated.

# fuser -cu mount_point

This command displays the name of the file system and the user login name for each process currently active in the file system.

2. Kill all processes accessing the file system.

# fuser -ck mount_point

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

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

# fuser -c mount_point

4. Unmount the file system.

# umount mount_point

Using the umount -fCommand

As the root user, you can unmount a file system, even if it is busy, by using the -f (force) option with the umount command. The following is the format for this command:

# umount -f mount_point

The file system is unmounted even if it contains open files. A forced unmount can result in loss of data and in zombie processes that are left running on the system. However, it is particularly useful for unmounting a shared file system if the remote file server is nonfunctional.

Repairing Important Files if Boot Fails

The following procedure describes how to boot from the  Unix Software CD-ROM to edit a misconfigured /etc/vfstab file.

1. Insert the  Unix 9 OE Software 1 of 2 CD-ROM into the CD-ROM drive.

2. Execute a single-user boot from the CD-ROM.

ok boot cdrom -s

Boot device: /pci@1f,0/pci@1,1/ide@3/cdrom@2,0:f File and args -s

SunOS Release 5.9 Generic 64 bit

Copyright 1983-2002 by Sun Microsystems, Inc. All rights reserved.

Configuring /dev and /devices

Use is subject to license terms

Using RPC Bootparams for network configuration information.

Skipping interface hme0

-

INIT: SINGLE USER MODE

#

Note – Performing a single-user boot operation from this software CD-ROM creates an in-memory copy of the /var file system, which supports your ability to perform administrative tasks.

3. Use the fsck command on the / (root) partition to check and repair any potential problems in the file system.

# fsck /dev/rdsk/c0t0d0s0

4. If the fsck command is successful, mount the / (root) file system on the /a directory to gain access to the file system on disk.

# mount /dev/dsk/c0t0d0s0 /a

5. Set and export the TERM variable, which enables the vi editor to work properly.

# TERM=sun

# export TERM

6. Edit the /etc/vfstab file, and correct any problems. Then exit the file.

# vi /a/etc/vfstab

:wq!

# cd /

# umount /a

8. Reboot the system.

# init 6

Accessing Mounted Diskettes and CD-ROMs

To provide access to file systems on diskettes and CD-ROMs, the  Unix provides users a standard interface referred to as Volume Management.

Note – The  Unix 9 OE includes support for additional removable media such as DVDs, Jaz drives, Zip drives, and PCMCIA memory cards. (PCMCIA stands for Personal Computer Memory Card International Association.) For more information on using these devices, see the resources available on the  Unix 9 Documentation CD.

Volume Management provides two major benefits:

l It automatically mounts removable media for both the root user and non-root users.

l It can give other systems on the network automatic access to any removable media currently inserted in the local system.

The Volume Management service is controlled by the /usr/sbin/vold daemon. By default, this service is always running on the system so that it can automatically manage diskettes and CD-ROMs for regular users.

Volume Management features automatic detection of CD-ROMs. However, it does not detect the presence of a diskette that has been inserted in the drive until the volcheck command is run. This command instructs the vold daemon to check the diskette drive for any inserted media. Volume Management can mount ufs , pcfs , hsfs , and udfs file systems.

Using Volume Management

To make working with diskettes and CD-ROMs simple for your users, each device is easy to mount and mounts at an easy-to-remember location.

If the vold daemon detects that the mounted device contains a file system, then the device is mounted at the directory location.

If the vold daemon detects that the mounted device does not contain a file system, the device is accessible through a path.

Media Device Access File Systems On

Media Device Access Raw Device On

When Volume Management is running on the system, a regular user can easily access a diskette or CD-ROM by following these basic steps:

File Description

/etc/vold.conf The Volume Management configuration file. This file defines  items, such as what action should be taken when media is inserted or ejected, which devices are managed by Volume Management, and which file system types are unsafe to eject. /etc/rmmount.conf The rmmount command configuration file. The rmmount command is a removable media mounter that is executed by the Volume Management daemon whenever a CD-ROM or diskette is inserted.

Restricting Access to Mounted Diskettes and CD-ROMs

To restrict regular users from accessing diskettes or CD-ROMs on the system, you can, as the root user, terminate the Volume Management service.

Stopping Volume Management

To stop Volume Management from running on a system temporarily, as the root user perform the command:

# /etc/init.d/volmgt stop

To restart the Volume Management service, as the root user perform the command:

# /etc/init.d/volmgt start

Troubleshooting Volume Management Problems

If a CD-ROM fails to eject from the drive, as the root user attempt to stop Volume Management. If this is unsuccessful, kill the vold daemon.

# /etc/init.d/volmgt stop

or as a last resort:

# pkill -9 vold

Push the button on the system to eject the CD-ROM. The CD-ROM tray ejects. Remove the CD-ROM, and leave the tray out. Then restart the Volume Management service.

# /etc/init.d/volmgt start

Wait a few seconds, and then push the CD-ROM tray back into the drive.

Accessing a Diskette or CD-ROM Without Volume Management

When Volume Management is not running, only the root user can mount

and access a diskette or CD-ROM. Follow these steps:

  1. Insert the media device.

  2. Become the root user.

  3. Create a mount point, if necessary.

  4. Determine the file system type.

  5. Mount the device by using the mount options listed in the following Sections.

  6. Work with files on the media device.

  7. Unmount the media device.

  8. Eject the media device.

  9. Exit the root session.

Using the mount Command

To mount a file system that resides on a CD-ROM when the Volume  Management services are stopped, as the root user, perform the command:

# mount -F hsfs -o ro /dev/dsk/c0t6d0s0 /cdrom

In this example, the file system type is hsfs , the file system resides on disk slice /dev/dsk/c0t6d0s0 , and the mount point /cdrom is a pre-existing directory in the  Unix.

To mount a file system that resides on a diskette when the Volume Management services are stopped, as the root user, perform the command:

# mkdir /pcfs

# mount -F pcfs /dev/diskette /pcfs

In this example, the file system type is pcfs. This file system resides on the /dev/diskette device, and the mount point used is /pcfs .

 


Last modified: July 07, 2013