This page contains recipes for using qemu to run FreeBSD inside virtual machines (especially non-native virtual machines) on a FreeBSD host. The goal is to have a at least one "blessed" qemu recipe for each architecture FreeBSD supports. For more details on running qemu in general including network configuration, see the qemu page.

For systems installed from an ISO image, the instructions assume you have downloaded an appropriate ISO image from a release or snapshot. When installing a new machine that requires a disk image, you can use truncate(1) to create an empty disk image before installing, for example:

truncate -s 16g /path/to/disk.img

If you wish to boot without a graphical console, add -nographic to the qemu command line.

arm64

An EFI firmware file is required to boot FreeBSD/arm64 in QEMU. See arm64/QEMU for information on where to get it.

Booting a snapshot disk image

qemu-system-aarch64 -m 4096M -cpu cortex-a57 -M virt  \
        -bios QEMU_EFI.fd -serial telnet::4444,server -nographic \
        -drive if=none,file=VMDISK,id=hd0 \
        -device virtio-blk-device,drive=hd0 \
        -device virtio-net-device,id=net0

Then telnet localhost:4444 to connect to the serial console.

mips

FreeBSD does not provide release images for mips, so a disk image must be built from source. Note that these instructions use a few placeholders:

/path/to/rootfs

Local directory on the host to hold the contents of the root filesystem.

/path/to/disk.img

A file on the host to hold the UFS disk image of the root filesystem.

/path/to/src

The path to the source tree used for the build.

Building Disk Image

make TARGET_ARCH=mips buildworld
make TARGET_ARCH=mips buildkernel KERNCONF=MALTA
mkdir /path/to/rootfs
make TARGET_ARCH=mips installworld DESTDIR=/path/to/rootfs
make TARGET_ARCH=mips installkernel KERNCONF=MALTA DESTDIR=/path/to/rootfs
make TARGET_ARCH=mips distribution DESTDIR=/path/to/rootfs
etcupdate extract -B -D /path/to/rootfs -s /path/to/src -M "TARGET_ARCH=mips"

Create /etc/fstab in the rootfs to mount '/dev/ada0' as an ufs filesystem for /. You might also wish to make other changes to files in /etc such as enabling ssh.

makefs -M 4g -B be /path/to/disk.img /path/to/rootfs

Booting Disk Image

The serial console will be available on stdin and stdout.

qemu-system-mips -kernel /path/to/rootfs/boot/kernel/kernel -nographic -hda /path/to/disk.img -m 2048

Using External GCC from Ports

To use external GCC from ports instead of the in-tree GCC 4.2.1 use these steps to build the image:

pkg install mips-xtoolchain-gcc
make TARGET_ARCH=mips CROSS_TOOLCHAIN=mips-gcc TARGET_CPUTYPE=mips3 buildworld
make TARGET_ARCH=mips CROSS_TOOLCHAIN=mips-gcc TARGET_CPUTYPE=mips3 buildkernel KERNCONF=MALTA
mkdir /path/to/rootfs
make TARGET_ARCH=mips CROSS_TOOLCHAIN=mips-gcc installworld DESTDIR=/path/to/rootfs
make TARGET_ARCH=mips CROSS_TOOLCHAIN=mips-gcc installkernel KERNCONF=MALTA DESTDIR=/path/to/rootfs
make TARGET_ARCH=mips distribution DESTDIR=/path/to/rootfs
etcupdate extract -B -D /path/to/rootfs -s /path/to/src -M "TARGET_ARCH=mips CROSS_TOOLCHAIN=mips-gcc"

To cross-compile simple programs using the rootfs and external GCC, use the following variables. Note that for C++ you may need to remove /usr/lib/include from the rootfs for builds to work correctly (note that this uses libc++ and so should work with C++11 programs):

ROOTFS=/path/to/rootfs
CC="mips-unknown-freebsd11.0-gcc -nostdinc -march=mips3 --sysroot=${ROOTFS} -isystem ${ROOTFS}/usr/include -B ${ROOTFS}/usr/lib -L${ROOTFS}/usr/lib -msoft-float"
CXX="mips-unknown-freebsd11.0-g++ -nostdinc -nostdinc++ -march=mips3 --sysroot=${ROOTFS} -isystem ${ROOTFS}/usr/include/c++/v1 -isystem ${ROOTFS}/usr/include -B ${ROOTFS}/usr/lib -L${ROOTFS}/usr/lib -msoft-float"

mips64

