Linux

如何創建非精簡配置的 qcow2 文件?

  • February 1, 2019

當我執行以下操作時,qcow2 文件小於 200KB。

# qemu-img create -f qcow2 /var/lib/libvirt/images/urb-dat0.qcow2 10G
# du -hsc /var/lib/libvirt/images/urb-dat0.qcow2
196K    /var/lib/libvirt/images/urb-dat0.qcow2

如果我將它附加到 KVM 來賓並且fdisk -l

Disk /dev/vdb: 0 MB, 197120 bytes, 385 sectors

問題

如何製作非精簡配置的 10GB qcow2 文件?

您可以使用該preallocation選項。

qemu-img create -o preallocation=full -f qcow2 /var/lib/libvirt/images/urb-dat0.qcow2 10G

參考:https ://linux.die.net/man/1/qemu-img

預分配模式(允許的值:關閉、元數據、完整)。具有預分配元數據的圖像最初較大,但在圖像需要增長時可以提高性能。完全預分配還向整個圖像寫入零,以便也預分配較低層(例如包含圖像文件的文件系統)。請注意,完整的預分配寫入虛擬磁碟的每個字節,因此對於大圖像可能需要很長時間。

引用自:https://serverfault.com/questions/841031