Debugging a failing OpenStack image
On my alpine-openstack-vm project, There is a CI process producing a VM image for OpenStack. The process involves testing that the machine boots. The test fails, but the machine is actually booted. What doesn’t work is the ssh access. As the machine can only be reached via SSH with a private key for obvious security reasons, not having access prevents proper debug.
The objective is to be able to run the produced VM locally to assess the issue. As the image in its current form doesn’t work, the VM image needs to be slightly modified in order to allow access. If the VM is run locally, adding a root password should be sufficient.
- Windows 11
- Hyper-V. Information on installation is here. If you are using WSL, you should already be set up or really close.
- A Windows Subsystem for Linux (WSL) distribution with
qemu-imginstalled. You can set it up faster with Powershell-WSL-Manager.
We need to download your Openstack image locally. Hopefully, it is kept as an artifact of our build.
We are going to convert the image from the
qcow2 format to the
vhdx in order
to be able to use it as the base disk of an Hyper-V VM. This will also allow us
to mount it inside a WSL distribution to modify it.
This is done with the
Mounting the image
Now we can mount the image in WSL:
Chrooting inside the image
We can now chroot inside the image to modify it:
Allowing access to the image
We set a root password in order to be able to login in our VM:
/etc/ssh/sshd_config, we enable root login and password authentication:
/etc/cloud/cloud.cfg, we allow ssh password authentication:
At this point, you can also add a
/root/.ssh/authorized_keys file containing a
public key for ssh authenticiation.
Then you can exit the chroot with the
Unmounting the image
From windows, type:
Creating the Hyper-V VM
To be able to create Hyper-V VMs from the command line, your user needs to be part of the
Hyper-V Administrators group. You can add your user to this group with the command line:
Unfortunately, you will also need to restart your machine 😞
Create and start the VM from the command line:
-Generation 1here in order to avoid UEFI initialization.
Now you can connect to the VM:
And you should be able to see the VM window:
The actual issue appears clearly in the image above. You should be able to connect as root with the password you entered before:
And look at the issues that created the error.
You can also connect with ssh. To find the IP address of the machine, you can type the following command on Powershell:
Here the address of the machine would be the second one, the one marked with Permanet. You can connect to it:
On the terminal window as well as with ssh, you are now able to find the issue with your image.
Once the reason of the issue is found, you can delete the VM:
The above procedure is interesting not only for debugging non working images but also to run any image as long as the image format can be handled by qemu. Having WSL at hand is also handy to mount and hack the image.