qemu-img convert轉換磁盤格式


老規矩,man 查看 qemu-img convert相關選項,如下:

 簡單翻譯如下:

convert [-c] [-p] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-B backing_file] [-o options] [-s snapshot_id_or_name] [-l snapshot_param] [-m num_coroutines] [-W] [-S sparse_size] filename [filename2 [...]] output_filename

Convert the disk image filename or a snapshot snapshot_param(snapshot_id_or_name is deprecated) to disk image output_filename using format output_fmt. It can be optionally compressed ("-c" option) or use any format specific options like encryption ("-o" option).

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

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 destination image.

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.

You can use the backing_file option to force the output 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, however 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
output_filename.

If the "-n" option is specified, the target volume creation 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.

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

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

convert動作是將filename(可以同時指定多個)的disk image,或者snapshot snapshot_param(snapshot_id_or_name選項被遺棄)轉換為output_filename,照這個意思,就是可以將多個input disk image合並為一個ouput disk image,可以配合使用-c 壓縮選項或者-o 加密選項,當然加密選項需要特定的文件格式支持。

只有qcow和qcow2支持壓縮,並且壓縮是只讀的,也就是說當一個壓縮的扇區重寫,那么該重寫扇區就會變為非壓縮數據
convert實際也可以用於壓縮disk image大小,比如使用可增長式 格式qcow,,空扇區會被探測並壓縮到目標disk image

SPARSE_SIZE表示轉換期間qemu-img創建稀疏映像時必須僅包含零的連續字節數(默認值為4k)。如果稀疏大小為0,則不會掃描源是否有未分配的扇區或零個扇區,而目標映像將始終完全分配。

可以使用-B 參數來創建基於input disk image(base file)的out disk image
使用-B backing_file選項來指定后端鏡像,讓生成的文件是copy-on-write的增量文件,這時必須讓轉換命令中指定的后端鏡像與輸入文件的后端鏡像的內容是相同的,盡管它們各自后端鏡像的目錄、格式可能不同。

 

相對路徑??

-n參數如果存在,那么target 卷創建將會跳過,這在創建rbd格式轉換時有用

-W表示亂序寫,可以提高性能,推薦在主機host device或者raw block device中使用,注意亂序寫不能和compressed壓縮同時使用

-m num_coroutines 指定多進程協同處理convert轉換,默認為8

 -f表示輸入disk image的格式

-O 表示輸出disk image的格式

 

根據man qemu-img中最后內容提示,支持的文件類型有:除了raw qcow2,還有以下格式:

 

 格式說明:vmdk  ,vdi vhd,vhdx 大家想必很熟悉了,raw是通用格式,qcow2是qemu主推的格式,qemu推薦使用raw和qcow2以獲取更好的performance

 

留坑:-B參數如何使用???


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM