Hosts/BSD

From QEMU
Revision as of 14:48, 20 March 2017 by Pm215 (talk | contribs)

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

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'.

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

Follow the straightforward install prompts (accepting defaults generally OK). You'll want to enable sshd and allow logins with prohibit-password.

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

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

NetBSD

TODO: I have not yet been able to get a NetBSD VM running to test with...