13.4. LVM-based Storage Pools
This chapter covers using LVM volume groups as storage pools.
LVM-based storage groups provide the full flexibility of LVM.
Note
Thin provisioning is currently not possible with LVM based storage pools.
Note
For more details on LVM, refer to the Red Hat Enterprise Linux Storage Administration Guide.
Warning
LVM-based storage pools require a full disk partition. If activating a new partition/device with these procedures, the partition will be formatted and all data will be erased. If using the host's existing Volume Group (VG) nothing will be erased. It is recommended to back up the storage device before commencing the following procedure.
13.4.1. Creating an LVM-based Storage Pool with virt-manager
LVM-based storage pools can use existing LVM volume groups or create new LVM volume groups on a blank partition.
Optional: Create new partition for LVM volumes
These steps describe how to create a new partition and LVM volume group on a new hard disk drive.Warning
This procedure will remove all data from the selected storage device.Create a new partition
Use thefdiskcommand to create a new disk partition from the command line. The following example creates a new partition that uses the entire disk on the storage device/dev/sdb.#
fdisk /dev/sdbCommand (m for help):Pressnfor a new partition.- Press
pfor a primary partition.Command action e extended p primary partition (1-4)
- Choose an available partition number. In this example the first partition is chosen by entering
1.Partition number (1-4):
1 - Enter the default first cylinder by pressing
Enter.First cylinder (1-400, default 1):
- Select the size of the partition. In this example the entire disk is allocated by pressing
Enter.Last cylinder or +size or +sizeM or +sizeK (2-400, default 400):
- Set the type of partition by pressing
t.Command (m for help):
t - Choose the partition you created in the previous steps. In this example, the partition number is
1.Partition number (1-4):
1 - Enter
8efor a Linux LVM partition.Hex code (type L to list codes):
8e - write changes to disk and quit.
Command (m for help):
wCommand (m for help):q Create a new LVM volume group
Create a new LVM volume group with thevgcreatecommand. This example creates a volume group named guest_images_lvm.#
vgcreate guest_images_lvm /dev/sdb1Physical volume "/dev/vdb1" successfully created Volume group "guest_images_lvm" successfully created
The new LVM volume group, guest_images_lvm, can now be used for an LVM-based storage pool.Open the storage pool settings
- In the
virt-managergraphical interface, select the host from the main window.Open the Edit menu and select Connection Details - click the Storage tab.
Create the new storage pool
Start the Wizard
Press the + button (the add pool button). The Add a New Storage Pool wizard appears.Choose a for the storage pool. We use guest_images_lvm for this example. Then change the tological: LVM Volume Group, andPress to continue.Add a new pool (part 2)
Fill in the and fields, and check the check box.- Use the field to either select an existing LVM volume group or as the name for a new volume group. The default format is storage_pool_name/lvm_Volume_Group_name.This example uses a new volume group named /dev/guest_images_lvm.
- The
Source Pathfield is optional if an existing LVM volume group is used in the .For new LVM volume groups, input the location of a storage device in theSource Pathfield. This example uses a blank partition /dev/sdc. - The check box instructs
virt-managerto create a new LVM volume group. If you are using an existing volume group you should not select the check box.This example is using a blank partition to create a new volume group so the check box must be selected.
Verify the details and press the button format the LVM volume group and create the storage pool.Confirm the device to be formatted
A warning message appears.Press the Yes button to proceed to erase all data on the storage device and create the storage pool.
Verify the new storage pool
The new storage pool will appear in the list on the left after a few seconds. Verify the details are what you expect, 465.76 GB Free in our example. Also verify the field reports the new storage pool as Active.It is generally a good idea to have the check box enabled, to ensure the storage pool starts automatically with libvirtd.Close the Connection Details dialog, as the task is now complete.
13.4.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
.
- Delete the storage pool by clicking
. This icon is only enabled if you stop the storage pool first.
13.4.3. Creating an LVM-based Storage Pool with virsh
This section outlines the steps required to create an LVM-based storage pool with the
virsh command. It uses the example of a pool named guest_images_lvm from a single drive (/dev/sdc). This is only an example and your settings should be substituted as appropriate.
Procedure 13.3. Creating an LVM-based storage pool with virsh
- Define the pool name guest_images_lvm.
#
virsh pool-define-as guest_images_lvm logical - - /dev/sdc libvirt_lvm \ /dev/libvirt_lvmPool guest_images_lvm defined - Build the pool according to the specified name. If you are using an already existing volume group, skip this step.
#
virsh pool-build guest_images_lvmPool guest_images_lvm built - Initialize the new pool.
#
virsh pool-start guest_images_lvmPool guest_images_lvm started - Show the volume group information with the
vgscommand.#
vgsVG #PV #LV #SN Attr VSize VFree libvirt_lvm 1 0 0 wz--n- 465.76g 465.76g - Set the pool to start automatically.
#
virsh pool-autostart guest_images_lvmPool guest_images_lvm marked as autostarted - List the available pools with the
virshcommand.#
virsh pool-list --allName State Autostart ----------------------------------------- default active yes guest_images_lvm active yes - The following commands demonstrate the creation of three volumes (volume1, volume2 and volume3) within this pool.
#
virsh vol-create-as guest_images_lvm volume1 8GVol volume1 created #virsh vol-create-as guest_images_lvm volume2 8GVol volume2 created #virsh vol-create-as guest_images_lvm volume3 8GVol volume3 created - List the available volumes in this pool with the
virshcommand.#
virsh vol-list guest_images_lvmName Path ----------------------------------------- volume1 /dev/libvirt_lvm/volume1 volume2 /dev/libvirt_lvm/volume2 volume3 /dev/libvirt_lvm/volume3 - The following two commands (
lvscanandlvs) display further information about the newly created volumes.#
lvscanACTIVE '/dev/libvirt_lvm/volume1' [8.00 GiB] inherit ACTIVE '/dev/libvirt_lvm/volume2' [8.00 GiB] inherit ACTIVE '/dev/libvirt_lvm/volume3' [8.00 GiB] inherit #lvsLV VG Attr LSize Pool Origin Data% Move Log Copy% Convert volume1 libvirt_lvm -wi-a- 8.00g volume2 libvirt_lvm -wi-a- 8.00g volume3 libvirt_lvm -wi-a- 8.00g
13.4.4. Deleting a Storage Pool Using virsh
The following demonstrates how to delete a storage pool using virsh:
- 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.
#
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




