それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

qemu-img のman pages の和訳をメモ

man の適当邦訳

man の適当邦訳

スナップショットについて情報が少なく、qemu-img の邦訳がなかったので、マニュアルを読むにあたってざっと日本語を作りながら確認していました。なんかに役に立つかも知れないので、私家版の邦訳を残しておきます。

qemu-img info

info [--object OBJECTDEF] [--image-opts]  [-f  FMT]  [--out‐
put=OFMT] [--backing-chain] [-U] FILENAME

in particular to know the size reserved on disk which can be different
from the displayed size. If VM snapshots are stored in the disk image,
they are displayed too.

info コマンドで利用者に、ファイル名で指定したファイルの 情報をだします。サイズ、予約サイズとホスト上の表示サイズが異なるので、
これを使って詳細情報を調べます。スナップショットが利用されている時に、
このコマンドで得られる情報が重要になってきます。

If a disk image has a backing file chain, information
about each disk image in the chain can be recursively
enumerated by using the option --backing-chain.
For instance, if you have an image chain like:
base.qcow2 <- snap1.qcow2 <- snap2.qcow2
To enumerate information about each disk image in the
above chain, starting from top to base, do:

backing file chain 利用中イメージファイルの場合、表示情報は各ファイルごとになります。再帰的に辿られます。ただし、---backin-chain の指定が必要です。

たとえば、次のようなチェイン構造のbacking fileの場合

base.qcow2 <- snap1.qcow2 <- snap2.qcow2

上記のチェーン辿りそれぞれのディスクイメージファイルを 先頭から情報を列挙してます。

qemu-img info --backing-chain snap2.qcow2

コマンド例は上記のとおりです。

qemu-img commit

commit [-f fmt] [-t cache] filename
Commit the changes recorded in filename in its base image.

変更差分を、base-fileへ書き出して統合する。

qemu-img snapshot

snapshot [-l | -a snapshot | -c snapshot | -d snapshot ] filename
List, apply, create or delete snapshots in image filename.

snapshot
:   Is  the  name  of  the  snapshot  to create, apply or delete
  -a     Applies a snapshot (revert disk to saved state)
  -c     Creates a snapshot
  -d     Deletes a snapshot
  -l     Lists all snapshots in the given image

スナップショット(一時保存)を併合・作成・削除する、スナップショットの一覧をみる。 (メモ-a/-dあたりがよく使うところっぽい。)

qemu-img create

create [--object OBJECTDEF] [-q] [-f FMT] [-b BACKING_FILE] [-F BACKING_FMT] [-u] [-o OPTIONS] FILENAME [SIZE]

create [-f fmt] [-o options] filename [size]

Create the new disk image filename of size size and format fmt.
Depending on the file format, you can add one or more options
that enable additional features of this format.
If the option backing_file is specified, then the image will
record only the differences from backing_file. No size needs
to be specified in this case.
backing_file will never be modified unless you use
the "commit" monitor command (or qemu-img commit).

The size can also be specified using the size option
with "-o", it doesn't need to be specified separately in this case.

新規にイメージ作成。サイズとフォーマットを指定し使う。
フォーマット次第でオプションは変わる。
詳しくはフォーマット章のオプションを見ておくこと。

例えば、backing_fileを明示したなら、
createしたイメージにbacking-fileからの差分が保存される。
この利用形態であればサイズ指定は不要です。
指定したbacking-fileは更新されず、差分が保持され、貯まった差分はcommitでbaseへ統合できる。
(サブコマンドcommitを参照のこと。)

qemu-img convert

convert [--object  OBJECTDEF]  [--image-opts]  [--target-im‐
age-opts] [--target-is-zero] [--bitmaps] [-U] [-C] [-c] [-p]
[-q] [-n] [-f FMT] [-t CACHE] [-T SRC_CACHE] [-O OUTPUT_FMT]
[-B  BACKING_FILE]  [-o  OPTIONS]  [-l  SNAPSHOT_PARAM]  [-S
SPARSE_SIZE] [-r RATE_LIMIT] [-m NUM_COROUTINES] [-W]  FILE‐
NAME [FILENAME2 [...]] OUTPUT_FILENAME

Convert the disk image FILENAME or a snapshot SNAP‐
SHOT_PARAM to disk image OUTPUT_FILENAME using format
OUTPUT_FMT. It can be optionally compressed (-c op‐
tion) or use any format specific options like encryp‐
tion (-o option).

Only the formats qcow and qcow2 support compression.
The compression is read-only. It means that if a com‐
pressed sector is rewritten, then it is rewritten as
uncompressed data.

FILENAMEやSNAP‐SHOT_PARAM指定されたディスクイメージを、
OUTPUT_FILENAMEへ書き出す。OUTPUT_FILENAMEはOUTPUT_FMTに従
い記述する。出力時に、圧縮オプション(-c)や暗号化(-o) が使える。

次のqcow/qcow2フォーマットだけが圧縮を取扱可能。圧縮は読込専用になる。
これは、セクタを圧縮し上書きしたら、次に上書きするときは、通常データが
別の領域に書き込まれることを意味する

Image conversion is also useful to get smaller image
when using a growable format such as qcow: the empty
sectors are detected and suppressed from the destina‐
tion image.

convert による変換器は肥大化したイメージの容量削減に活用できる。
未利用セクタが検出されたら、出力時にカットするのである。

SPARSE_SIZE indicates the consecutive number of bytes
(defaults to 4k) that must contain only zeros for
qemu-img to create a sparse image during conversion.
If SPARSE_SIZE is 0, the source will not be scanned
for unallocated or zero sectors, and the destination
image will always be fully allocated.

