Solaris ZFS Administration Guide

Chapter 2 Getting Started With ZFS

This chapter provides step-by-step instructions on setting up simple ZFS configurations. By the end of this chapter, you should have a basic idea of how the ZFS commands work, and should be able to create simple pools and file systems. This chapter is not designed to be a comprehensive overview and refers to later chapters for more detailed information.

The following sections are provided in this chapter:

ZFS Hardware and Software Requirements and Recommendations

Make sure you review the following hardware and software requirements and recommendations before attempting to use the ZFS software:

Creating a Basic ZFS File System

ZFS administration has been designed with simplicity in mind. Among the goals of the ZFS design is to reduce the number of commands needed to create a usable file system. When you create a new pool, a new ZFS file system is created and mounted automatically.

The following example illustrates how to create a simple mirrored storage pool named tank and a ZFS file system named tank in one command. Assume that the whole disks /dev/dsk/c1t0d0 and /dev/dsk/c2t0d0 are available for use.


# zpool create tank mirror c1t0d0 c2t0d0

For more information about redundant ZFS pool configurations, see Replication Features of a ZFS Storage Pool.

The new ZFS file system, tank, can use as much of the disk space as needed, and is automatically mounted at /tank.


# mkfile 100m /tank/foo
# df -h /tank
Filesystem             size   used  avail capacity  Mounted on
tank                   80G   100M    80G     1%    /tank

Within a pool, you will probably want to create additional file systems. File systems provide points of administration that allow you to manage different sets of data within the same pool.

The following example illustrates how to create a file system named fs in the storage pool tank.


# zfs create tank/fs

The new ZFS file system, tank/fs, can use as much of the disk space as needed, and is automatically mounted at /tank/fs.


# mkfile 100m /tank/fs/foo
# df -h /tank/fs
Filesystem             size   used  avail capacity  Mounted on
tank/fs                 80G   100M    80G     1%    /tank/fs

In most cases, you will probably want to create and organize a hierarchy of file systems that matches your organizational needs. For more information about creating a hierarchy of ZFS file systems, see Creating a ZFS File System Hierarchy.

Creating a ZFS Storage Pool

The previous example illustrates the simplicity of ZFS. The remainder of this chapter demonstrates a more complete example similar to what you would encounter in your environment. The first tasks are to identify your storage requirements and create a storage pool. The pool describes the physical characteristics of the storage and must be created before any file systems are created.

ProcedureHow to Identify Storage Requirements for Your ZFS Storage Pool

  1. Determine available devices.

    Before creating a storage pool, you must determine which devices will store your data. These devices must be disks of at least 128 Mbytes in size, and they must not be in use by other parts of the operating system. The devices can be individual slices on a preformatted disk, or they can be entire disks that ZFS formats as a single large slice.

    For the storage example used in How to Create a ZFS Storage Pool, assume that the whole disks /dev/dsk/c1t0d0 and /dev/dsk/c2t0d0 are available for use.

    For more information about disks and how they are used and labeled, see Using Disks in a ZFS Storage Pool.

  2. Choose data replication.

    ZFS supports multiple types of data replication, which determines what types of hardware failures the pool can withstand. ZFS supports non-redundant (striped) configurations, as well as mirroring and RAID-Z (a variation on RAID-5).

    For the storage example used in How to Create a ZFS Storage Pool, basic mirroring of two available disks is used.

    For more information about ZFS replication features, see Replication Features of a ZFS Storage Pool.

ProcedureHow to Create a ZFS Storage Pool

  1. Become root or assume an equivalent role with the appropriate ZFS rights profile.

    For more information about the ZFS rights profiles, see ZFS Rights Profiles.

  2. Pick a pool name.

    The pool name is used to identify the storage pool when you are using the zpool or zfs commands. Most systems require only a single pool, so you can pick any name that you prefer, provided it satisfies the naming requirements outlined in ZFS Component Naming Requirements.

  3. Create the pool.

    For example, create a mirrored pool that is named tank.


    # zpool create tank mirror c1t0d0 c2t0d0
    

    If one or more devices contains another file system or is otherwise in use, the command cannot create the pool.

    For more information about creating storage pools, see Creating a ZFS Storage Pool.

    For more information about how device usage is determined, see Detecting In-Use Devices.

  4. View the results.

    You can determine if your pool was successfully created by using the zpool list command.


    # zpool list
    NAME                    SIZE    USED   AVAIL    CAP  HEALTH     ALTROOT
    tank                     80G    137K     80G     0%  ONLINE     -

    For more information about viewing pool status, see Querying ZFS Storage Pool Status.

