I wanted to quickly setup a virtual machine on my laptop using VMWare Workstation and Redhat 9. I generally don’t think about that too much and do that manually (shame on me).

But now I saw a KVM guest image on the Redhat site, and I thought “Let’s use that”.

I could start it up fine (after converting the qcow format to vmdk - https://blog.ktz.me/migrate-qcow2-images-from-kvm-to-vmware/), but I can’t login to the guest afterwards.

It’s possible to set a root password using a separate tool (https://access.redhat.com/solutions/641193), but I got on another track - why not use cloud-init instead ?

Cloud-init and vmware workstation

So the kvm guest has cloud-init installed (that’s the whole point of the image). So now it’s sufficient to provide the NoCloud configuration option to the virtual machine, and we can do that in the form of a virtual cd-rom image.

Convert the qcow image to vmdk

This command converts the qcow2 format to vmdk.

qemu-img convert -f qcow2 -O vmdk rhel-baseos-9.1-x86_64-kvm.qcow2 rhel-baseos-9.1-x86_64.vmdk

Prepare cloud-init configuration

Install cloud-utils.

sudo yum install cloud-utils-growpart

Create a meta-data file

instance-id: tomsawx
local-hostname: tomsawx

Create a user-data file, with a password and a public ssh key.

#cloud-config
password: Passw0rd
chpasswd: {expire: False}
ssh_pwauth: True
ssh_authorized_keys:
 - ssh-rsa AAAAB3...8= my-user-key

You need both a user-data file and a meta-data file to have a valid cloud-init configuration !

Generate an iso image with both user-data and meta-data:

genisoimage -output seed.iso -volid cidata -joliet -rock user-data meta-data 

Create a virtual machine

Now create a new virtual machine. Select an ‘existing’ disk, and point to the Redhat KVM guest’s vmdk file you converted earlier. It’s obviously better to copy that converted vmdk file into the folder you’re putting the VMWare virtual machine in !

Then add a CD-ROM drive and select the seed.iso image you created, with the cloud-init user-data and meta-data.

It needs to end up looking something like this: VMWare workstation

Start the virtual machine up , and you’ll notice that the hostname I defined in meta-data is set:

cloud-init

You can now login with username cloud-user and the password defined in user-data.

You can also login to the system ‘remotely’ using ssh, with your ssh key. For instance:

ssh cloud-user@172.16.XX.XX

What next

Great ! So now, I can prepare a couple of configurations to go do what I set of to do (prepare Linux machines to play around with Ansible Automation Platform) !

Next, I want to preconfigure the network for these virtual machines, and I want to see if it’s possible to load the cloud-init configuration from a remote webserver…

Cloud-init and qemu

A tutorial for qemu is here:

https://cloudinit.readthedocs.io/en/latest/tutorial/qemu.html