If you have not heard about cloud-init then you should definately search for it and learn about cloud-config as well. You can find the documentation for cloud-config here. It is used for configuring VMs when running in cloud environments. Specially useful to inject the ssh keys or set the root password but you can do anything in the cloud-config as there is a section where you can run bash commands. While this is useful for cloud instances, you can make use of this feature when running your vm with qemu or libvirtd. All you need to do is either attach a iso disc with user-data and meta-data files in it or even simpler, you can use virt-install command. The command that I use is as follows
The various parameters are
- import - import existing disk
- name - name for the vm
- memory, vcpus - memory and vcpus to use for the vm
- disk - a.qcow2 in the above command is already existing disk and it can be cloud image of any Linux OS.
- cloud-init - This defines the cloud init that you want to use. Here we are using:
- root-password-generate - generate a random password and display that
- disable - Disable cloud-init in the VM for subsequent boots
- meta-data - file with meta-data
- user-date - file with cloud-config or user-data
- network - define network to use
- os-type - Type of OS.
- graphics - spice is used for graphics display
- autoconsole - disable lauching console automatically.
- virt-type - Virtualization type to use.
- os-variant - Linux distribution you are installing.