13.2. Partition-based Storage Pools
This section covers using a pre-formatted block device, a partition, as a storage pool.
For the following examples, a host physical machine has a 500GB hard drive (
/dev/sdc) partitioned into one 500GB partition (/dev/sdc1). We set up a storage pool for it using the procedure below.
13.2.1. Creating a Partition-based Storage Pool Using virt-manager
This procedure creates a new storage pool using a partition of a storage device.
Procedure 13.1. Creating a partition-based storage pool with virt-manager
Set the File System to ext4
From a command window, enter the following command to set the file system to ext4#
mkfs.ext4 /dev/sdc1Open the storage pool settings
- In the
virt-managergraphical interface, select the host physical machine from the main window.Open the Edit menu and select Connection Details - click the Storage tab of the Connection Details window.
Create the new storage pool
Add a new pool (part 1)
Press the + button (at the bottom of the window). The Add a New Storage Pool wizard appears.Choose a for the storage pool. This example uses the name guest_images_fs. Change the tofs: Pre-Formatted Block Device.Press the button to continue.Add a new pool (part 2)
Change the , , and fields.Verify the details and press the button to create the storage pool.
Verify the new storage pool
The new storage pool appears in the storage list on the left after a few seconds. Verify the size is reported as expected, 2.88 GB Free in this example. Verify the field reports the new storage pool as Active.Select the storage pool. In the field, click the check box. This will make sure the storage device starts whenever thelibvirtdservice starts.The storage pool is now created, close the Connection Details window.
13.2.2. Deleting a Storage Pool Using virt-manager
This procedure demonstrates how to delete a storage pool.
- 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. To do this, select the storage pool you want to stop and click
at the bottom of the Storage window.
- Delete the storage pool by clicking
. This icon is only enabled if you stop the storage pool first.
13.2.3. Creating a Partition-based Storage Pool Using virsh
This section covers creating a partition-based storage pool with the
virsh command.
Warning
Do not use this procedure to assign an entire disk as a storage pool (for example,
/dev/sdb). Guests should not be given write access to whole disks or block devices. Only use this method to assign partitions (for example, /dev/sdb1) to storage pools.
Procedure 13.2. Creating pre-formatted block device storage pools using virsh
Create the storage pool definition
Use the virshpool-define-ascommand to create a new storage pool definition. There are three options that must be provided to define a pre-formatted disk as a storage pool:- Partition name
- The
nameparameter determines the name of the storage pool. This example uses the name guest_images_fs in the example below. - device
- The
deviceparameter with thepathattribute specifies the device path of the storage device. This example uses the partition /dev/sdc1. - mountpoint
- The
mountpointon the local file system where the formatted device will be mounted. If the mount point directory does not exist, thevirshcommand can create the directory.The directory /guest_images is used in this example.
#
virsh pool-define-as guest_images_fs fs - - /dev/sdc1 - "/guest_images"Pool guest_images_fs definedThe new pool is now created.Verify the new pool
List the present storage pools.#
virsh pool-list --allName State Autostart ----------------------------------------- default active yes guest_images_fs inactive noCreate the mount point
Use thevirsh pool-buildcommand to create a mount point for a pre-formatted file system storage pool.#
virsh pool-build guest_images_fsPool guest_images_fs built #ls -la /guest_imagestotal 8 drwx------. 2 root root 4096 May 31 19:38 . dr-xr-xr-x. 25 root root 4096 May 31 19:38 .. #virsh pool-list --allName State Autostart ----------------------------------------- default active yes guest_images_fs inactive noStart the storage pool
Use thevirsh pool-startcommand to mount the file system onto the mount point and make the pool available for use.#
virsh pool-start guest_images_fsPool guest_images_fs started #virsh pool-list --allName State Autostart ----------------------------------------- default active yes guest_images_fs active noTurn on autostart
By default, a storage pool is defined withvirshis not set to automatically start each timelibvirtdstarts. Turn on automatic start with thevirsh pool-autostartcommand. The storage pool is now automatically started each timelibvirtdstarts.#
virsh pool-autostart guest_images_fss Pool guest_images_fs marked as autostarted #virsh pool-list --allName State Autostart ----------------------------------------- default active yes guest_images_fs active yesVerify the storage pool
Verify the storage pool was created correctly, the sizes reported are as expected, and the state is reported asrunning. Verify there is a "lost+found" directory in the mount point on the file system, indicating the device is mounted.#
virsh pool-info guest_images_fsName: guest_images_fs UUID: c7466869-e82a-a66c-2187-dc9d6f0877d0 State: running Persistent: yes Autostart: yes Capacity: 458.39 GB Allocation: 197.91 MB Available: 458.20 GB #mount | grep /guest_images/dev/sdc1 on /guest_images type ext4 (rw) #ls -la /guest_imagestotal 24 drwxr-xr-x. 3 root root 4096 May 31 19:47 . dr-xr-xr-x. 25 root root 4096 May 31 19:38 .. drwx------. 2 root root 16384 May 31 14:18 lost+found
13.2.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 guest_images_disk - Optionally, if you want to remove the directory where the storage pool resides use the following command:
#
virsh pool-delete guest_images_disk - Remove the storage pool's definition
#
virsh pool-undefine guest_images_disk



