2011年8月28日日曜日

KVM qcow2 メモ


このエントリーをはてなブックマークに追加


使い方のメモ

試したバージョン
# qemu-img -h
qemu-img version 0.14.0, Copyright (c) 2004-2008 Fabrice Bellard
usage: qemu-img command [command options]
QEMU disk image utility


イメージの作成
# qemu-img create -f qcow2 -o options filename size

filenameで指定された名前で、sizeで指定された容量のqcow2イメージを作成する。

未使用状態では数MBで、OSからからの使用量に合わせて徐々に拡張される。

-o options で指定できるオプションは以下、
"backing_file"
File name of a base image (see create subcommand)

"backing_fmt"
Image format of the base image

"encryption"
If this option is set to "on", the image is encrypted.

Encryption uses the AES format which is very secure (128 bit
keys). Use a long password (16 characters) to get maximum
protection.

"cluster_size"
Changes the qcow2 cluster size (must be between 512 and 2M).
Smaller cluster sizes can improve the image file size whereas
larger cluster sizes generally provide better performance.

"preallocation"
Preallocation mode (allowed values: off, metadata). An image
with preallocated metadata is initially larger but can improve
performance when the image needs to grow.


スナップショット

作成
# qemu-img snapshot -c snapname qcow2_image_file

一覧
# qemu-img snapshot -l qcow2_image_file

削除
# qemu-img snapshot -d snapname qcow2_image_file

スナップショットの時点へ復元する
# qemu-img snapshot -a snapname qcow2_image_file

スナップショットは仮想マシン稼働中にも取得できるが、仮想OS上でファイルシステムを同期してSyncする方法がないので止めてから取得するのが確実。


リサイズ

拡張するサイズを指定してやる。-も指定できるが使わないほうがよい。
# qemu-img resize disk.qcow2 +100M


※snapshotが存在するイメージはサイズ変更不可。
# qemu-img create -f qcow2 test.qcow2 100M
Formatting 'test.qcow2', fmt=qcow2 size=104857600 encryption=off cluster_size=0

# qemu-img info test.qcow2
image: test.qcow2
file format: qcow2
virtual size: 100M (104857600 bytes)
disk size: 136K
cluster_size: 65536

# qemu-img resize test.qcow2 +50M
Image resized.

# qemu-img info test.qcow2
image: test.qcow2
file format: qcow2
virtual size: 150M (157286400 bytes)
disk size: 136K
cluster_size: 65536

# qemu-img snapshot -c s1 test.qcow2

# qemu-img info test.qcow2
image: test.qcow2
file format: qcow2
virtual size: 150M (157286400 bytes)
disk size: 144K
cluster_size: 65536
Snapshot list:
ID TAG VM SIZE DATE VM CLOCK
1 s1 0 2011-08-28 00:07:52 00:00:00.000

# qemu-img resize test.qcow2 +50M
qemu-img: This image format does not support resize

# qemu-img snapshot -d s1 test.qcow2

# qemu-img resize test.qcow2 +50M
Image resized.

# qemu-img info test.qcow2
image: test.qcow2
file format: qcow2
virtual size: 200M (209715200 bytes)
disk size: 144K
cluster_size: 65536

0 件のコメント:

コメントを投稿