Solaris Handbook for Sun Peripherals

Creating and Mounting File Systems

You need to create a file system for a partition when you have:

You must know the logical device name of the disk drive and partition for which you want to create a file system. Refer to Appendix A, SCSI Addressing" for more information on logical device names.


Note -

The disk for which you plan to create a file system must already be formatted and partitioned.


To Create a File System
  1. Become superuser.

  2. Use the newfs command to create a new file system on a partition:


    # newfs /dev/rdsk/cntndnsn
    


    Caution - Caution -

    Make sure that you have specified the correct logical device name before you create a new file system. If you specify the wrong logical device name you will render the data on that partition inaccessible. See "Logical Device Names" for details.


  3. Type y to confirm:


    newfs: construct a new file system /dev/rdsk/cx
    txdx
    sx (y/n)? y
    

    Newfs creates the necessary file system structures and a lost+found directory on the disk partition. Repeat these steps for each partition that will be used to contain a file system. Only one file system can be created per partition.

To Mount a File System

Once you have created a file system, you need to make it available to others by mounting it. A mounted file system is attached to the system directory tree at the specified mount point (a directory), and becomes available to the system and users. The root file system is always mounted. Any other file system can be connected (mounted) or disconnected (unmounted) from the root (/) file system.

To mount a file system, follow these steps:

  1. Edit the /etc/vfstab file with vi or any text editor.

    1. Add the entry by separating each field with a space or a tab. If a field has no value, enter a dash (-) as a field placeholder. There are seven fields and each field must have an entry.


      #device      device       mount        FS   fsck    mount
        mount
      #to mount    to fsck      point        type pass    at
      boot options
      #
      #/dev/dsk/c1d0s2 /dev/rdsk/c1d0s2 /usr  ufs  1      yes
          -
      fd      -       /dev/fd fd      -       no      -
      /proc   -       /proc   proc    -       no      -
      /dev/dsk/c0t0d0s1       -       -       swap    -    no
           -
      /dev/dsk/c0t0d0s0    /dev/rdsk/c0t0d0s0      /   ufs  
        1 no -
      swap    -       /tmp   tmpfs   -       yes     -
      /dev/dsk/c0t1d0s6  /dev/rdsk/c0t1d0s6   /abc   ufs   2    yes     -
      /dev/dsk/c0t1d0s7  /dev/rdsk/c0t1d0s7   /def   ufs   2    yes     -
      


      Caution - Caution -

      Be careful when editing this system configuration file. The field columns do not line up. It is very easy to make a mistake. The system reads this file at boot time and when mount and fsck commands are run. If an error resides in this file, these commands may fail, leaving the system in an undesirable state.


      In this example, the bottom two lines were added, one line for each new file system. Each field was entered based on the following field information:

      Table 2-1 fields/etc/vfstab

      Field  

      Field Heading 

      Description 

      device to mount

      Specify the logical device name for the file system that will be mounted, usually from the /dev/dsk directory.

      device to fsck

      Specify the logical device name of the device that fsck runs on, usually from the /dev/rdsk directory.

      mount point

      Specify the directory to use as the file system mount point. 

      FS type

      Specify the file system type, usually ufs for local file systems.

      fsck pass

      Specify a number that controls the way that fsck runs:

      1=run fsck one file system at a time, in the order listed.

      2=run fsck simultaneously on file systems.-=do not run fsck

      mount at boot

      Specify yes or no. yes=this file system should be mounted at boot time and with the mountall command. no= this file system should not be mounted at boot time nor with the mountall command.

      mount options

      Specify mount options separated by a comma but no whitespace, or place a dash (-) in this field for no options.

    2. Save the /etc/vfstab file with the modifications.


    Note -

    For more information about writing entries in the /etc/vfstab file, see man Pages(4): File Formats and the System Administration Guide.


  2. Create the directories that you want to use as mount points:


    # mkdir  /abc  /def
    

    The mount point directory must be created prior to mounting a file system. Two mount points (directories) are created for this example.

  3. Type:


    # mount /abc /def
    

    The mount command will read the /etc/vfstab entries for these file systems and mount them accordingly. Also, each time you boot the system the /etc/vfstab file is read and all appropriate file systems, including the new ones, will be mounted.


    Note -

    Be sure not to mount any partition that you intend to use as swap space or as an unmounted partition.


  4. Use the df command to see all file systems that are mounted:


    # df -k
    Filesystem            kbytes    used   avail capacity 
    Mounted on
    /dev/dsk/c0t0d0s0    1759982  779007  975109    45%    /
    /proc                      0       0       0     0%   
    /proc
    fd                         0       0       0     0%   
    /dev/fd
    swap                  217808     384  217424     1%   
    /tmp
    /dev/dsk/c0t1d0s6     118344	       4  118340	     0% 
      /abc
    /dev/dsk/c0t1d0s7      80059	       4   80055     0%  
     /def
    

  1. To unmount a file system use the umount command:


    # umount /abc
    

    You must be superuser to mount and unmount file systems.

    The operating system will not permit you to unmount the / or /usr file systems.

    If your current working directory is in the file system that you wish to unmount, you must change (cd) to another directory or the system will report device is busy.