FreeBSD does not provide release images for mips64, so a disk image must be built from source. Note that these instructions use a few placeholders:

/path/to/rootfs

Local directory on the host to hold the contents of the root filesystem.

/path/to/disk.img

A file on the host to hold the UFS disk image of the root filesystem.

/path/to/src

The path to the source tree used for the build.

Building Disk Image

make TARGET_ARCH=mips64 buildworld
make TARGET_ARCH=mips64 buildkernel KERNCONF=MALTA64
mkdir /path/to/rootfs
make TARGET_ARCH=mips64 installworld DESTDIR=/path/to/rootfs
make TARGET_ARCH=mips64 installkernel KERNCONF=MALTA64 DESTDIR=/path/to/rootfs
make TARGET_ARCH=mips64 distribution DESTDIR=/path/to/rootfs
etcupdate extract -B -D /path/to/rootfs -s /path/to/src -M "TARGET_ARCH=mips64"

Create /etc/fstab in the rootfs to mount '/dev/ada0' as an ufs filesystem for /. You might also wish to make other changes to files in /etc such as enabling ssh.

makefs -M 4g -B be /path/to/disk.img /path/to/rootfs

Booting Disk Image

The serial console will be available on stdin and stdout.

qemu-system-mips64 -kernel /path/to/rootfs/boot/kernel/kernel -nographic -hda /path/to/disk.img -m 2048

Using External GCC from Ports

To use external GCC from ports instead of the in-tree GCC 4.2.1 use these steps to build the image:

pkg install mips-xtoolchain-gcc
make TARGET_ARCH=mips64 CROSS_TOOLCHAIN=mips-gcc buildworld
make TARGET_ARCH=mips64 CROSS_TOOLCHAIN=mips-gcc buildkernel KERNCONF=MALTA64
mkdir /path/to/rootfs
make TARGET_ARCH=mips64 CROSS_TOOLCHAIN=mips-gcc installworld DESTDIR=/path/to/rootfs
make TARGET_ARCH=mips64 CROSS_TOOLCHAIN=mips-gcc installkernel KERNCONF=MALTA64 DESTDIR=/path/to/rootfs
make TARGET_ARCH=mips64 distribution DESTDIR=/path/to/rootfs
etcupdate extract -B -D /path/to/rootfs -s /path/to/src -M "TARGET_ARCH=mips64 CROSS_TOOLCHAIN=mips-gcc"

To cross-compile simple programs using the rootfs and external GCC, use the following variables. Note that for C++ you may need to remove /usr/lib/include from the rootfs for builds to work correctly (note that this uses libc++ and so should work with C++11 programs):

ROOTFS=/path/to/rootfs
CC="mips-unknown-freebsd11.0-gcc -nostdinc -mabi=64 --sysroot=${ROOTFS} -isystem ${ROOTFS}/usr/include -B ${ROOTFS}/usr/lib -L${ROOTFS}/usr/lib -msoft-float"
CXX="mips-unknown-freebsd11.0-g++ -nostdinc -nostdinc++ -mabi=64 --sysroot=${ROOTFS} -isystem ${ROOTFS}/usr/include/c++/v1 -isystem ${ROOTFS}/usr/include -B ${ROOTFS}/usr/lib -L${ROOTFS}/usr/lib -msoft-float"

powerpc

Note: This does not yet work. Both the default (g3beige) and mac99 machine types hang during boot.

powerpc64

To disable the graphic console, use -nographic -vga none. Note that the default NIC provided by qemu(4) (llan(4)) does not provide media status. As a result, DHCP is not started by devd out of the box. Use SYNCHDHCP in /etc/rc.conf instead of DHCP to enable DHCP on boot.

Install from ISO

qemu-system-ppc64 -cdrom /path/to/disc1.iso -drive file=/path/to/disk.img,format=raw -boot d

Booting Installed System

qemu-system-ppc64 -drive file=/path/to/disk.img,format=raw

sparc64

FreeBSD/sparc64 should boot with qemu 2.6 and above with -nographic option. Confirmed with 10.4-STABLE snapshot (r326054) and qemu 2.9.0; however, 12.0-CURRENT hangs during the boot process (YMMV).

Install from ISO

qemu-system-sparc64 -cdrom /path/to/disc1.iso -drive file=/path/to/disk.img,format=raw -boot d

Booting Installed System

qemu-system-sparc64 -drive file=/path/to/disk.img,format=raw


CategoryVirtualization

QemuRecipes (last edited 2017-12-17 05:48:18 by AlexeyDokuchaev)