From nobody Sat Feb 7 06:35:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620664867; cv=none; d=zohomail.com; s=zohoarc; b=EYZm0GcqJPRXux5CkaX2OTJtqRXaweX1O4F0RxmCaioka2Dq6COVbadKWCTWHZz5SvBV7Wl5za4OqV/2VsZopTRjBtj7lcC4bDiuEZF4CjqoWjoUHAUQDB62zpth0nN37iVqnkUDh2xHRHMN//t1/5ONF24Fqa2iMhxusHO7EHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620664867; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=nLIZtOhKnSXDRTMacNUDxEcR7GuI4XZ1aPnFa+FPFsA=; b=Z8r7dAVk3we7at/NugcKMFNE1JpfWxJfxWTDKu2aNQ5JHdhncQBvYomcNStYxSiNnv2L6MfLiXvI9xOMGxoyE8pPmkTX6/jSrZ7iilJQyLxv0I0mpCqxTpZ5+2+mBWVwaZzbsSNf/EWkFaMJI0aIU8qRdmv+0eLMm6B60p4CFGk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620664867064130.6591203086724; Mon, 10 May 2021 09:41:07 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-286-g_cXSycoO1iBeVEWnTI_fw-1; Mon, 10 May 2021 12:40:22 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 435CBA40C4; Mon, 10 May 2021 16:40:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 153E51E6; Mon, 10 May 2021 16:40:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CE2CB1800B8A; Mon, 10 May 2021 16:40:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14AGeAXO026001 for ; Mon, 10 May 2021 12:40:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 066CD60BD8; Mon, 10 May 2021 16:40:10 +0000 (UTC) Received: from localhost.localdomain (ovpn-115-55.ams2.redhat.com [10.36.115.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D46519EF1; Mon, 10 May 2021 16:40:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620664865; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=nLIZtOhKnSXDRTMacNUDxEcR7GuI4XZ1aPnFa+FPFsA=; b=OaxnFGqOkT9HiZ7UkYvMZey/fZTjNoXYDIVlThcEUJQ0lP7aLixjqWM3K8Lrzabmc0lsEj aHlIiacURIIuKawwptxjZNxhQ7i7LJ5lU/ypOt7gi4fdthWUCshEaFkgxOZaWyQKKG88qu 0XovmHZe6es0hhHle9BtGBy/1RllMwY= X-MC-Unique: g_cXSycoO1iBeVEWnTI_fw-1 From: Kashyap Chamarthy To: libvir-list@redhat.com Subject: [libvirt PATCH v2 2/2] docs: kbase: Add a doc on merging disk image chains Date: Mon, 10 May 2021 18:39:56 +0200 Message-Id: <20210510163956.549925-3-kchamart@redhat.com> In-Reply-To: <20210510163956.549925-1-kchamart@redhat.com> References: <20210510163956.549925-1-kchamart@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) This is a rewrite of: https://wiki.libvirt.org/page/Live-merge-an-entire-disk-image-chain-inc= luding-current-active-disk Once this commit merges, the above wiki should point to this kbase document. Signed-off-by: Kashyap Chamarthy --- docs/kbase/merging_disk_image_chains.rst | 200 +++++++++++++++++++++++ docs/kbase/meson.build | 1 + 2 files changed, 201 insertions(+) create mode 100644 docs/kbase/merging_disk_image_chains.rst diff --git a/docs/kbase/merging_disk_image_chains.rst b/docs/kbase/merging_= disk_image_chains.rst new file mode 100644 index 0000000000..7635bd3eec --- /dev/null +++ b/docs/kbase/merging_disk_image_chains.rst @@ -0,0 +1,200 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D +Merging disk image image chains +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D + +.. contents:: + +Context +=3D=3D=3D=3D=3D=3D=3D + +Sometimes a `disk image chain +`_ can get long and +cumbersome. For the purpose of illustration, consider this smaller disk +image chain:: + + base.raw <-- a.qcow2 <-- b.qcow2 <-- c.qcow2 (live QEMU) + +You may want to reduce the backing chain length, or consolidate *all* +the disk images in the chain into a single image. But you want to +accomplish this *without* incurring guest down time. Here's how to go +about it. + +The same principles used in the `live full disk backup +` document are +used here too. + +Reducing the disk image chain length +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Starting the earlier image chain:: + + base.raw <-- a.qcow2 <-- b.qcow2 <-- c.qcow2 (live QEMU) + +Reduce the length of the chain by two images, with the resulting chain +being:: + + base.raw <-- c.qcow2 (live QEMU) + +Where the ``base.raw`` contains the contents of ``a.qcow2`` and +``b.qcow2``. + +#. Start by listing the current active disk image in use:: + + $ virsh domblklist vm1 + Target Source + ------------------------------------------------ + vda /var/lib/libvirt/images/base.raw + +#. Create the image chain by creating three QCOW2 overlays (or "external + snapshots") on top of each other, while adding some differentiating + content in each image:: + + $ virsh snapshot-create-as --domain vm1 snap1 \ + --diskspec vda,file=3D/var/lib/libvirt/images/a.qcow2 \ + --disk-only --no-metadata + + # + + $ virsh snapshot-create-as --domain vm1 snap2 \ + --diskspec vda,file=3D/var/lib/libvirt/images/b.qcow2 \ + --disk-only --no-metadata + + # + + $ virsh snapshot-create-as --domain vm1 snap3 \ + --diskspec vda,file=3D/var/lib/libvirt/images/c.qcow2 \ + --disk-only --no-metadata + +#. Enumerate the backing file chain (here the ``force-share`` option + simply allows ``qemu-img`` to safely query the disk image status + while it is active) :: + + $ qemu-img info --force-share --backing-chain /var/lib/libvirt/images/= cur.qcow2 + [...] + +#. Again, list the current active disk image in use:: + + $ virsh domblklist vm1 + Target Source + ------------------------------------------------ + vda /var/lib/libvirt/images/c.qcow2 + +#. Perform the "block-commit" by specify the "base" and "top" images, + i.e. merge the contents of ``b.qcow2`` *and* ``a.qcow2`` into + ``base.raw``, *and* :: + + $ virsh blockcommit vm1 vda \ + --base=3D/var/lib/libvirt/images/base.raw + --top=3D/var/lib/libvirt/images/b.qcow2 + +A note on accessing 'base' and 'top' images +------------------------------------------- + +Specifying file paths, as above, make sense when your disks are in the +local filesystem. However, when using more complicated setups such as +network block device (NBD) disks, there are no file paths. Hhere is +where accessing the disk by its index number comes into picture. + +As an example, the below is the ```` element of the guest XML for +with the original disk image chain of four images:: + + ... + + + + + + + + + + + + + + + + + + +
+ + ... + +And we can merge the images ``a.qcow2`` and ``b.qcow2`` into +``base.qcow2`` using the index numbers 1 (for ``base.qcow2``) and :: + + $> virsh blockcommit vm1 vda --base=3D'vda[1]' --top=3D'vda[3]' + +Note that the shell quoting is necessary here, since unquoted ``[1]`` +would do an unexpected shell "globbing" (i.e. file name expansion) if +you have a file '1' in the current directory + +Accessing the disk images via their index numbers is more useful when +you're using blockCommit() API programmatically. + + +Consolidating an entire disk image chain into a single image +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Again, starting the original image chain:: + + base.raw <-- a.qcow2 <-- b.qcow2 <-- c.qcow2 (live QEMU) + +Reduce the length of the chain by two images, with the resulting chain +being:: + + base.raw (live QEMU) + +Where the ``base.raw`` contains the contents of ``a.qcow2``, ``b.qcow2`` +and ``c.qcow2``; *and* the live QEMU is piovoted to point to the +``base.raw``. + + +#. Use the same procedure discussed earlier to create the disk image + chain. + + +#. Now perform the "active block-commit" operation:: + + $ virsh blockcommit vm1 vda --verbose --pivot --active + Block Commit: [100 %] + Successfully pivoted + + Notes: + + - ``--active``: It performs a two-stage operation: first, the contents + from top images (``a.qcow2``, ``b.qcow2``, and ``c.qcow2``) are + committed into the base image; and in the second stage, the the + "block-commit" operation remains awake to synchronize any further + changes from top images into base. Here the user can take two + actions: cancel the job, or pivot the job, i.e. adjust the base + image as the current active image. + + - ``--pivot``: Once data is committed from sn1, sn2 and current into + base, it pivots the live QEMU to use base as the active image. + + - ``--verbose``: It shows the progress of block operation. + + +#. Again, check the current active block device in use:: + + $ virsh domblklist vm1 + Target Source + ------------------------------------------------ + vda /var/lib/libvirt/images/base.raw + + +#. Enumerate the backing file chain:: + + $ qemu-img info --backing-chain /var/lib/libvirt/images/base.raw + [...] + + And the final resulting disk image "chain" will be a single, + consolidated disk image:: + + [base] (live QEMU) + +It is worth bearing in mind that once the above pivot completes, *all* +three overlay files =E2=80=94 ``a.qcow2``, ``b.qcow2``, and ``c.qcow2`` = =E2=80=94 are no +longer valid, and can be safely discarded. diff --git a/docs/kbase/meson.build b/docs/kbase/meson.build index 51d4bc7b90..7631b47018 100644 --- a/docs/kbase/meson.build +++ b/docs/kbase/meson.build @@ -10,6 +10,7 @@ docs_kbase_files =3D [ 'locking-lockd', 'locking', 'locking-sanlock', + 'merging_disk_image_chains', 'migrationinternals', 'qemu-passthrough-security', 'rpm-deployment', --=20 2.30.2