이 콘텐츠는 선택한 언어로 제공되지 않습니다.

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.

맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat