سؤال

I'm building a piece of software that needs to spin up KVM guests dynamically from a script. I'm hoping that KVM offers an 'AMI' like functionality so that I can spin up new guests without having to go through the entire OS install process.

I've read a little about the 'migrate' functionality but its doesn't sound quite right.

I would really like to be able to build up a guest, image it, and then be able to spin up clones of that image over and over.

هل كانت مفيدة؟

المحلول

Just in case the answer to this can be helpful to anyone else who is trying to create analogies between EC2 and KVM here you go.

With KVM, when you start up a guest you specify a disk image file (guestos.img). To reuse that same "image" with another guest all you have to do is shutdown the original guest, copy it's image (and probably rename for clarity's sake) and then start a new guest that points to the copied image. Voila!

Here's some code for giggles:

// 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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top