Create an LVM Storage Pool with Libvirt

Hands-On Lab

 

Photo of Matthew Pearson

Matthew Pearson

Linux Training Architect II in Content

Length

01:00:00

Difficulty

Intermediate

Libvirt is a collection of software that provides a unified method for managing virtual machines on different virtualization platforms. One of the management features is the ability to create storage pools that can be used when provisioning virtual machines. In this hands-on lab, you will be tasked with creating an LVM storage pool that you will use to create multiple storage volumes.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Create an LVM Storage Pool with Libvirt

Introduction

Libvirt is a collection of software that provides a unified method for managing virtual machines on different virtualization platforms. One of the management features is the ability to create storage pools that can be used when provisioning virtual machines. In this hands-on lab, you will be tasked with creating an LVM storage pool that you will use to create multiple storage volumes.

Solution

  1. Begin by logging in to the lab server using the credentials provided on the hands-on lab page:

    ssh cloud_user@PUBLIC_IP_ADDRESS
  2. Become the root user:

    sudo -i

Install the libvirt package

  1. Install libvirt:

    yum install libvirt

Start and enable the libvirt service

  1. Start up the libvirt service:

    systemctl start libvirtd
  2. Enable it to start at boot:

    systemctl enable libvirtd

Create a volume group named vg-libvirt using the /dev/xvdg disk

  1. Create a physical volume using the /dev/xvdg disk:

    pvcreate /dev/xvdg
  2. Create the vg-libvirt volume group using the /dev/xvdg physical volume:

    vgcreate vg-libvirt /dev/xvdg

Create a storage pool called lvm_pool using the vg-libvirt volume group

Create a storage pool called lvm_pool using the vg-libvirt volume group, and ensure that it is initialized and that autostart has been enabled.

  1. Create the storage pool using the vg-libvirt logical volume:

    virsh pool-define-as lvm_pool logical --source-name vg-libvirt --target /dev/xvdg
  2. Start the storage pool:

    virsh pool-start lvm_pool
  3. Enable autostart for the storage pool:

    virsh pool-autostart lvm_pool

Create two storage volumes named vol1 and vol2 from the lvm_pool storage pool

Create two storage volumes named vol1 and vol2 from the lvm_pool storage pool. Each volume should be 4 GB.

  1. Create the vol1 volume:

    virsh vol-create-as lvm_pool vol1 4G
  2. Create the vol2 volume:

    virsh vol-create-as lvm_pool vol2 4G
  3. Verify both volumes were created correctly:

    virsh vol-list lvm_pool

Conclusion

Congratulations — you've completed this hands-on lab!