我正在构建一个需要从脚本动态启动 KVM guest 的软件。我希望 KVM 提供类似“AMI”的功能,以便我可以启动新的 guest ,而无需完成整个操作系统安装过程。
我读过一些有关“迁移”功能的内容,但听起来不太正确。
我真的很希望能够构建一个 guest ,对其进行镜像,然后能够一遍又一遍地克隆该镜像。
最佳答案
以防万一这个问题的答案对任何其他试图在 EC2 和 KVM 之间进行类比的人有所帮助。
使用 KVM,当您启动 guest 虚拟机时,您可以指定一个磁盘镜像文件 (guestos.img)。要与另一个 guest 重用相同的“图像”,您所要做的就是关闭原始 guest ,复制其图像(可能为了清晰起见重命名),然后启动一个指向复制图像的新 guest 。瞧!
这是一些咯咯笑的代码:
// Shutdown the image
virsh shutdown vm-name
// Copy the image
cp image-file-name.img copy-file-name.img
// Export the old XML definition file with:
virsh dumpxml vm-name > copy-vm-def.xml
// Edit the copy-vm-def.xml to point to copied image file and choose new vm name
// Then, create the new guest
virsh create copy-vm-def.xml
关于linux - EC2 AMI 的 KVM 等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9069522/