# pkg install qemu sudo
Appendix A. QEMU Setup
Table of Contents
This appendix contains helpful information for getting QEMU installed on FreeBSD and instructions for common use.
QEMU can be invoked to display a vt(4) style virtual terminal console using SDL.
Because of this the user environment, either X Window or Wayland, must allow for use of the DISPLAY variable in the local environment.
It can also be invoked in -nographics
mode, resulting is the current screen or window immediately becoming the console for the QEMU instance.
The examples in this book utilize the SDL based vt(4) based console and also include a using a FreeBSD serial console (described Adding a Serial Console).
Additional resources for understanding and using QEMU include:
The QEMU Virtualization chapter in the FreeBSD Handbook
The qemu(1) manual page
The QEMU Home Page
QEMU is available as a package or a port. There are a large number of build options on the port, so in most cases it is best to install the package:
Perform the following steps to get a QEMU virtual machine started. The Quick Start section in the Introduction has a suggested layout.
Designate a destination directory for the virtual machine(s). This procedure is an example that does not use the directory layout in this book. We will call this directory QVM.
Create the image files that will become the QEMU virtual machines. Use qemu-img(1) to create the images. Using the
qcow2
format is recommended as the scripts in this book use that format.# cd QVM # qemu-img create -f qcow2 -o preallocation=full MyQemuVM 4G
Download or copy a FreeBSD installation DVD into the QVM directory and rename it to fbsd.iso. You can also just link that name to an existing DVD.
Set up networking You can use QEMU without any networking, with an internal legacy based SLiRP protocol that uses an internal DHCP server, or you can use the FreeBSD tap(4) and if_bridge(4) interfaces to connect to your local network. In this example, we will install without a network interface, and add it later.
Once the image file is complete, you can enter these commands to start up the virtual machine:
/usr/local/bin/qemu-system-x86_64 -monitor stdio \ -cpu qemu64 \ -vga std \ -m 4096 \ -smp 2 \ -cdrom fbsd.iso \ -boot order=cd,menu=on \ -blockdev driver=file,aio=threads,node-name=fbsdimg,filename=MyQemuVM.qcow2 \ -blockdev driver=qcow2,node-name=drive0,file=fbsdimg \ -device virtio-blk-pci,drive=drive0,bootindex=1 \ -name \"FreeBSD\"
The virtual machine should start in a console window and load the FreeBSD installation DVD. Install the system as usual, but select UFS as the filesystem. If you want to use ZFS, increase the amount of memory (
-m parameter
).To add networking, configure a tap(4) device as
tap0
, and an if_bridge(4) device asbridge0
as shown in the Quick Start section. You can add thetap0
andbridge0
devices to the above configuration with these two lines (add above the-name
line).-netdev tap,id=nd0,ifname=tap0,script=no,downscript=no,br=bridge0 \ -device e1000,netdev=nd0,mac=02:55:33:12:34:56 \
If you want the virtual machine to use DHCP on your local network, add your host interface (em0, bge0, etc.) to the bridge. For example, to add an
em0
host interface use:# ifconfig bridge0 addm em0
If you are having trouble, check the other resources noted above. The given examples should work.