13.6. NFS-based Storage Pools
13.6.1. Creating an NFS-based Storage Pool with virt-manager
Open the host physical machine's storage tabOpen the Storage tab in the Connection Details window.
- Select a host physical machine from the main
virt-managerwindow. Click Edit menu and select Connection Details.
- Click the Storage tab.
Figure 13.20. Storage tab
Create a new pool (part 1)Press the + button (the add pool button). The Add a New Storage Pool wizard appears.
Figure 13.21. Add an NFS name and typeChoose a name for the storage pool and pressto continue.
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
Figure 13.22. Create an NFS storage poolPressto create the new storage pool.
13.6.2. Deleting a Storage Pool Using virt-manager
- 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 .
Figure 13.23. Stop Icon
- 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
Create the storage pool definitionUse the
virsh pool-define-ascommand to define a new persistent storage pool. Use the
virsh pool-create-ascommand 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-clientPool nfspool definedThe following options are required for creating NFS-based storage pools:
To view the resultant XML without defining the pool, add the
nameof the storage pool.This example uses the name nfspool. All further
virshcommands used in this example use this name.
typeof the storage pool. For an NFS-based storage pool, the type is
hostnameof the NFS server where the mount point created in step 1 is located. This can be a hostname or IP address. In this example,
localhostis used as the host.
source pathis the location on the NFS server of the files to be served.This example uses the /home/path/to/mountpoint/directory directory.
targetwhere the NFS client stores reference copies of the file.This example uses
/tmp/nfspool-clientas the target.
--print-xmloption to the command. The following shows the command above with the
# 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>
Verify that the storage pool is listedVerify that the storage pool object is created correctly and the state reports it as
virsh pool-list --allName State Autostart ----------------------------------------- default active yes nfspool inactive noYou can also run the
virsh pool-dumpxmlcommand 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>
Create the local directoryUse the
virsh pool-buildcommand to build the directory-based storage pool for a specified directory, in this example nfspool:
virsh pool-build guest_imagesPool guest_images built #
ls -la /nfspooltotal 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 --allName State Autostart ----------------------------------------- default active yes nfspool inactive no
Start the storage poolUse the
virsh pool-startcommand to enable a directory storage pool. This enables the volumes of the pool to be used as guest disk images.
virsh pool-start nfspoolPool nfspool started #
virsh pool-list --allName State Autostart ----------------------------------------- default active yes nfspool active no
NoteYou can build and start a storage pool in one step:
virsh-pool start nfspool --build
Turn on autostartTurn on
autostartfor the storage pool.
NoteThis step is optional.Autostart configures the
libvirtdservice to start the storage pool when the
virsh pool-autostart nfspoolPool nfspool marked as autostarted #
virsh pool-list --allName State Autostart ----------------------------------------- default active yes nfspool active yes
Verify the storage pool configurationVerify 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
Persistentis reported as
yes. If you want the pool to start automatically when the service starts, make sure that
Autostartis reported as
virsh pool-info nfspoolName: 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-clienttotal 8 total 4 drwxr-xr-x. 2 root root 4096 Aug 28 15:59 . drwxrwxrwt. 26 root root 640 Aug 28 16:07 .. #
13.6.4. Deleting a Storage Pool Using virsh
- 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
- Optionally, remove the directory where the storage pool resides:
virsh pool-delete nfspool
- Remove the storage pool's definition
virsh pool-undefine nfspoolPool nfspool has been undefined