libvirt VM bundle tool#

scotty_vm_bundle.sh script will generate a tar.bz2 archive containing the kernel, the rootfs and a script to define a QEMU VM in libvirt.

Installation#

Installing scotty_vm_bundle.sh can be easily done with pip as part of the official Scotty tool bundle.

$ pip install --user avnet-scotty

upgrading an existing installation can be done with:

$ pip install --user --upgrade avnet-scotty

Dependencies#

In order for the script to work, it requires libvirt to be installed both on the machine that is used to create the bundle and on the target machine. To install dependencies you can use the following commands :

  • Ubuntu 18.04, 20.04, 21.10, 22.04, Debian 10, Debian 11
  • CentOS stream 8, stream 9, RHEL 8, 9
$ sudo apt install qemu-system libvirt-daemon-system virtinst virt-viewer
$ sudo yum install qemu-kvm libvirt virt-install virt-viewer

Setup#

To fully enable QEMU, please perform the following operations.

Add user to libvirt group:

$ sudo adduser $USER libvirt

Start default network if not already started:

$ sudo virsh net-list --all
$ sudo virsh net-start default # only if network 'default' is inactive

Grant user libvirt-qemu the right access permissions:

$ sudo setfacl -m u:libvirt-qemu:r-x ${BUILD_DIR}/tmp/deploy/images/qemux86-64

After this, a logout out of your current user session is required.

How to use#

The syntax of calling scotty_vm_bundle.sh is the following:

$ cd ${BUILD_DIR}/tmp/deploy/images/qemux86-64
$ scotty_vm_bundle.sh <vm_name> <kernel> rootfs.ext4

where <vm_name> is the name of the vm that is going to be created, <kernel> is the kernel image and rootfs.ext4 is the rootfs image produced by Yocto.

For example:

$ cd /home/$USER/build/build/tmp/deploy/images/qemux86-64
$ scotty_vm_bundle.sh my_vm \
    bzImage-qemux86-64.bin \
    simplecore-weston-demo-image-qemux86-64.ext4

Calling scotty_vm_bundle.sh will produce <vm_name>_bundle.tar.bz2 archive that contains the kernel, the rootfs and the scotty_vm_bundle.sh script.

Then, create a new folder and extract the <vm_name>_bundle.tar.bz2 archive to that folder:

$ mkdir my_vm
$ tar -xj my_vm_bundle.tar.bz2 -C ./my_vm

Go to the new folder and call scotty_vm_bundle.sh:

$ cd my_vm
$ ./scotty_vm_bundle.sh [vm_name]

The script will create a VM in libvirt. scotty_vm_bundle.sh accepts two optional arguments:

  • vm_name to override the default VM name.

The VM can then be started:

$ virsh -c qemu:///system start my_vm
$ virsh -c qemu:///system console my_vm

One can get a graphic interface (only if the VM has been created from a graphic image bundle):

$ virt-viewer -c qemu:///system my_vm

Other useful commands:

$ virsh -c qemu:///system shutdown my_vm
$ virsh -c qemu:///system reboot my_vm

To remove the bundle:

$ virsh undefine my_vm