为什么 NBD 要嵌套 NBD?qcow2 镜像链解析原理

创建 NBD 镜像时,为什么要把 backing 的所有镜像全部设置为 NBD? 因为镜像链的解析是 qemu driver 负责的,NBD 和本地 file 都只是独立的块设备,没有解析能力。 现象 创建 NBD 镜像时报错: cmd [qemu-img create -f qcow2 -b nbd://10.0.0.10:54195 -F qcow2 /dev/qbd/vol/vol-example.img] on [local] failed: ret[1] out[] err[qemu-img: /dev/qbd/vol/vol-example.img: Could not open backing file: Could not open '/data/image/centos79x64a': No such file or directory Could not open backing image.]. exec_time is [0.093]s 怪不得创建 NBD 镜像的时候,会把 backing 的所有镜像全部设置为 NBD。之前很费解。 有一个误区 以为通过 NBD 找到 nbd://10.0.0.10:54195 head 镜像,那么 NBD 镜像的 backing 镜像,自然通过 NBD head 链接一起使用了。 ...

July 18, 2026 · 2 min · 223 words · 文叨叨

qemu-img commit 的链为什么必须完整?-d 参数又是什么

qemu-img commit 的链必须是完整的,虽然 commit 的是 head,看起来和底层几级镜像没关系,但实际还是需要。commit 链的关系还可以是临时的,-d 参数决定 commit 后是否清空文件。 现象 qemu-img commit 的链,必须是完整的。 虽然你 commit 的是 head,看起来和底层几级的镜像没有关系,但实际还是需要的: root@host:~/tmp# qemu-img commit -f qcow2 /root/tmp/vm-example_tmp.img qemu-img: Could not open '/root/tmp/vm-example_tmp.img': Could not open backing file: Could not open backing file: Could not open '/root/tmp/focal1x64a': No such file or directory 排查 commit 链的关系还可以是临时的 下面命令不会改变 /dev/vg2/vm-example_lss-sjjgi703 的 backing file,但是确可以提交数据到其他链上,非常方便: qemu-img commit --image-opts file.filename=/dev/vg2/vm-example_lss-sjjgi703,backing.file.filename=/root/tmp/vm-example.img 底层链有 nbd 镜像也会失败 如果底层的链中有 nbd 镜像,那么即便 commit 没到 nbd img,也会失败: 2024-12-09 18:08:26,809 INFO -139636383823616- commit_snap command is [qemu-img commit -f qcow2 -d /data/container/vm-example/vm-example.resize_tmp.img] ret is [(1, '', u"qemu-img: Block format 'nbd' used by node '#block817' does not support reopening files")] 如果底层的链中有 nbd 镜像,那么即便 commit 没到 nbd img,也会失败。 ...

January 18, 2026 · 2 min · 224 words · 文叨叨