SPARSE_SIZE で連続バイトの制限を指定できる。デフォルトは4k。 SPARSE_SIZE=0の場合、qemu-img 変換ででは、変換元ファイルをスキャンせずにゼロセクタの割当のためにスキャンせず、変換後ファイルではしっかり全量割り当てる。

You can use the BACKING_FILE option to force the out‐
put image to be created as a copy on write image of
the specified base image; the BACKING_FILE should
have the same content as the input's base image, how‐
ever the path, image format, etc may differ.
If a relative path name is given, the backing file is
looked up relative to the directory containing OUT‐
PUT_FILENAME.

BACKING_FILEを利用もできる。この指定でCoW(Copy on Write)を強制したイメージファイルを作成できる。BACKING_FILEは変換に使うファイルで同じ内容である必要がある。ただしパス・フォーマット(qcow2)などは異なってもいい。 BACKING_FILEに相対パス渡しの際は backing-fileはOUT‐PUT_FILENAMEのディレクトリ名からの相対パスとして扱われる。

If the -n option is specified, the target volume cre‐
ation will be skipped. This is useful for formats
such as rbd if the target volume has already been
created with site specific options that cannot be
supplied through qemu-img

-nオプションを明示なら、変換先のファイル(パス)作成はスキップされる。

このオプションでrbdフォーマットのように、変換先ファイルがすでに存在していてqemu-imgにパスをしかたなく渡さざるを得ないときなどに役立つ。

Out of order writes can be enabled with -W to improve
performance. This is only recommended for preallo‐
cated devices like host devices or other raw block
devices. Out of order write does not work in combina‐
tion with creating compressed images.

NUM_COROUTINES specifies how many coroutines work in
parallel during the convert process (defaults to 8).

NUM_COROUTINES でco-routines の本数を指定して並列化をする、デフォルト=8

qemu-img rebase

rebase [-f fmt] [-t cache] [-p] [-u] -b backing_file [-F backing_fmt] filename

Changes the backing file of an image.
Only the formats "qcow2" and "qed" support changing the backing file.
The backing file is changed to backing_file and (if the image format of
filename supports this) the backing file format is changed to backing_fmt.

There are two different modes in which "rebase" can operate:

backing file(ベースイメージ)の変更、qed/qcow2だけがこのbacking-fileをサポート。 backing fileは backing-fileに変変更されbacking_fmtに変更されます。(ファイル名がフォーマットを指定している時)

rebaseコマンドでは、次の2つのモードの操作が可能です。

Safe mode

This is the default mode and performs a real rebase operation.
The new backing file may differ from the old one and qemu-img
rebase will take care of keeping the guest-visible content of
filename unchanged.
In order to achieve this, any clusters that differ between
backing_file and the old backing file of filename are merged
into filename before actually changing the backing file.

Unsafe mode

qemu-img uses the unsafe mode if "-u" is specified.
In this mode, only the backing file name and format of filename
is changed without any checks on the file contents. The user
must take care of specifying the correct new backing file,
or the guest-visible content of the image will be corrupted.
This mode is useful for renaming or moving the backing
file to somewhere else. It can be used without an accessible
old backing file, i.e. you can use it to fix an image whose
backing file has already been moved/renamed.

セーフモード

デフォルト動作で、通常のリベースを処理します。
作成されるbacking file は元のファイルのqemu-imgリベースと違い、
仮想VM上からみたファイル名に変化がなきよう配慮されます。

この実現のため、backing_fileからの差分をもつ
すべてのイメージとbacking file のファイル名はマージされてから、
Backing file処理が走ります

Note that the safe mode is an expensive operation,
comparable to converting an image.
It only works if the old backing file still exists.

注意 セーフモードは負荷の大きい処理です。
比較、変換の処理でイメージファイルが高コストです。
また、もととなるbacking fileが現存してるときに動作可能です。

アンセーフモード

-u オプションを明示した時たとき、アンセーフモードで起動します。
backing file の名前とファイル名からフォーマットが変更されます。
このときファイルの中身などのチェックなしに処理されます。
利用者が、ファイル名について注意を払う必要があります。
このモードは名前変更(rename)をするときにとても重宝します。
また旧ファイルはすでに存在しなくなっていても動作します。
たとえば、すでに移動済みのbacking fileを参照するように参照を変更する時です。

qemu-img で使えるフォーマット

qcow2  
  QEMU  image  format, the most versatile format. Use it to  
  have smaller images (useful if your filesystem  does  not  
  supports holes, for example on Windows), optional AES en‐  
  cryption, zlib based compression and support of  multiple  
  VM snapshots.  

Supported options:

compat
:  Determines  the  qcow2 version to use. like compat=0.10

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 en‐crypted with 128-bit AES-CBC.

cluster_size
: Changes the qcow2 cluster size  (must  be  between512 and 2M).

preallocation
: Preallocation mode (allowed values: off, metadata,falloc, full).

lazy_refcounts
:   If this option is set to on, reference  count  updates  are  postponed  with  the   of avoiding metadata I/O and improving  performance.

nocow
:   If  this option is set to on, it will turn off COWof the file. 
:   It's only valid on btrfs,no  effect on other file systems.
:   #### btrfs poor permance
:   Btrfs  has low performance when hosting a VM image file, even more when the guest on the VM using btrfs as file system, also. Turning off COW is a way to mitigate this bad performance. Generally  there are two ways to turn off COW on btrfs:
````