qemurecipes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
qemurecipes [2015/09/25 18:31] – JohnBaldwinqemurecipes [2020/12/11 14:24] (current) – Add riscv qemu invocation MitchellHorne
Line 1: Line 1:
 +====== QemuRecipes ======
 +
 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|qemu]] page. 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|qemu]] page.
  
Line 9: Line 11:
 If you wish to boot without a graphical console, add ''%%-nographic%%'' to the qemu command line. If you wish to boot without a graphical console, add ''%%-nographic%%'' to the qemu command line.
  
-====== arm64 ======+====== armv7 ======
  
-An EFI firmware file is required to boot %%FreeBSD%%/arm64 in QEMU. Obtain it from http://people.FreeBSD.org/~gjb/QEMU_EFI.fd.+First, install the U-Boot port, sysutils/u-boot-qemu-arm.
  
-===== Booting a snapshot disk image =====+===== Booting Disk Image ===== 
 + 
 +The serial console will be available on stdin and stdout.
  
 <code> <code>
-qemu-system-aarch64 -m 4096M -cpu cortex-a57 -M virt  \ +qemu-system-arm -M virt -m 512m -nographic -bios /usr/local/share/u-boot/u-boot-qemu-arm/u-boot.bin -hda /path/to/disk.img
- -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+
 </code> </code>
  
-Then ''%%telnet localhost:4444%%'' to connect to the serial console.+====== aarch64 ====== 
 + 
 +See also: [[arm64/QEMU]] 
 + 
 +%%FreeBSD%%/aarch64 (aka ARM64) image can be booted in two ways: using U-Boot, or with UEFI image.  For instructions on how to boot with UEFI, see [[arm64/QEMU]]. 
 +To boot using U-Boot, install sysutils/u-boot-qemu-arm64 port. 
 + 
 +===== Booting Disk Image ===== 
 + 
 +<code> 
 +qemu-system-aarch64 -M virt -m 512m -cpu cortex-a57 -nographic -bios /usr/local/share/u-boot/u-boot-qemu-arm64/u-boot.bin -hda /path/to/disk.img 
 +</code> 
 + 
 +====== 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 ===== 
 + 
 +<code> 
 +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" 
 +</code> 
 + 
 +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. 
 + 
 +<code> 
 +makefs -M 4g -B be /path/to/disk.img /path/to/rootfs 
 +</code> 
 + 
 +===== Booting Disk Image ===== 
 + 
 +The serial console will be available on stdin and stdout. 
 + 
 +<code> 
 +qemu-system-mips -kernel /path/to/rootfs/boot/kernel/kernel -nographic -hda /path/to/disk.img -m 2048 
 +</code> 
 + 
 +===== 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: 
 + 
 +<code> 
 +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" 
 +</code> 
 + 
 +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): 
 + 
 +<code> 
 +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" 
 +</code> 
 + 
 +====== 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 ===== 
 + 
 +<code> 
 +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" 
 +</code> 
 + 
 +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. 
 + 
 +<code> 
 +makefs -M 4g -B be /path/to/disk.img /path/to/rootfs 
 +</code> 
 + 
 +===== Booting Disk Image ===== 
 + 
 +The serial console will be available on stdin and stdout. 
 + 
 +<code> 
 +qemu-system-mips64 -kernel /path/to/rootfs/boot/kernel/kernel -nographic -hda /path/to/disk.img -m 2048 
 +</code> 
 + 
 +===== 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: 
 + 
 +<code> 
 +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" 
 +</code> 
 + 
 +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): 
 + 
 +<code> 
 +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" 
 +</code>
  
 ====== powerpc ====== ====== powerpc ======
Line 31: Line 158:
 ====== powerpc64 ====== ====== powerpc64 ======
  
-The ''%%-nographic%%'' option does not appear to work with this emulation.  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.+See Also: [[powerpc/QEMU]] 
 + 
 +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 ===== ===== Install from ISO =====
Line 43: Line 172:
 <code> <code>
 qemu-system-ppc64 -drive file=/path/to/disk.img,format=raw qemu-system-ppc64 -drive file=/path/to/disk.img,format=raw
 +</code>
 +
 +====== riscv ======
 +
 +See also: [[riscv/QEMU]] and [[riscv]]
 +
 +Booting %%FreeBSD%%/riscv64 requires installing two ports: sysutils/opensbi and sysutils/u-boot-qemu-riscv64.
 +
 +===== Booting Disk Image =====
 +
 +<code>
 +qemu-system-riscv64 -M virt -m 512m -nographic -bios /usr/local/share/opensbi/lp64/generic/firmware/fw_jump.elf -kernel /usr/local/share/u-boot/u-boot-qemu-riscv64/u-boot.bin -drive file=/path/to/disk.img,format=raw,id=hd0 -device virtio-blk-device,drive=hd0
 </code> </code>
  
 ====== sparc64 ====== ====== sparc64 ======
  
-**Note:** %%FreeBSD%%/sparc64 does not currently boot under qemu (see [[https://lists.freebsd.org/pipermail/freebsd-sparc64/2015-September/009638.html|this thread]]), but once it does, these commands should probably work.+%%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 ===== ===== Install from ISO =====
Line 60: Line 201:
 qemu-system-sparc64 -drive file=/path/to/disk.img,format=raw qemu-system-sparc64 -drive file=/path/to/disk.img,format=raw
 </code> </code>
 +
 +----
 +
 +[[CategoryVirtualization]]
  
  • qemurecipes.1443205892.txt.gz
  • Last modified: 2015/09/25 18:31
  • by JohnBaldwin