From nobody Mon Feb 9 10:28:59 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=1620145003; cv=none; d=zohomail.com; s=zohoarc; b=lQ7PZUrwvEU61CO0SSgDHaPvxcjm6jLT3xEmtjb2BbrCmWMvyZRgTLgI7RnNP4npVJIujVcRGH7e3z3t3RLWcbQ8LG53bTZiZMVXIR8pmUZeRzZmmmvkGw9Vwnw1ubXxGvgOngLG8uPXOrNH+Qo8MEgoASgM82K2/Qrhs9qR+Jo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620145003; 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=89AFGFS2b9Tkt9XPLvpyN/wvGOlHyi1EkMQaKb/ujuI=; b=I1vhjlshy9PURhYHU62VybFOuoeLFlngHBamqmCBrYnn9L4Y2NaTfS+aZxkPlFXRwl3/raZQy8thjK58o2s9+kYqa1e5TFWy3otYpOp10EIYPtJEjOrVB/bfSmRE6axqX0cNFtqWxQdg9uL27hzvN960eo5dvAFQdtBgXv3LxxE= 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 1620145003313861.2937092221698; Tue, 4 May 2021 09:16:43 -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-450-rMbkjn08NL2I1MhNmRZoqw-1; Tue, 04 May 2021 12:16:39 -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 9ED1580ED8B; Tue, 4 May 2021 16:16:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 77FDF5C238; Tue, 4 May 2021 16:16:33 +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 3ACFF5534E; Tue, 4 May 2021 16:16:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144GGNZF026833 for ; Tue, 4 May 2021 12:16:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 385FA90BD; Tue, 4 May 2021 16:16:23 +0000 (UTC) Received: from localhost.localdomain (ovpn-113-176.ams2.redhat.com [10.36.113.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3BF819C71; Tue, 4 May 2021 16:16:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620145001; 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=89AFGFS2b9Tkt9XPLvpyN/wvGOlHyi1EkMQaKb/ujuI=; b=WOFrezomXeJ1cZ82sOrxdjyV5ED4XwLzFjY2s800ntevKn01rZig3NHG3X5v7e0p+f56xw swHOYL6ELOkDkeocCtZEOlHVRFZYDpZ646nZDWIeyuXa+IrESpbH902w32ke+hO1gtR72B hGWgzioe1Bqxx39vmfSPPnpat75Eqnc= X-MC-Unique: rMbkjn08NL2I1MhNmRZoqw-1 From: Kashyap Chamarthy To: libvir-list@redhat.com Subject: [libvirt PATCH 2/2] docs: kbase: Add a doc on merging disk image chains Date: Tue, 4 May 2021 18:16:13 +0200 Message-Id: <20210504161613.159831-3-kchamart@redhat.com> In-Reply-To: <20210504161613.159831-1-kchamart@redhat.com> References: <20210504161613.159831-1-kchamart@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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/index.rst | 3 + docs/kbase/merging_disk_image_chains.rst | 197 +++++++++++++++++++++++ 2 files changed, 200 insertions(+) create mode 100644 docs/kbase/merging_disk_image_chains.rst diff --git a/docs/kbase/index.rst b/docs/kbase/index.rst index 5ee3b5fce8..8e8d959e92 100644 --- a/docs/kbase/index.rst +++ b/docs/kbase/index.rst @@ -15,6 +15,9 @@ Usage `Live full disk backup `__ A walkthrough of how to take effective live full disk backups. =20 +`Merging disk image chains `__ + Ways to reduce or consolidate disk image chains. + `Virtio-FS `__ Share a filesystem between the guest and the host =20 diff --git a/docs/kbase/merging_disk_image_chains.rst b/docs/kbase/merging_= disk_image_chains.rst new file mode 100644 index 0000000000..07732c4e0d --- /dev/null +++ b/docs/kbase/merging_disk_image_chains.rst @@ -0,0 +1,197 @@ +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 + +Context +------- + +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 +------------------------------------ + +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``. + +1. Start by listing the current active disk image in use:: + + $ virsh domblklist vm1 + Target Source + ------------------------------------------------ + vda /var/lib/libvirt/images/base.raw + +2. 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 + +3. 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 + [...] + +4. Again, list the current active disk image in use:: + + $ virsh domblklist vm1 + Target Source + ------------------------------------------------ + vda /var/lib/libvirt/images/c.qcow2 + +5. 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 the entire chain into a single image +-------------------------------------------------- + +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``. + + +1. Use the same procedure discussed earlier to create the disk image + chain. + + +2. 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. + + +3. Again, check the current active block device in use:: + + $ virsh domblklist vm1 + Target Source + ------------------------------------------------ + vda /var/lib/libvirt/images/base.raw + + +4. 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. --=20 2.30.2