Hosts/BSD
QEMU on BSD hosts
This documentation is not written by a BSD expert - corrections welcome!
QEMU can be built on BSD hosts. At the moment most QEMU developers are Linux users, though, so BSD is not very well supported.
This page includes documentation of how to get the various BSD flavours running in a VM inside QEMU, so that Linux-based developers can do build tests on them. If you're running natively on BSD you can ignore the "VM setup" instructions.
FreeBSD
VM setup
Download and uncompress the official FreeBSD qcow2 image from
https://download.freebsd.org/ftp/releases/VM-IMAGES/11.0-RELEASE/amd64/Latest/
Run the image with:
qemu-system-x86_64 -m 2048 \ -hda FreeBSD-11.0-RELEASE-amd64.qcow2 -enable-kvm \ -netdev user,id=mynet0,hostfwd=tcp:127.0.0.1:7722-:22 \ -device e1000,netdev=mynet0
(TODO: check virtio works and recommend that instead.)
Enable networking and ssh by adding these lines to /etc/rc.conf:
sshd_enable="YES" ifconfig_em0="DHCP"
Edit /etc/ssh/sshd_config to add
PermitRootLogin prohibit-password
and then reboot the VM or run
service netif restart service sshd start
Copy your ssh public key into the VM's /root/.ssh/authorized_keys
You should now be able to ssh into the VM from outside with
ssh -p 7722 root@localhost
Required packages
Install enough packages to do builds:
pkg update pkg install git pkg install gcc pkg install gmake pkg install python pkg install pkgconf pkg install pixman pkg install bison pkg install glib
TODO: suggest some not-required-but-recommended packages?
Building
You can configure and build QEMU as you would on Linux:
mkdir build cd build ../configure gmake gmake check
Note that you need to use 'gmake', not plain 'make'.
(NB as of 2017-03-20 you'll also need --disable-user to work around a QEMU bug.)
OpenBSD
VM setup
Get installer, create disk:
qemu-img create -f qcow2 disk.qcow2 15G wget https://www.mirrorservice.org/pub/OpenBSD/6.0/amd64/cd60.iso
Run installer:
qemu-system-x86_64 -m 2048 -hda disk.qcow2 \ -cdrom cd60.iso -enable-kvm \ -netdev user,id=mynet0,hostfwd=tcp:127.0.0.1:7922-:22 \ -device e1000,netdev=mynet0 -smp 2
Follow the straightforward install prompts (accepting defaults generally OK). You'll want to enable sshd and allow logins with prohibit-password.
NB: it's important to run the installer with more than one CPU, or it will not install the SMP kernel and you won't be able to run the resulting system with multiple CPUs.
Reboot when it asks, and when it's rebooted kill the QEMU VM.
Now run the VM on the installed image:
qemu-system-x86_64 -m 2048 \ -drive if=virtio,file=disk.qcow2,format=qcow2 \ -enable-kvm \ -netdev user,id=mynet0,hostfwd=tcp:127.0.0.1:7922-:22 \ -device e1000,netdev=mynet0
Copy your ssh public key into root's .ssh/authorized_keys
You should now be able to get in to the VM with
ssh -p 7922 root@localhost
Make sure that the filesystem you're building and running QEMU from has the "wxallowed" option set in /etc/fstab, like:
d3651b0622794af6.k /home ffs rw,wxallowed,nodev,nosuid 1 2
then either reboot or use "mount -uo wxallowed /wherever" to set it for this session. (This is necessary because QEMU assumes it can map memory RWX for TCG and 'make check' will fail if it can't.)
Required packages
Install enough packages to build QEMU
pkg_add git pkg_add gmake pkg_add python (select a python 2.7, and run the ln -sf runes to make it default) pkg_add gcc (you need this to get a gcc that's not the ancient default) pkg_add g++ pkg_add glib2 pkg_add bison pkg_add sdl
TODO: recommended-but-not-required packages?
Build
Configure and make as usual:
mkdir build cd build ../configure -cc=x86_64-unknown-openbsd6.0-gcc-4.9.3 --cxx=x86_64-unknown-openbsd6.0-g++-4.9.3 gmake
(NB as of 2017-03-20 you'll also need --disable-user to work around a QEMU bug.)
NetBSD
Create a disk image, and grab the install cd image:
qemu-img create -f qcow2 disk.qcow2 15G wget http://cdn.netbsd.org/pub/NetBSD/NetBSD-7.1/images/NetBSD-7.1-amd64.iso
Run the installer:
qemu-system-x86_64 -m 2048 -enable-kvm \ -drive if=virtio,file=disk.qcow2,format=qcow2 \ -netdev user,id=mynet0,hostfwd=tcp::7722-:22 \ -device e1000,netdev=mynet0 \ -cdrom NetBSD-7.1-amd64.iso
The defaults will generally do. When it gets to the big menu of things to configure at the end of the install: configure networking (select defaults); enable NTP and ntpdate; enable ssh; set a root password.
Reboot into the installed system. Edit /etc/ssh/sshd_config to set 'PermitRootLogin: without-password', and set up ssh authorized keys.
Now you can run the installed image:
qemu-system-x86_64 -m 2048 \ -drive if=virtio,file=disk.qcow2,format=qcow2 \ -enable-kvm \ -netdev user,id=mynet0,hostfwd=tcp:127.0.0.1:7722-:22 \ -device e1000,netdev=mynet0
You should now be able to get in to the VM with
ssh -p 7722 root@localhost
Required packages
Run this to make pkg_add actually work:
export PKG_PATH="http://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/<PORT>/<RELEASE-NUMBER>/All"
Then install dependencies:
pkg_add git gmake python27 glib2 bison pkgconf
TODO: optional dependencies?
Building
You can configure and build QEMU as you would on Linux:
mkdir build cd build ../configure --python=python2.7 gmake gmake check
Note that you need to use 'gmake', not plain 'make'.