Ce contenu n'est pas disponible dans la langue sélectionnée.

Chapter 6. QEMU


One of the use cases for Ceph Block Devices involves providing block device images to virtual machines. For example, a user may create a "golden" image with an operating system and any relevant software in an ideal configuration. Then, the user takes a snapshot of the image. Finally, the user clones the snapshot, typically many times. The ability to make copy-on-write clones of a snapshot means that Ceph can provision block device images to virtual machines quickly, because the client doesn’t have to download an entire image each time it spins up a new virtual machine. See Chapter 3, Snapshots for more details. Ceph Block Devices can integrate with the QEMU virtual machine.

Important

To use Ceph Block Devices with QEMU, you must have access to a running Ceph storage cluster.

6.1. Quick Start

A storage pool, a RBD image and a client key will need to be created to host the virtual machines images. Perform the following commands from a Ceph Monitor or a Ceph client node.

  1. Create a storage pool:

    Syntax

    # ceph osd pool create <pool_name> <pg_num> [<pgp_num>]
    Copy to Clipboard Toggle word wrap

    Example

    # ceph osd pool create libvirt-pool 128 128
    Copy to Clipboard Toggle word wrap

  2. Create a RBD image for the virtual machine:

    Syntax

    # rbd create <image_name> --size <megabytes> --pool <pool-name> --image-format 2
    Copy to Clipboard Toggle word wrap

    Example

    # rbd create librbd --size 13240 --pool libvirt-pool --image-format 2
    Copy to Clipboard Toggle word wrap

  3. Create a Ceph user and add capabilities:

    Syntax

    # ceph auth get-or-create client.<user_name> <daemon_type> 'allow <capability>' [<daemon_type> 'allow <capability> pool=<pool_name>']
    Copy to Clipboard Toggle word wrap

    Example

    # ceph auth get-or-create client.libvirt mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=libvirt-pool'
    Copy to Clipboard Toggle word wrap

  4. Verify the user’s authentication key and capabilities:

    Exmaple

    # ceph auth list client.libvirt
    
    client.libvirt
           key: AQC/+EhVmQ+NOxAA0OZAEXBSR0pD3gDPwxrFDA==
           caps: [mon] allow r
           caps: [osd] allow class-read object_prefix rbd_children, allow rwx pool=libvirt-pool
    Copy to Clipboard Toggle word wrap

    Note

    Make note of the client.libvirt key.

On the client node, verify that KVM/QEMU packages are installed and the libvirtd service is running. See the Red Hat Enterprise Linux Virtualization Deployment and Administration Guide for more details. Also, verify that the latest ceph-common package is installed. See the Red Hat Ceph Storage Installation Guide for more details. Then create a virtual machine, but do not add any storage devices to the virtual machine. If the virtual machine powers on after creation, then power off the virtual machine before editing.

  1. Edit the virtual machine configuration:

    Syntax

    # virsh edit <VM_name>
    Copy to Clipboard Toggle word wrap

    Exmaple

    # virsh edit example-vm
    Copy to Clipboard Toggle word wrap

  2. Add the new RBD image to the virtual machine configuration. Append the following code block to the end of the virtual machine configuration. Substitute the Ceph Monitor for the <monitor_host_name> variable:

    Example

    <disk type='network' device='disk'>
          <source protocol='rbd' name='libvirt-pool/librbd'>
                <host name='<monitor_host_name>' port='6789'/>
          </source>
          <target dev='vda' bus='virtio'/>
    </disk>
    Copy to Clipboard Toggle word wrap

  3. Create a secret.xml file using the client.libvirt user:

    Example

    # cat > secret.xml <<EOF
    <secret ephemeral='no' private='no'>
          <usage type='ceph'>
                <name>client.libvirt secret</name>
          </usage>
    </secret>
    EOF
    Copy to Clipboard Toggle word wrap

  4. Define the secret:

    Example

    # virsh secret-define --file secret.xml
    Copy to Clipboard Toggle word wrap

    Note

    Make note of the generated UUID that is returned. This will be used to set the secret.

  5. Set the UUID:

    Syntax

    # virsh secret-set-value --secret <uuid_from_previous_step> --base64 <ceph_user_key>
    Copy to Clipboard Toggle word wrap

    Example

    # virsh secret-set-value --secret 727c2e12-a6ac-4f57-a553-8b6fd13a1da9 --base64 AQC/+EhVmQ+NOxAA0OZAEXBSR0pD3gDPwxrFDA==
    Copy to Clipboard Toggle word wrap

  6. Edit the virtual machine configuration and add authentication block to the disk block:

    Authentication Block Example

    <auth username='libvirt'>
          <secret type='ceph' uuid='727c2e12-a6ac-4f57-a553-8b6fd13a1da9'/>
    </auth>
    Copy to Clipboard Toggle word wrap

    Full Disk Block Example

    <disk type='network' device='disk'>
          <driver name='qemu' type='raw'/>
              <auth username='libvirt'>
                  <secret type='ceph' uuid='727c2e12-a6ac-4f57-a553-8b6fd13a1da9'/>
              </auth>
          <source protocol='rbd' name='libvirt-pool/librbd'>
              <host name='MON1' port='6789'/>
          </source>
          <target dev='vda' bus='virtio'/>
    </disk>
    Copy to Clipboard Toggle word wrap

  7. Start the virtual machine and install an operating system.
Important

Configuring the authentication is required for each KVM/QEMU client.

Retour au début
Red Hat logoGithubredditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance. Découvrez nos récentes mises à jour.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez le Blog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

Theme

© 2025 Red Hat