例如:
root@f42-vm:~# qemu-img create -f raw disk.raw 1G
Formatting 'disk.raw', fmt=raw size=1073741824
root@f42-vm:~#
root@f42-vm:~# ls -ls disk.raw
4 -rw-r--r-- 1 root root 1073741824 Oct 14 11:01 disk.raw
root@f42-vm:~#
root@f42-vm:~# qemu-img info --output=json disk.raw | jq
{
"children": [
{
"name": "file",
"info": {
"children": [],
"virtual-size": 1073741824,
"filename": "disk.raw",
"format": "file",
"actual-size": 4096,
"format-specific": {
"type": "file",
"data": {}
},
"dirty-flag": false
}
}
],
"virtual-size": 1073741824,
"filename": "disk.raw",
"format": "raw",
"actual-size": 4096,
"dirty-flag": false
}
root@f42-vm:~#
我觉得既然创建的磁盘文件是稀疏文件,那应该可以不用 0 填充前 4KB ,找了半天没找到原因,希望有兴趣的 v 友能一起研究一下。