12.3.3. Creating a Directory-based Storage Pool with virsh
Create the storage pool definition
Use thevirsh pool-define-as
command to define a new storage pool. There are two options required for creating directory-based storage pools:- The
name
of the storage pool.This example uses the name guest_images. All furthervirsh
commands used in this example use this name. - The
path
to a file system directory for storing guest image files. If this directory does not exist,virsh
will create it.This example uses the /guest_images directory.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow virsh pool-define-as guest_images dir - - - - "/guest_images"
# virsh pool-define-as guest_images dir - - - - "/guest_images" Pool guest_images defined
Verify the storage pool is listed
Verify the storage pool object is created correctly and the state reports it asinactive
.Copy to Clipboard Copied! Toggle word wrap Toggle overflow virsh pool-list --all
# virsh pool-list --all Name State Autostart ----------------------------------------- default active yes guest_images inactive no
Create the local directory
Use thevirsh pool-build
command to build the directory-based storage pool for the directory guest_images (for example), as shown:Copy to Clipboard Copied! Toggle word wrap Toggle overflow virsh pool-build guest_images ls -la /guest_images virsh pool-list --all
# virsh pool-build guest_images Pool guest_images built # ls -la /guest_images 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 guest_images inactive no
Start the storage pool
Use the virsh commandpool-start
to enable a directory storage pool, thereby allowing allowing volumes of the pool to be used as guest disk images.Copy to Clipboard Copied! Toggle word wrap Toggle overflow virsh pool-start guest_images virsh pool-list --all
# virsh pool-start guest_images Pool guest_images started # virsh pool-list --all Name State Autostart ----------------------------------------- default active yes guest_images active no
Turn on autostart
Turn onautostart
for the storage pool. Autostart configures thelibvirtd
service to start the storage pool when the service starts.Copy to Clipboard Copied! Toggle word wrap Toggle overflow virsh pool-autostart guest_images virsh pool-list --all
# virsh pool-autostart guest_images Pool guest_images marked as autostarted # virsh pool-list --all Name State Autostart ----------------------------------------- default active yes guest_images active yes
Verify the storage pool configuration
Verify the storage pool was created correctly, the size is reported correctly, and the state is reported asrunning
. If you want the pool to be accessible even if the guest virtual machine is not running, make sure thatPersistent
is reported asyes
. If you want the pool to start automatically when the service starts, make sure thatAutostart
is reported asyes
.Copy to Clipboard Copied! Toggle word wrap Toggle overflow virsh pool-info guest_images ls -la /guest_images
# virsh pool-info guest_images Name: guest_images UUID: 779081bf-7a82-107b-2874-a19a9c51d24c State: running Persistent: yes Autostart: yes Capacity: 49.22 GB Allocation: 12.80 GB Available: 36.41 GB # ls -la /guest_images total 8 drwx------. 2 root root 4096 May 30 02:44 . dr-xr-xr-x. 26 root root 4096 May 30 02:44 .. #
A directory-based storage pool is now available.