I'm slowly working on getting libvirt more functional on FreeBSD and, thanks to help of a lot of other people who did very valuable reviews of my patches and contributed other portability fixes, at this point libvirt on FreeBSD is capable of running Qemu VMs with some limitations. I'll provide a quick howto on doing that and what limitations exist at this point.
Building libvirt
As I'm playing with the codebase, it's more convenient for me to use direct git checkout instead of port. I'll provide an instuction how to build it (port should work as well, but I haven't tested).
Configure command looks this way:
CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" ./configure \ --without-polkit \ --disable-werror
CFLAGS and LDFLAGS are needed to help it find yajl includes and libs. We're disabling polkit because we don't want to waste extra time configuring it and we disable treating warnings as errors because some third party libs' headers could mess things up.
When it configures successfully, it's traditional gmake && gmake install.
Preparing a VM
Nothing special about VM preparation, just create a Qemu VM like you usually do, configure it for you needs and you're almost ready to go.
There are some things recommended to do though:
- Make virtio stuff available (see vtnet(4), virtio_balloon(4), virtio_blk(4) for details) on your guest
- Configure network interface to using DHCP by adding this line to /etc/rc.conf: ifconfig_vtnet0="DHCP"
Defining and running a domain
Before running up libvirtd, make sure you have bridge(4) and tap(4) modules loaded or built into kernel.
Then you need to execute libvirtd and then connect to it using virsh:
virsh -c "qemu:///system"Now, we need to create an XML file with domain definition. Here's the one I use: https://gist.github.com/novel/7399465
You might notice we're using virtio for network device and for the disk drive. You'll have to modify a path to the image location and adjust mem/cpu amount for your needs.
Once you're done with that, execute 'define /path/to/domain.xml' in virsh, and domain with name 'qemu' (unless you changed it) will be created. You can start it using 'start qemu' command in virsh.
To see what's going on, we could use vnc. To figure out what vnc port our VM is available at, we need to execute 'vncdisplay qemu' and it should print something like:
127.0.0.1:0
Now we can connect using vnc client, for example, if you use net/vnc, the proper command will be:
vncviewer 127.0.0.1:0
If everything goes well, you'll get an access to your VM's console.
Run ifconfig to check if there's an IP address on vtnet0 interface:
vtnet0: flags=8843metric 0 mtu 1500 options=80028 ether 52:54:00:ae:4c:37 inet 192.168.122.117 netmask 0xffffff00 broadcast 192.168.122.255 media: Ethernet 1000baseT status: active
And on the host you'll have:
- bridge(4) device virbr0
- tap(4) device vnet0 which corresponds to our VM and is member of virbr0 bridge
It's possible to connect from guest to host and vice versa. Unfortunately, it's not possible to provide access to the internet for VM without manual configuration. Normally, libvirt should do that, but its bridge driver needs some work to do that on FreeBSD, and that's on my todo list.
Apart from bridge stuff, there are a lot of other limitations on FreeBSD currently, but firewalling for bridge driver and nwfilter are probably the most important now. It's not quite easy to come up with a good way to implement it. For example, one has to choose what firewall package to use, pf and ipfw being the main candidates for that.
I'll cover my thoughts and concerns in a separate post.
Feel free to poke me if you have any questions/thoughts.
Update 25/01/2014: some people have troubles because of the old qemu version. On FreeBSD, please use qemu-devel port, because qemu port is too old.
Error starting domain: Operation not supported: JSON monitor is required---- I am getting this error while starting VM on qemu.. please help..
ReplyDeleteThanxxx