13.6. NFS-based Storage Pools

This section provides information about creating and deleting storage pools with an NFS mount point. It assumes that an NFS is already mounted on the host machine. For more information about creating and adding an NFS mount point, see the Red Hat Enterprise Linux Storage Administration Guide.

13.6.1. Creating an NFS-based Storage Pool with virt-manager

  1. Open the host physical machine's storage tab

    Open the Storage tab in the Connection Details window.
    1. Open virt-manager.
    2. Select a host physical machine from the main virt-manager window. Click Edit menu and select Connection Details.
    3. Click the Storage tab.
      Storage tab

      Figure 13.20. Storage tab

  2. Create a new pool (part 1)

    Press the + button (the add pool button). The Add a New Storage Pool wizard appears.
    Add an NFS name and type

    Figure 13.21. Add an NFS name and type

    Choose a name for the storage pool and press Forward to continue.
  3. Create a new pool (part 2)

    Enter the target path for the device, the host name and the NFS share path. Set the Format option to NFS or auto (to detect the type). The target path must be identical on all host physical machines for migration.
    Enter the host name or IP address of the NFS server. This example uses server1.example.com.
    Enter the NFS path. This example uses /nfstrial.
    Create an NFS storage pool

    Figure 13.22. Create an NFS storage pool

    Press Finish to create the new storage pool.

13.6.2. Deleting a Storage Pool Using virt-manager

This procedure demonstrates how to delete a storage pool.
  1. To avoid any issues with other guests using the same pool, it is best to stop the storage pool and release any resources in use by it. To do this, select the storage pool you want to stop and click .
    Stop Icon

    Figure 13.23. Stop Icon

  2. Delete the storage pool by clicking the Trash can icon. This icon is only enabled if you stop the storage pool first.

13.6.3. Creating an NFS-based Storage Pool with virsh

Procedure 13.8. Creating an NFS-based storage pool

  1. Create the storage pool definition

    Use the virsh pool-define-as command to define a new persistent storage pool. Use the virsh pool-create-as command to define a new non-persistent storage pool.
    A persistent storage pool is accessible even when the guest virtual machine is not running and continues to exist after the host reboots. A non-persistant storage pool is only available when the guest virtual machine is running and only exists until the host reboots.
    This example uses a persistent storage pool.
    # virsh pool-define-as nfspool netfs --sourcehost localhost --source-path /home/path/to/mountpoint/directory --target /tmp/nfspool-client
    Pool nfspool defined
    The following options are required for creating NFS-based storage pools:
    • The name of the storage pool.
      This example uses the name nfspool. All further virsh commands used in this example use this name.
    • The type of the storage pool. For an NFS-based storage pool, the type is netfs.
    • The hostname of the NFS server where the mount point created in step 1 is located. This can be a hostname or IP address. In this example, localhost is used as the host.
    • The source path is the location on the NFS server of the files to be served.
      This example uses the /home/path/to/mountpoint/directory directory.
    • The target where the NFS client stores reference copies of the file.
      This example uses /tmp/nfspool-client as the target.
    To view the resultant XML without defining the pool, add the --print-xml option to the command. The following shows the command above with the --print-xml option added:
    # virsh pool-define-as nfspool netfs --sourcehost localhost --source-path /home/path/to/mountpoint/directory --target /tmp/nfspool-client --print-xml
    <pool type='netfs'>
      <name>nfspool</name>
      <source>
        <host name='localhost'/>
        <dir path='/home/path/to/mountpoint/directory'/>
      </source>
      <target>
        <path>/tmp/nfspool-client</path>
      </target>
    </pool>
  2. Verify that the storage pool is listed

    Verify that the storage pool object is created correctly and the state reports it as inactive.
    # virsh pool-list --all
    Name                 State      Autostart
    -----------------------------------------
    default              active     yes
    nfspool              inactive   no
    You can also run the virsh pool-dumpxml command to view the output.
    # virsh pool-dumpxml nfspool
    <pool type='netfs'>
    <name>nfspool</name>
    <uuid>ad9bca0f-977f-4fe1-90c6-cb44f676f1ce</uuid>
    <capacity unit='bytes'>0</capacity>
    <allocation unit='bytes'>0</allocation>
    <available unit='bytes'>0</available>
    <source>
      <host name='localhost'/>
      <dir path='/home/vm-storage/nfspool'/>
      <format type='auto'/>
    </source>
    <target>
      <path>/tmp/nfspool-client</path>
    </target>
    </pool>
  3. Create the local directory

    Use the virsh pool-build command to build the directory-based storage pool for a specified directory, in this example nfspool:
    # virsh pool-build guest_images
    Pool guest_images built
    # ls -la /nfspool
    total 8
    drwx------.  2 root root 4096 May 30 02:44 .
    dr-xr-xr-x. 26 root root 4096 May 30 02:44 ..
    # virsh pool-list --all
    Name                 State      Autostart
    -----------------------------------------
    default              active     yes
    nfspool              inactive   no
  4. Start the storage pool

    Use the virsh pool-start command to enable a directory storage pool. This enables the volumes of the pool to be used as guest disk images.
    # virsh pool-start nfspool
    Pool nfspool started
    # virsh pool-list --all
    Name                 State      Autostart
    -----------------------------------------
    default             active     yes
    nfspool             active     no
    

    Note

    You can build and start a storage pool in one step:
    # virsh-pool start nfspool --build
  5. Turn on autostart

    Turn on autostart for the storage pool.

    Note

    This step is optional.
    Autostart configures the libvirtd service to start the storage pool when the libvirtd service starts.
    # virsh pool-autostart nfspool
    Pool nfspool marked as autostarted
    # virsh pool-list --all
    Name                 State      Autostart
    -----------------------------------------
    default              active     yes
    nfspool              active     yes
    
  6. Verify the storage pool configuration

    Verify the storage pool was created correctly, the size is reported correctly, and the state is reported as running. If you want the pool to be persistent, make sure that Persistent is reported as yes. If you want the pool to start automatically when the service starts, make sure that Autostart is reported as yes.
    # virsh pool-info nfspool
    Name:           nfspool
    UUID:           ad9bca0f-977f-4fe1-90c6-cb44f676f1ce
    State:          running
    Persistent:     yes
    Autostart:      yes
    Capacity:       123.63 GiB
    Allocation:     10.87 GiB
    Available:      112.76 GiB
    
    # ls -la /tmp/nfspool-client
    total 8
    total 4
    drwxr-xr-x.  2 root root 4096 Aug 28 15:59 .
    drwxrwxrwt. 26 root root  640 Aug 28 16:07 ..
    #
    
The NFS-based storage pool is now available.

13.6.4. Deleting a Storage Pool Using virsh

The following demonstrates how to delete a storage pool using virsh:
  1. To avoid any issues with other guest virtual machines using the same pool, it is best to stop the storage pool and release any resources in use by it.
    # virsh pool-destroy nfspool
  2. Optionally, remove the directory where the storage pool resides:
    # virsh pool-delete nfspool
  3. Remove the storage pool's definition
    # virsh pool-undefine nfspool
    Pool nfspool has been undefined