voidlinux virtualization

This recipe is for setting virtualization on a voidlinux desktop.

Use this setup script to set things up on void linux.

Connecting to libvirtd

Note that virsh and virt-manager commands connect to different libvirtd sessions by defauult.

virsh defaults to qemu:///session while virt-manager to qemu:///system.

It is better to use qemu:///system as qemu:///session does not seem to see all available resources.

To force virsh to connect to the right session you can use commands such as:

virsh --connect qemu:///system net-list
virsh --connect qemu:///system pool-list

Create network

Set-up a bridge for internal networking using NetworkManager. See this article for reference.

Go to NetworkManager menu and use the Edit network connections applet:

  • add new bridge connection
  • give a suitable name
  • disable IPv4 and IPv6
  • everything can be left as default.

Import images

This needs to be done on CLI (as the GUI doesn't seem to allow this)

virsh --connect qemu:///system vol-create-as $pool $vol 32k --format $format
virsh --connect qemu:///system vol-upload $vol $file

For format, use raw for iso, qcow2 for actual drives.

Setup VM

Just create VM as normal.

virt-manager create Vm wizard

  1. manual install
  2. alpine linux
  3. mem: depends
  4. Create storage (4GB is enough)
  5. name. Customize configuration. Network use NAT.
  6. Add CDROM, make readonly and shareable
  7. Add Network connected to internal bridge.
  8. Add boot device.
  9. Add shared filesystem:
  • driver: virtio-9p
  • source path: /var/lib/libvirt/filesystems/shared
  • target path: /shared

Prepare system

  1. create filesystem
  • mkfs.vfat /dev/vda
  • apk add syslinux
  • syslinux /dev/vda
  1. copy media
  • mount -t vfat /dev/vda /mnt
  • cp -av /media/cdrom/. /mnt
  • edit /mnt/boot/syslinux/syslinux.cfg add: dom0_mem=1024M
  • umount /mnt
  1. remove cdrom
  • power off
  • remove cdrom
  • change boot options
  1. re-start system
  2. setup-alpine
  • enter fqdn
  • set interface eth0 to dhcp
  1. Mount shared fs:
  • mount -t 9p -o trans=virtio /shared /shared
  • fstab
  • /sharepoint /share 9p trans=virtio,version=9p2000.L,rw 0 0

Thin provisioning

Create an overlay file like so:

qemu-img create -b ubuntu-20.04-server-cloudimg-amd64-disk-kvm.img -F qcow2 -f qcow2 guest-1.qcow2