Thursday, March 21, 2013

qemu control script


Since i've played with +QEMU i always searched for an easy way to create or modify my guest. Start or stopping them was easy with my init script, but creating new one always involved many steps. Even though it isn't complicated i wanted something simpler.


So i've started to write an new script and called it qemu control or simple qc. Over the time it got more and more features and now i though maybe someone else could be interested, especially in case someone uses my init script.
In the last days i've cleaned up the init script to make it more readable. Now it shouldn't be to difficult to get into the code, however i'll gonna show how it's used.



Usage:

First of all, what can you do with it? Since my vm's are all on lvm partitions, qc works only with lvm partitions. It can create new vm's, copy exiting one, delete, modify configs, convert to qcow2 and compress vm's. More on every single feature below.
For every new guest it also creates default init scripts (based on my own one), while it also removes it when deleting a vm.
Everything (except deleting) can be done even when a vm is running, because the script always creates snapshots of the given vm.


Features:

 ./qc copy  
Copies an exiting vm (even when running) including their init script config, but changes its setting to suit the new vm. It also changes the vm host name (if possible) to the given name.

 ./qc new  
Creates an new empty lvm partition for an vm, including an changed default config which suit the vm. This doesn't install the guest os.

 ./qc edit   
Edit an exiting configuration file (based on my own init script) of an qemu guest.

 ./qc del  
Deletes a vm, including their init script config.

 ./qc convert [path]  
Converts a exiting lvm partition to a qcow2 file. It's also possible to directly compress it afterwards. You can also add an default path.

 ./qc compress [path]  
Only compresses a lvm partition into a gz file (like for backups). You can also add an default path.

Default init script and config can be set in the script. Also things like default logical volume name, snapshot size and image size can be set in the script. Logical volume name and path must be set anyway.

Note: I'm usually using pigz to compress the vms since it's much faster on multicore systems. If you don't have it you can either change it to gzip or simple install pigz (its in portage).


Download:

The script is a work in progress and it's probably still in a bad shape, however for those who are interested, you can download the script on github. The link is: https://github.com/mm1ke/qc

No comments:

Post a Comment