我将邀请一位嘉宾:
qemu-system-x86-64 \
-nographic \
-machine virt \
-smp 2 \
-m 4G \
-bios images/fw_jump.elf \
-kernel images/Image \
-append "root=/dev/vda2 ro" \
-device virtio-blk-device,drive=hd0 -drive file=Fedora-38-sda.qcow2,format=qcow2,id=hd0 \
-netdev user,id=net0,hostfwd=tcp::10000-:22 -device virtio-net-device,netdev=net0 \
-device virtio-net-device,netdev=e0 -netdev tap,id=e0 \
-virtfs local,path=mount/development-toolchain-native,mount_tag=host0,security_model=passthrough,id=host0 \
-virtfs local,path=mount/development-2023-07-13-1400,mount_tag=host1,security_model=passthrough,id=host1
我想同时启动更多这样的实例以创建集群。为了让虚拟机独立运行,我应该复制什么?
每个虚拟机都需要一个独立的磁盘。最简单的解决方案是为每个使用原始磁盘作为后备存储的虚拟机创建一个新的 qcow2 映像:
for node in {1..10}; do
drive=node${node}.qcow2
qemu-img create -f qcow2 -F qcow2 -b Fedora-38-sda.qcow2 $drive 10G
qemu-system-x86-64 \
-nographic \
-machine virt \
-smp 2 \
-m 4G \
-bios images/fw_jump.elf \
-kernel images/Image \
-append "root=/dev/vda2 ro" \
-device virtio-blk-device,drive=hd0 -drive file=$drive,format=qcow2,id=hd0 \
-netdev user,id=net0,hostfwd=tcp::10000-:22 -device virtio-net-device,netdev=net0 \
-device virtio-net-device,netdev=e0 -netdev tap,id=e0 \
-virtfs local,path=mount/development-toolchain-native,mount_tag=host0,security_model=passthrough,id=host0 \
-virtfs local,path=mount/development-2023-07-13-1400,mount_tag=host1,security_model=passthrough,id=host1
done