Rocky 9, recover kernel virtual machines

With a clean install of Rocky 9, I lost the xml definitions of my vm guests, which were buried in the old o/s partition. I do have the qcow2 files, and the original commands that I used to create them.

I have installed “libvirt” on Rocky 9, noting that it now uses socket activated “modular” daemons.

I’m about to re-create the storage pools, but I don’t know how to recover the vm guests from the qcow2 files?

No backup?

A VM is essentially this many cores and ram, these devices and that storage. People do spawn new (different) instances with snapshot of old volume, so the specs of the VM are not tightly coupled with the qcow content. (Disclaimer: I’ve never used qcow knowingly; always raw.)

What can go wrong is not to give the things that the installed OS in the guest image does expect.
For example, you have Rocky 9 guest, which requires x86_64-v2 CPU features, and define new VM to not pass those to guest. That would fail.
Or, you had specific MAC addresses on network interfaces and VM’s network config fails without them.

I would presume that there is a way to loop-mount the qcow2 image on the host. (One definitely can do that with raw volumes.) Then you can read the config and logs of the guest.

The backups were in line with previous clean o/s installs, but I only started using vm guests since Rocky 8.x, and completely overlooked the need to backup the xml files. I’d placed the qcow2 files on separate storage thinking the vm guests were “backed up”. I try to treat the o/s partition as “throw away”.

The vm guests are just vanilla Rocky 8.6 vms, using default network.

Right now, I don’t know how to “bring them back” into libvirt.

If you had virt-manager installed you just click through using an existing disk image and it will create a basic vm config with whatever hardware is there by default. It is pretty straightforward using virt-manager.

For future the xml files are under /etc/libvirt/qemu so you can back them up by taking copies or use the virsh console command to dumpxml for all your vms.

Just create a new vm using the existing disk. ‘virt-install --os-variant list’ will list all the available os-variants.

OK, it’s working again.
Here’s what I did (based on the help in this forum post).

  1. Run the original virt-install command, but as a dry-run, this shows the original xml that was used to create the vm guest, and can be compared with the xml that will be created when resurrecting the vm guest.
virt-install --dry-run --print-xml --name vmg01 --memory 2048 --vcpus 2 --disk pool=vmg_pool,size=10 --disk pool=vmg_pool,size=10 --os-variant rocky8.5 --boot uefi --cdrom /vms/iso/Rocky-8.5-x86_64-dvd1.iso
  1. Resurrect the vm guest that currently only exists in qcow2. In this case, I have re-created the original storage pool exactly as before, so I’m using the ‘vol’ option instead of the ‘path’ option.
virt-install --name vmg01 --memory 2048 --vcpus 2 --import --disk vol=vmg_pool/vmg01.qcow2,bus=virtio --disk vol=vmg_pool/vmg01-1.qcow2,bus=virtio --os-variant rocky8.5 --boot uefi

Note the use of --import and the args passed to --disk

Running the virt-install command suddenly started the virt-viewer and booted the machine, I didn’t expect that, I thought it would just create the vm guest definition. I didn’t know how to shut it down using virt-viewer, so I used systemd.

At this point, I can start and stop the vm guest, and use it.

virsh start vmg01
virsh shutdown vmg01

But, ssh and ping by host wasn’t working, so I had to set up ‘libvirt-nss.x86_64’, but there was an UNEXPECTED issue here when I ran ‘authselect’, the whole screen went black, all my open windows were lost and I had to log in again. This didn’t happen on Rocky 8.6.

After logging back in, the vm guests are working again.

I can make a backup of the xml, but I’m not sure the correct procedure, or where to restore it to, just copy back into ‘libvirt’ and hope it works, or some special command?

From where to where? I don’t see anything about network interfaces on your virt-install lines.

Libvirt can create virtual networks. (The “default” is included in the packages.) Their XML definitions are in ‘/etc/libvirt/qemu/networks/’.
If you have custom networks, then you want a backup of those too.

Libvirt does read the XML from those directories on service start, so restoring files from backup and restart/reboot should suffice.

Regarding the network, I’m using the “default” network, as mentioned in my post of Aug 07, 2022 2:55pm. I didn’t put it on the command line, becuase I think it’s automatic provided it’s configured.

virsh net-list --all
 Name      State    Autostart   Persistent
 default   active   yes         yes

It’s “normal” for ping by host to not work for vm host to vm guests, so RHEL docs mention using ‘libvirt-nss.x86_64’. When I say “normal” I mean it was the same on Rocky 8.5, and is still the same on Rocky 9.0.

Regarding backing up the xml I see two files


Not sure what’s happening with ‘authselect’, it used to activate after reboot, now it wrecks your logged in session and forces a new login (or something like that).