Qemu : Snapshot

Qemu : Version 6.2.0

Liens :
https://techpiezo.com/linux/use-and-implementation-of-backing-file-and-snapshot-in-qemu-kvm/
https://www.unixmen.com/qemu-kvm-using-copy-write-mode/

1/ Création de l'image de base.

$ qemu-img create -f qcow2 vda.qcow2 10G
Formatting 'vda.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=10737418240 lazy_refcounts=off refcount_bits=16

2/ Premier démarrage de l'image pour commencer l'installation de Lubuntu 20.04.

$ qemu-system-x86_64 -enable-kvm -m 2048 -display sdl  -vga std -hda vda.qcow2 -cdrom lubuntu-20.04.3-desktop-amd64.iso -boot d -net nic,model=rtl8139 -net user -smp 2 

3/ Lancement de l'image.

$ qemu-system-x86_64 -enable-kvm -m 2048 -display sdl  -vga std -hda vda.qcow2 -smp 2 -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp::10022-:22 

4/ Information sur l'image de base propre, sans aucune mise-à-jour ou installation de logiciel.

$ qemu-img info vda.qcow2
image: vda.qcow2
file format: qcow2
virtual size: 10 GiB (10737418240 bytes)
disk size: 5.76 GiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false

5/ Créer une image de vda.qcow2 comme une image de sauvegarde (backing) et créer un instantané (snapshot)/superposition (overlay) nommé 'instantane.qcow2'.

$ qemu-img create -f qcow2 -F qcow2 -b vda.qcow2 instantane.qcow2
Formatting 'instantane.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off compression_type=zlib size=10737418240 backing_file=vda.qcow2 backing_fmt=qcow2 lazy_refcounts=off refcount_bits=16

Les changements seront uniquement sur cette image.

$ ls -lh *.qcow2
-rw-r--r-- 1 util01 util01 193K janv. 21 21:27 instantane.qcow2
-rw-r--r-- 1 util01 util01 5,8G janv. 21 21:10 vda.qcow2

L'instantané est maintenant utilisable comme image de démarrage :

$ qemu-system-x86_64 -enable-kvm -m 2048 -display sdl  -vga std -hda instantane.qcow2 -smp 2 -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp::10022-:22

6/ Information sur l'instantané.

$ qemu-img info instantane.qcow2
image: instantane.qcow2
file format: qcow2
virtual size: 10 GiB (10737418240 bytes)
disk size: 3.86 GiB
cluster_size: 65536
backing file: vda.qcow2
backing file format: qcow2
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false
$ ls -lh *.qcow2
-rw-r--r-- 1 util01 util01 3,9G janv. 21 22:01 instantane.qcow2
-rw-r--r-- 1 util01 util01 5,8G janv. 21 21:10 vda.qcow2

7/ Information sur l'image de base/référence et de l'instantané.

$ qemu-img info --backing-chain instantane.qcow2
image: instantane.qcow2
file format: qcow2
virtual size: 10 GiB (10737418240 bytes)
disk size: 3.86 GiB
cluster_size: 65536
backing file: vda.qcow2
backing file format: qcow2
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false

image: vda.qcow2
file format: qcow2
virtual size: 10 GiB (10737418240 bytes)
disk size: 5.76 GiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false

8/ Appliquer l'instantané sur l'image de sauvegarde.

  • Rebase :
$ qemu-img rebase -F qcow2 -b vda.qcow2 instantane.qcow2
  • Commit :
    $ qemu-img commit instantane.qcow2
    Image committed.

L'image 'vda.qcow2' est de nouveau utilisable comme image de démarrage.

$ ls -l vda.qcow2 
-rw-r--r-- 1 util01 util01 9397993472 janv. 21 22:06 vda.qcow2