Skip to content

Instantly share code, notes, and snippets.

@sprout42
Last active May 27, 2023 23:40
Show Gist options
  • Save sprout42/367567392caa7dd2b0a7320c4b817f45 to your computer and use it in GitHub Desktop.
Save sprout42/367567392caa7dd2b0a7320c4b817f45 to your computer and use it in GitHub Desktop.
OVA to libvirt
# example using the VM from https://practicalbinaryanalysis.com/
# Get some handy virt-manager and virtsh tools
$ sudo apt install virt-manager
# Make sure the libvirtd service is running
$ systemctl status libvirtd.service | head -13
● libvirtd.service - Virtualization daemon
Loaded: loaded (/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-03-26 13:55:54 EDT; 27min ago
Docs: man:libvirtd(8)
https://libvirt.org
Main PID: 12595 (libvirtd)
Tasks: 19 (limit: 32768)
Memory: 59.8M
CGroup: /system.slice/libvirtd.service
├─12595 /usr/sbin/libvirtd
├─12967 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
└─12968 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
# If your user was not a member of the `libvirt` group, that group will have been added. Log out and log back in.
# The default connection URI for `libvirt` tools will be set (at least in a ubuntu-based system) in the `LIBVIRT_DEFAULT_URI` environment variable.
$ echo $LIBVIRT_DEFAULT_URI
qemu:///system
$ file binary.ova
binary.ova: POSIX tar archive (GNU)
$ tar xf binary.ova
$ ls binary*
binary-disk001.vmdk binary.ova binary.ovf
# Attempting to install straigt from the OVF with `virt-convert` tried to use `/var/lib` and would have required sudo
$ virt-convert binary.ovf
... permission denied ...
# Setting `LIBVIRT_DEFAULT_URI` to `qemu:///session` instead of `qemu:///system` should help this apparently.
# I can't find a way to do this in the global configs, so set this in your .bashrc:
export LIBVIRT_DEFAULT_URI="qemu:///session"
# Now the virt-convert works:
$ virt-convert -O qcow2 binary-disk001.vmdk /home/aaron/.local/share/libvirt/images/binary-disk001.qcow2
Creating guest 'binary.ovf'.
< VM starts automatically and virt-viewer opens >
# I'd like to be able to get access to this VM without using the GUI so enable a serial terminal:
$ sudo systemctl enable serial-getty@ttyS0.service
$ sudo systemctl start serial-getty@ttyS0.service
# To start headless you can just do
$ virsh start binary.ovf
# connect to the console
$ virsh console binary.ovf
# attach to the gui if you must (this can also take the VM "ID")
$ virt-viewer -a binary.ovf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment