R&D/Hypervisor

Create QCOW2 Image

sunshout 2014. 5. 20. 23:37

QCOW2(QEMU Copy On Write) format disk 


1. QCOW2 Creation


1. Create Base Image with 10G size disk

qemu-img create -f qcow2 base.img 10G


2. Create Root Image which using base.img

qemu-img create -b base.img -f qcow2 root.img





qemu-img info shows the chaining information of root.img

sunshout@ubuntu-vm:/storage$ qemu-img info root.img

image: root.img

file format: qcow2

virtual size: 10G (10737418240 bytes)

disk size: 196K

cluster_size: 65536

backing file: base.img

Format specific information:

    compat: 1.1

    lazy refcounts: false

sunshout@ubuntu-vm:/storage$



2. QCOW2 Rebase image

- Changing base.img to another base image.

- For example, change root file system with new update fetch.



* Create new base image

qemu-img create -f qcow2 new_base.img 10G


* rebase backing image of root.img

qemu-im rebase -f qcow2 -u -F qcow2 -b new_base.img root.img

 options:

 -f : backing file's format

-F : root disk's file format

-b : new backing file's path

-u : unsafe mode (does not check similarity of base image and new base image)


sunshout@ubuntu-vm:/storage$ qemu-img create -f qcow2 new_base.img 10G

Formatting 'new_base.img', fmt=qcow2 size=10737418240 encryption=off cluster_size=65536 lazy_refcounts=off

sunshout@ubuntu-vm:/storage$ qemu-img rebase -u -f qcow2 -F qcow2 -b new_base.img root.img

sunshout@ubuntu-vm:/storage$ qemu-img info root.img

image: root.img

file format: qcow2

virtual size: 10G (10737418240 bytes)

disk size: 196K

cluster_size: 65536

backing file: new_base.img

backing file format: qcow2

Format specific information:

    compat: 1.1

    lazy refcounts: false

sunshout@ubuntu-vm:/storage$



- My development git : https://github.com/choonho/qemu-rebase.git


rebase.diff