MusicBrainz VM Server under QEMU on Arch Linux

MusicBrainz Server logo

MusicBrainz database is used by many applications such as Headphones or MusizBrainz Picard. The one major issue with the database is that the official service is slow and often unavailable while mirrors are either paid or unreliable long term. The server can be installed from scratch locally but is quite tedious which is why it is easier to run the server as a virtual machine. It is not as efficient as the entire OS will have to run in the background but it much easier to setup. Virtual Box can be used to run the VM without any changes but there is no need to run multiple Virtual Machine Managers so in this case QEMU is used.

 

Before continuing first install qemu and libvirt packages and optionally virt-manager for a GUI interface then download the latest official MusicBrainz virtual image from the ftp server or better still just grab the torrent file and download the image with your favorite BitTorrent client like uTorrent Server, Deluge or rTorrent.

 

Convert VM Image

The VM image is provided in .ova format which can not be used by QEMU directly. First the actual image needs to be extracted and then converted into a format QEMU can use.

 

Extract the downloaded VM image to the default QEMU image location.

sudo tar xvf ~/Downloads/musicbrainz-server-2015-08-06.ova -C /var/lib/libvirt/images

This will yield a .ovf and .vmdk image files. While QEMU does support VMware’s VMDK images, it does not understand the compression it uses and so it is not usable without conversion.

 

Install qemu.

sudo pacman -S qemu

 

Install optional qemu dependencies.

sudo pacman -S dmidecode dnsmasq firewalld

 

Convert the VMDK image to QCOW2 image with qemu-img utility.

sudo qemu-img convert \
-f vmdk \
-O qcow2 \
/var/lib/libvirt/images/musicbrainz-server_default-2015-08-06-disk1.vmdk \
/var/lib/libvirt/images/musicbrainz-server-2015-08-06.qcow2

 

Delete the original image files as they are no longer needed.

sudo rm /var/lib/libvirt/images/musicbrainz-server_default-2015-08-06-disk1.vmdk ~/Downloads/musicbrainz-server-2015-08-06.ova

 

Install MusicBrainz VM

Install Libvirt.

sudo pacman -S libvirt

 

Start libvirt.

sudo systemctl start libvirtd

 

Enable libvirt to start on boot.

sudo systemctl enable libvirtd

 

Import an existing image.

sudo virt-install \
--connect qemu:///system \
--name=MusicBrainz-Server \
--ram 2048 \
--vcpus=7 \
--os-type=linux \
--os-variant=ubuntu14.04 \
--disk path=/var/lib/libvirt/images/musicbrainz-server-2015-08-06.qcow2,device=disk,bus=virtio,format=qcow2 \
--vnc \
--noautoconsole \
--import

Optimisations performed --os-variant. All possible variables can be listed with osinfo-query os command.

 

List all virtual machines to confirm the image was imported.

sudo virsh list --all

 

Start the VM.

sudo virsh start MusicBrainz-Server

 

Shut down the VM.

sudo virsh shutdown MusicBrainz-Server

 

Alternatively GUI interface like virt-manager can be used to configure and manage VMs. It can be used to accomplish the same tasks with minimal pre-requisite knowledge but it does require a Desktop Environment to use..

 

Install virt-manager.

sudo pacman -S virt-manager

 

Configure MusicBrainz Server

To get access to the database an account is required. It is free to Sign-up for non-commercial use. Create an account and generate an access token. Once done, login to the VM with vm username and musicbrainz password.

 

Find the assigned IP address.

ip addr show

With the IP address acquired, SSH can be used to manage the VM from this point on.

 

Login to the VM server via SSH.

ssh vm@192.168.122.132 -p 22

 

Open the configuration file.

sudo nano /home/musicbrainz/musicbrainz-server/lib/DBDefs.pm

Search for sub REPLICATION_ACCESS_TOKEN { "" } line, insert the generated access token between the double quotes and save the file.

 

Start the initial replication.

bin/replicate now

This can cake a very long time which is why it is a good idea to allocate as many cores to the VM as possible during initial setup. Expect several hours before the command completes even on a fast machine.

 

Build the search indexes.

bin/reindex

 

Enable background replication.

bin/replicate start

 

Access MusicBrainz Server

Access the web interface on 192.168.0.100:8181 and test by searching for an artist or album. Change 192.168.0.100 to the actual IP address if different. Leave the default port as 5000 unless it has been changed manually.

 

MusicBrainz VM Server needs to run on the same physical machine or withing a guest on that same machine as the application that is accessing it. Attempting to query the server from the network results in a Attempt to query MusicBrainz for wham failed (caused by: ) error in Headphones and a Connection timed out (QT code 99, HTTP code None) error in Picard. This is due to the fact that NAT networking allows outgoing connections from the guests but incoming connections are only allowed from within the same physical machine. This can be overcome with a hook script that forwards incoming traffic on defined ports to the VMs defined in said script however it is beyond the scope of this article.

dom