Creating a ZFS File System Hierarchy

After creating a storage pool to store your data, you can create your file system hierarchy. Hierarchies are simple yet powerful mechanisms for organizing information. They are also very familiar to anyone who has used a file system.

ZFS allows file systems to be organized into arbitrary hierarchies, where each file system has only a single parent. The root of the hierarchy is always the pool name. ZFS leverages this hierarchy by supporting property inheritance so that common properties can be set quickly and easily on entire trees of file systems.

ProcedureHow to Determine Your ZFS File System Hierarchy

  1. Pick the file system granularity.

    ZFS file systems are the central point of administration. They are lightweight and can be created easily. A good model to use is a file system per user or project, as this model allows properties, snapshots, and backups to be controlled on a per-user or per-project basis.

    Two ZFS file systems, bonwick and billm, are created in How to Create ZFS File Systems.

    For more information on managing file systems, see Chapter 6, Managing ZFS File Systems.

  2. Group similar file systems.

    ZFS allows file systems to be organized into hierarchies so that similar file systems can be grouped. This model provides a central point of administration for controlling properties and administering file systems. Similar file systems should be created under a common name.

    For the example in How to Create ZFS File Systems, the two file systems are placed under a file system named home.

  3. Choose the file system properties.

    Most file system characteristics are controlled by using simple properties. These properties control a variety of behavior, including where the file systems are mounted, how they are shared, if they use compression, and if any quotas are in effect.

    For the example in How to Create ZFS File Systems, all home directories are mounted at /export/zfs/user, are shared by using NFS, and with compression enabled. In addition, a quota of 10 Gbytes on bonwick is enforced.

    For more information about properties, see Introducing ZFS Properties.

ProcedureHow to Create ZFS File Systems

  1. Become root or assume an equivalent role with the appropriate ZFS rights profile.

    For more information about the ZFS rights profiles, see ZFS Rights Profiles.

  2. Create the desired hierarchy.

    In this example, a file system that acts as a container for individual file systems is created.


    # zfs create tank/home
    
  3. Set the inherited properties.

    After the file system hierarchy is established, set up any properties that should be shared among all users:


    # zfs set mountpoint=/export/zfs tank/home
    # zfs set sharenfs=on tank/home
    # zfs set compression=on tank/home
    # zfs get compression tank/home
    NAME             PROPERTY       VALUE                      SOURCE
    tank/home        compression    on                         local

    A new feature is available that enables you to set file system properties when the file system is created. For example:


    # zfs create -o mountpoint=/export/zfs -o sharenfs=on -o compression=on tank/home
    

    For more information about properties and property inheritance, see Introducing ZFS Properties.

    Next, individual file systems are grouped under the home file system in the pool tank.

  4. Create the individual file systems.

    Note that the file systems could have been created and then the properties could have been changed at the home level. All properties can be changed dynamically while file systems are in use.


    # zfs create tank/home/bonwick
    # zfs create tank/home/billm
    

    These file systems inherit their property settings from their parent, so they are automatically mounted at /export/zfs/user and are NFS shared. You do not need to edit the /etc/vfstab or /etc/dfs/dfstab file.

    For more information about creating file systems, see Creating a ZFS File System.

    For more information about mounting and sharing file systems, see Mounting and Sharing ZFS File Systems.

  5. Set the file system-specific properties.

    In this example, user bonwick is assigned a quota of 10 Gbytes. This property places a limit on the amount of space he can consume, regardless of how much space is available in the pool.


    # zfs set quota=10G tank/home/bonwick
    
  6. View the results.

    View available file system information by using the zfs list command:


    # zfs list
    NAME                   USED  AVAIL  REFER  MOUNTPOINT
    tank                  92.0K  67.0G   9.5K  /tank
    tank/home             24.0K  67.0G     8K  /export/zfs
    tank/home/billm          8K  67.0G     8K  /export/zfs/billm
    tank/home/bonwick        8K  10.0G     8K  /export/zfs/bonwick

    Note that the user bonwick only has 10 Gbytes of space available, while the user billm can use the full pool (67 Gbytes).

    For more information about viewing file system status, see Querying ZFS File System Information.

    For more information about how space is used and calculated, see ZFS Space Accounting.